/** * Constructs a new escaping iteratoror using the escaping method and value supplied. * * @param string $escapingMethod The escaping method to use * @param \Traversable $value The iterator to escape */ public function __construct($escapingMethod, \Traversable $value) { // Set the original value for __call(). Set our own iterator because passing // it to IteratorIterator will lose any other method calls. parent::__construct($escapingMethod, $value); $this->iterator = new \IteratorIterator($value); }
/** * Decorate Notifier * * Automatically attach the decorate toolbar if the delegate has previously already been attached. This will * subscribe the decorator to the event dispatcher. * * @param object $delegate The object being decorated * @return void * @throws \InvalidArgumentException If the delegate is not an object * @see ControllerToolbarMixin::attachToolbar() */ public function onDecorate($delegate) { $controller = $delegate->getController(); if ($controller->inherits('Nooku\\Library\\ControllerToolbarMixin')) { if ($controller->hasToolbar($delegate->getType())) { $controller->detachToolbar($delegate); $controller->attachToolbar($this); } } parent::onDecorate($delegate); }
/** * Overloaded call function * * Auto-matically fetch the entity and forward the call if the method exists in the entity, * if not delegate to the model instead. * * @param string $method The function name * @param array $arguments The function arguments * @throws \BadMethodCallException If method could not be found * @return mixed The result of the function */ public function __call($method, $arguments) { $model = $this->getDelegate(); $entity = $this->fetch(); //Call the method if it exists if (!method_exists($model, $method) && is_callable(array($entity, $method))) { $result = null; // Call_user_func_array is ~3 times slower than direct method calls. switch (count($arguments)) { case 0: $result = $entity->{$method}(); break; case 1: $result = $entity->{$method}($arguments[0]); break; case 2: $result = $entity->{$method}($arguments[0], $arguments[1]); break; case 3: $result = $entity->{$method}($arguments[0], $arguments[1], $arguments[2]); break; default: // Resort to using call_user_func_array for many segments $result = call_user_func_array(array($entity, $method), $arguments); } return $result; } return parent::__call($method, $arguments); }
/** * Get the decorated toolbar * * @return ControllerToolbarInterface */ public function getDelegate() { return parent::getDelegate(); }