/** * Invokes the callback with the provided values * @param zibo\library\Callback $calback Callback to order the values * @param array $values Values to order * @return array Array with the values ordered */ private function invoke(Callback $callback, $values) { if (!$this->arguments) { return $callback->invoke($values); } $arguments = $this->arguments; array_unshift($arguments, $values); return $callback->invokeWithArrayArguments($arguments); }
/** * Runs this job * @return null */ public function run() { $args = func_get_args(); try { $this->callback->invokeWithArrayArguments($args); $this->lastRunTime = time(); } catch (Exception $exception) { $this->lastRunTime = time(); throw $exception; } }
/** * Gets the callback for the provided method * @param object $object Object of the method * @param string $methodName Name of the method * @return zibo\library\Callback * @throws zibo\ZiboException when the method is not invokable */ protected function getCallback($object, $methodName) { try { $callback = new Callback(array($object, $methodName)); if (!$callback->isCallable()) { throw new ZiboException('Could not invoke action ' . $methodName . ' in ' . get_class($object)); } } catch (ZiboException $exception) { throw new ZiboException('Could not dispatch action ' . $methodName . ' in ' . get_class($object), 0, $exception); } return $callback; }
/** * Invokes a method on the Soap client * @param string $name Name of the method * @param array $arguments The arguments for the method, the authentication token will be prepended to this array before passing it to the Soap client * @return mixed The result of the remote method */ public function __call($name, $arguments) { $this->login(); array_unshift($arguments, $this->token); $callback = new Callback(array($this->client, $name)); return $callback->invokeWithArrayArguments($arguments); }
/** * @dataProvider providerInvokeThrowsExceptionWhenUnableToInvokeCallback * @expectedException zibo\ZiboException */ public function testInvokeThrowsExceptionWhenUnableToInvokeCallback($callback) { $callback = new Callback($callback); $callback->invoke(); }
/** * Creates an instance of the provided dependency * @param string $interface Full class name of the interface or parent class * @param Dependency $dependency Definition of the class to create * @param array $exclude Array with the interface as key and an array with * id's of dependencies as key to exclude from the get calls. * @return mixed Instance of the dependency * @throws zibo\ZiboException when the dependency could not be created */ protected function create($interface, Dependency $dependency, array $exclude = null) { if (!self::$objectFactory) { self::$objectFactory = new ObjectFactory(); } if (!$exclude) { $exclude = array($interface => array($dependency->getId() => true)); } elseif (!isset($exclude[$interface])) { $exclude[$interface] = array($dependency->getId() => true); } else { $exclude[$interface][$dependency->getId()] = true; } $className = $dependency->getClassName(); $arguments = $dependency->getConstructorArguments(); $arguments = $this->getCallbackArguments($arguments, $exclude); $instance = self::$objectFactory->create($className, $interface, $arguments); $calls = $dependency->getCalls(); if ($calls) { foreach ($calls as $call) { $arguments = $this->getCallbackArguments($call->getArguments(), $exclude); $callback = new Callback(array($instance, $call->getMethodName())); $callback->invokeWithArrayArguments($arguments); } } return $instance; }