Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_Core
- * @package ILLI
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\Core\Exception;
- USE ILLI\Core\Virtual\Member\iField as iField;
- USE ReflectionClass AS __ReflectionClass;
- USE Exception AS __Exception;
- /**
- * ILLI Exception
- *
- * @category ILLI_Core_Exception
- * @package ILLI
- * @subpackage Core\Exception
- * @namespace ILLI\Core\Exception
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.1
- * @version 3.0.1
- */
- CLASS Exception EXTENDS __Exception
- {
- USE \ILLI\Core\tObject;
- USE \ILLI\Core\Virtual\Member\tField;
- private static $__hasCatched = [];
- public function __construct()
- {
- // define properties
- $this
- ->tField_define('previous', '\Exception', [])
- ->tField_define('renderer', __NAMESPACE__.'\ExceptionMessage', [])
- ->tField_define('arguments', 'array', [])
- ->tField_define
- (
- 'unparsed', 'string',
- [
- iField::PROP_INIT => 'Unknown Error.',
- iField::PROP_PRIVATE_SET => TRUE,
- iField::PROP_PRIVATE_GET => TRUE
- ]
- )
- ->tField_define
- (
- 'code', 'integer',
- [
- iField::PROP_INIT => 0,
- iField::PROP_PRIVATE_SET => TRUE,
- iField::PROP_PRIVATE_GET => FALSE
- ]
- )
- ->tField_define
- (
- 'message', 'string',
- [
- iField::PROP_ON_GET => (function(array $data)
- {
- $data[iField::CALLBACK_PROP_CONTAINS] = $this->tField_get('renderer')->getParsed();
- return $data;
- }),
- iField::PROP_PRIVATE_SET => TRUE,
- iField::PROP_PRIVATE_GET => FALSE
- ]
- );
- // parse arguments by type and store value
- foreach(func_get_args() as $arg)
- {
- if(is_integer($arg))
- {
- $this->tField_set('code', $arg);
- }
- else
- if(is_string($arg))
- {
- $this->tField_set('unparsed', $arg);
- }
- else
- if(is_array($arg))
- {
- $this->tField_set('arguments', $arg);
- }
- else
- if(is_object($arg))
- {
- if($arg instanceOf __Exception)
- $this->tField_set('previous', $arg);
- }
- }
- // set message-parser
- $this->tField_set
- (
- 'renderer',
- ExceptionMessage::create()
- ->setMessage($this->tField_get('unparsed'))
- ->setArguments($this->tField_get('arguments'))
- );
- // load message-template by error-code
- if(FALSE === $this->tField_isTouched('unparsed')
- && TRUE === $this->tField_isTouched('code'))
- {
- $constants = (new __ReflectionClass(get_called_class()))->getConstants();
- foreach($constants as $name => $value)
- {
- if($value !== $this->tField_get('code'))
- continue;
- $const = str_replace('CODE_', '', $name);
- if(!isset($constants[$const]))
- break;
- $this->tField_set('unparsed', $constants[$const]);
- $this->tField_get('renderer')->setMessage($this->tField_get('unparsed'));
- }
- }
- else
- // load the exception default message
- if(FALSE === $this->tField_isTouched('unparsed')
- && FALSE === $this->tField_isTouched('code'))
- {
- var_dump('load default message by exceptionclass: '.$this->tObject_getType());
- }
- else
- // use the given message
- if(TRUE === $this->tField_isTouched('unparsed'))
- {
- var_dump('use message from constructor: '.$this->tField_get('unparsed'));
- }
- self::$__hasCatched[] = get_called_class();
- parent::__construct
- (
- $this->tField_get('message'),
- $this->tField_get('code'),
- $this->tField_get('previous')
- );
- }
- public function __set($key, $value)
- {
- if(FALSE === $this->tField_isPrivateSet($key))
- $this->tField_set($key, $value);
- }
- public function __get($key)
- {
- if(FALSE === $this->tField_isPrivateGet($key))
- return $this->tField_get($key);
- }
- public function getType()
- {
- return $this->tObject_getType();
- }
- public function hasCatched($name)
- {
- return in_array($name, self::$__hasCatched);
- }
- public function getHashCode()
- {
- return $this->tObject_getHashCode();
- }
- public function toString()
- {
- return $this->tObject_toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement