Пример #1
0
 /**
  * Call to undefined method.
  *
  * @param  string  method name
  * @param  array   arguments
  * @return mixed
  * @throws MemberAccessException
  */
 public static function call($_this, $name, $args)
 {
     $class = new ClassReflection($_this);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class->name}' method without name.");
     }
     // event functionality
     if ($class->hasEventProperty($name)) {
         if (is_array($list = $_this->{$name}) || $list instanceof Traversable) {
             foreach ($list as $handler) {
                 fixCallback($handler);
                 if (!is_callable($handler)) {
                     $able = is_callable($handler, TRUE, $textual);
                     throw new InvalidStateException("Event handler '{$textual}' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
                 }
                 call_user_func_array($handler, $args);
             }
         }
         return NULL;
     }
     // extension methods
     if ($cb = $class->getExtensionMethod($name)) {
         array_unshift($args, $_this);
         return call_user_func_array($cb, $args);
     }
     throw new MemberAccessException("Call to undefined method {$class->name}::{$name}().");
 }
Пример #2
0
 /**
  * Call to undefined method.
  * @param  string  method name
  * @param  array   arguments
  * @return mixed
  * @throws MemberAccessException
  */
 public static function call($_this, $name, $args)
 {
     $class = new ClassReflection($_this);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class->name}' method without name.");
     }
     // event functionality
     if ($class->hasEventProperty($name)) {
         if (is_array($list = $_this->{$name}) || $list instanceof Traversable) {
             foreach ($list as $handler) {
                 callback($handler)->invokeArgs($args);
             }
         }
         return NULL;
     }
     // extension methods
     if ($cb = $class->getExtensionMethod($name)) {
         array_unshift($args, $_this);
         return $cb->invokeArgs($args);
     }
     throw new MemberAccessException("Call to undefined method {$class->name}::{$name}().");
 }
Пример #3
0
 /**
  * Adding method to class.
  * @param  string  method name
  * @param  mixed   callback or closure
  * @return mixed
  */
 public static function extensionMethod($name, $callback = NULL)
 {
     if (strpos($name, '::') === FALSE) {
         $class = get_called_class();
     } else {
         list($class, $name) = explode('::', $name);
     }
     $class = new ClassReflection($class);
     if ($callback === NULL) {
         return $class->getExtensionMethod($name);
     } else {
         $class->setExtensionMethod($name, $callback);
     }
 }