示例#1
0
 public function debug($variable = NULL, $next = NULL)
 {
     $class = get_class($this);
     if (is_null($variable)) {
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class))->output($this);
         return $this;
     }
     if ($variable === true) {
         return Eden_Debug::i()->next($this, $next);
     }
     if (!is_string($variable)) {
         Eden_Debug::i()->output(Eden_Error::DEBUG_NOT_STRING);
         return $this;
     }
     if (isset($this->{$variable})) {
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class . '->' . $variable))->output($this->{$variable});
         return $this;
     }
     $private = '_' . $variable;
     if (isset($this->{$private})) {
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class . '->' . $private))->output($this->{$private});
         return $this;
     }
     Eden_Debug::i()->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY, $variable, $clas));
     return $this;
 }
 /** 
  * Force outputs any class property
  *
  * @param string|null
  * @param string|null
  * @return this
  */
 public function debug($variable = NULL, $next = NULL)
 {
     //we are using tool in all cases
     $class = get_class($this);
     //if variable is null
     if (is_null($variable)) {
         //output the class
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class))->output($this);
         return $this;
     }
     //if variable is true
     if ($variable === true) {
         //return whatever the next response is
         //or return the next specified variable
         return Eden_Debug::i()->next($this, $next);
     }
     //if variable is not a string
     if (!is_string($variable)) {
         //soft output error
         Eden_Debug::i()->output(Eden_Error::DEBUG_NOT_STRING);
         return $this;
     }
     //if variable is set
     if (isset($this->{$variable})) {
         //output it
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class . '->' . $variable))->output($this->{$variable});
         return $this;
     }
     //could be private
     $private = '_' . $variable;
     //if private variable is set
     if (isset($this->{$private})) {
         //output it
         Eden_Debug::i()->output(sprintf(self::DEBUG, $class . '->' . $private))->output($this->{$private});
         return $this;
     }
     //soft output error
     Eden_Debug::i()->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY, $variable, $clas));
     return $this;
 }
示例#3
0
if(!class_exists('Eden_Class')){class Eden_Class{const DEBUG='DEBUG %s:';const INSTANCE=0;private static $_instances=array();public static function i(){if(static::INSTANCE===1){return self::_getSingleton();}return self::_getMultiple();}public function __call($name,$args){if(preg_match("/^[A-Z]/",$name)){try{return Eden_Route::i()->getClass($name,$args);}catch(Eden_Route_Error $e){}}try{return Eden_Route::i()->getMethod()->call($this,$name,$args);}catch(Eden_Route_Error $e){Eden_Error::i($e->getMessage())->trigger();}}public function __invoke(){if(func_num_args()==0){return $this;}$args=func_get_args();if(is_array($args[0])){$args=$args[0];}$class=array_shift($args);if(strpos('Eden_',$class) !==0){$class='Eden_'.$class;}try{return Eden_Route::i()->getClass($class,$args);}catch(Eden_Route_Error $e){Eden_Error::i($e->getMessage())->trigger();}}public function __toString(){return get_class($this);}public function callThis($method,array $args=array()){Eden_Error::i()->argument(1,'string');return Eden_Route::i()->getMethod($this,$method,$args);}public function debug($variable=NULL,$next=NULL){$class=get_class($this);if(is_null($variable)){Eden_Debug::i()->output(sprintf(self::DEBUG,$class))->output($this);return $this;}if($variable===true){return Eden_Debug::i()->next($this,$next);}if(!is_string($variable)){Eden_Debug::i()->output(Eden_Error::DEBUG_NOT_STRING);return $this;}if(isset($this->$variable)){Eden_Debug::i()->output(sprintf(self::DEBUG,$class.'->'.$variable))->output($this->$variable);return $this;}$private='_'.$variable;if(isset($this->$private)){Eden_Debug::i()->output(sprintf(self::DEBUG,$class.'->'.$private))->output($this->$private);return $this;}Eden_Debug::i()->output(sprintf(Eden_Error::DEBUG_NOT_PROPERTY,$variable,$class));return $this;}public function each($callback){Eden_Error::i()->argument(1,'callable');return Eden_Loop::i()->iterate($this,$callback);}public function routeThis($route){Eden_Error::i()->argument(1,'string');if(func_num_args()==1){Eden_Route::i()->getClass()->route($route,$this);return $this;}Eden_Error::i()->argument(2,'string','object');$args=func_get_args();$source=array_shift($args);$class=array_shift($args);$destination=NULL;if(count($args)){$destination=array_shift($args);}Eden_Route::i()->getMethod()->route($this,$source,$class,$destination);return $this;}public function when($isTrue,$lines=0){if($isTrue){return $this;}return Eden_When::i($this,$lines);}protected static function _getMultiple($class=NULL){if(is_null($class) && function_exists('get_called_class')){$class=get_called_class();}$class=Eden_Route::i()->getClass()->getRoute($class);return self::_getInstance($class);}protected static function _getSingleton($class=NULL){if(is_null($class) && function_exists('get_called_class')){$class=get_called_class();}$class=Eden_Route::i()->getClass()->getRoute($class);if(!isset(self::$_instances[$class])){self::$_instances[$class]=self::_getInstance($class);}return self::$_instances[$class];}private static function _getInstance($class){$trace=debug_backtrace();$args=array();if(isset($trace[1]['args']) && count($trace[1]['args']) > 1){$args=$trace[1]['args'];array_shift($args);}else if(isset($trace[2]['args']) && count($trace[2]['args']) > 0){$args=$trace[2]['args'];}if(count($args)===0 || !method_exists($class,'__construct')){return new $class;}$reflect=new ReflectionClass($class);try{return $reflect->newInstanceArgs($args);}catch(Reflection_Exception $e){Eden_Error::i()->setMessage(Eden_Error::REFLECTION_ERROR)->addVariable($class)->addVariable('new')->trigger();}}}}