示例#1
0
 /**
  * Invoke an extended resource from a caller context
  *
  * @param Next\Components\Object $caller
  *   Caller Object
  *
  * @param string $method
  *   Callable resource name
  *
  * @param array $args
  *   Calling Arguments
  *
  * @return mixed|boolean
  *   Return what extended method returns.
  *
  *   If invoking process fail, false will returned.
  *
  * @throws Next\Components\Debug\Exception
  *   Called resource is not known as an extended method
  */
 public function call(Object $caller, $method, array $args = array())
 {
     $caller = $caller->getClass()->getName();
     if (array_key_exists($caller, $this->callables)) {
         $offset = ArrayUtils::search($this->callables[$caller], $method);
         if ($offset != -1) {
             try {
                 $reflector = new \ReflectionMethod($this->callables[$caller][$offset][0], $method);
                 return $reflector->invokeArgs($this->callables[$caller][$offset][0], $args);
             } catch (\ReflectionException $e) {
                 return FALSE;
             }
         }
     }
     // Unknown Method
     throw \Next\Components\Debug\Exception::wrongUse('Method <strong>%s</strong> could not be matched against any
         methods in extended Context', array($method));
 }
示例#2
0
 /**
  * Invoke a prototyped resource from a caller context
  *
  * @param Next\Components\Object $caller
  *   Caller Object
  *
  * @param string $method
  *   Callable resource name
  *
  * @param array $args
  *   Calling Arguments
  *
  * @return Next\Components\Object
  *   Caller Object updated
  *
  * @throws Next\Components\Debug\Exception
  *   Called resource is not known as a prototype nor as a extended method
  */
 public function call(Object $caller, $method, array $args = array())
 {
     if (isset(self::$prototypes[$method])) {
         // Merging always optional arguments with called arguments
         if (count($args) > 0) {
             ArrayUtils::insert(self::$prototypes[$method][1], $args);
         } else {
             // Nothing to Merge? OK!
             $args =& self::$prototypes[$method][1];
         }
         $result = call_user_func_array(self::$prototypes[$method][0], $args);
         /**
          * @internal
          *
          * If operation results in an Object, let's return it
          *
          * This ensures operations of one type can return a different type
          */
         if ($result instanceof Object) {
             return $result;
         }
         // Otherwise let's update caller Object
         return $caller->set($result);
     }
     throw \Next\Components\Debug\Exception::wrongUse('Method <strong>%s</strong> could not be matched against any
         methods in extended Context or prototyped functions', array($method));
 }