Beispiel #1
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));
 }