invokeArgs() public static method

Invokes callback with an array of parameters.
public static invokeArgs ( $callable, array $args = [] ) : mixed
$args array
return mixed
Example #1
0
 public function getBodyContent($data)
 {
     if (array_key_exists(self::CALLBACK, $this->option) === FALSE) {
         if (isset($data[$this->option[self::ID]]) === FALSE && is_null($data[$this->option[self::ID]]) === FALSE) {
             throw new Grid_Exception('Column ' . $this->option[self::ID] . ' does not exists in DataSource.');
         }
         $src = $data[$this->option[self::ID]];
     } else {
         $args = array($data);
         if (isset($this->option[self::CALLBACK_ARGS])) {
             if (!is_array($this->option[self::CALLBACK_ARGS])) {
                 throw new Grid_Exception(__CLASS__ . '::CALLBACK_ARGS must be an array. ' . gettype($this->option[self::CALLBACK_ARGS]) . ' given.');
             }
             $args = array_merge($args, $this->option[self::CALLBACK_ARGS]);
         }
         $src = Callback::invokeArgs($this->option[self::CALLBACK], $args);
     }
     $img = Html::el('img', array('src' => $src));
     if (isset($this->option[self::MAX_WIDTH]) === TRUE) {
         $img->style('max-width:' . $this->fixPixels($this->option[self::MAX_WIDTH]), TRUE);
     }
     if (isset($this->option[self::MAX_HEIGHT]) === TRUE) {
         $img->style('max-height:' . $this->fixPixels($this->option[self::MAX_HEIGHT]), TRUE);
     }
     return $img;
 }
 /**
  * Filter data
  * @param array $filters
  * @return static
  */
 public function filter(array $filters)
 {
     foreach ($filters as $filter) {
         if ($filter->isValueSet()) {
             if ($filter->hasConditionCallback()) {
                 Callback::invokeArgs($filter->getConditionCallback(), [$this->data_source, $filter->getValue()]);
             } else {
                 if ($filter instanceof Filter\FilterText) {
                     $this->applyFilterText($filter);
                 } else {
                     if ($filter instanceof Filter\FilterMultiSelect) {
                         $this->applyFilterMultiSelect($filter);
                     } else {
                         if ($filter instanceof Filter\FilterSelect) {
                             $this->applyFilterSelect($filter);
                         } else {
                             if ($filter instanceof Filter\FilterDate) {
                                 $this->applyFilterDate($filter);
                             } else {
                                 if ($filter instanceof Filter\FilterDateRange) {
                                     $this->applyFilterDateRange($filter);
                                 } else {
                                     if ($filter instanceof Filter\FilterRange) {
                                         $this->applyFilterRange($filter);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Example #3
0
 public function formatValue($row)
 {
     if ($this->callback) {
         return Callback::invokeArgs($this->callback, [$row, $this]);
     }
     return $this->getChainedValue($row);
 }
 /**
  * @param AbstractRequest $request
  * @return AbstractResponse
  * @throws DispatcherException
  */
 public function dispatch(AbstractRequest $request)
 {
     switch ($request->getType()) {
         case AbstractRequest::TYPE_CONFIRM:
             if (!$this->confirmCallback) {
                 throw new DispatcherException("Dispatcher: Confirm callback is not defined.");
             }
             $res = Callback::invokeArgs($this->confirmCallback, [$request, $this->prepareConfirmResponse()]);
             if (!$res instanceof ConfirmResponse) {
                 throw new DispatcherException('Return value from callback is not ConfirmResponse type.');
             }
             return $res;
         case AbstractRequest::TYPE_SMS:
             if (!$this->smsCallback) {
                 throw new DispatcherException("Dispatcher: Info callback is not defined.");
             }
             $res = Callback::invokeArgs($this->smsCallback, [$request, $this->prepareResponse()]);
             if (!$res instanceof Response) {
                 throw new DispatcherException('Return value from callback is not Response type.');
             }
             return $res;
         default:
             throw new DispatcherException("Dispatcher: Uknown request type.");
     }
 }
Example #5
0
 /**
  * @param mixin $row
  * @return mixin
  */
 public function getValue($row)
 {
     if ($this->valueCallback === NULL) {
         return is_array($row) ? $row[$this->name] : $row->{$this->name};
     }
     return Callback::invokeArgs($this->valueCallback, [$row]);
 }
 /**
  * @param \Venne\DataTransfer\DataTransferQuery $query
  * @return \Venne\DataTransfer\DataTransferObject
  */
 public function fetchObject(DataTransferQuery $query)
 {
     $class = '\\' . trim($query->getClass(), '\\');
     $values = $query->getValues();
     if (!class_exists($class)) {
         throw new InvalidArgumentException(sprintf('Class \'%s\' does not exist.', $class));
     }
     if (!is_subclass_of($class, 'Venne\\DataTransfer\\DataTransferObject')) {
         throw new InvalidArgumentException(sprintf('Class \'%s\' must inherit from \'Venne\\DataTransfer\\DataTransferObject\'.', $class));
     }
     if (!$query->isCacheEnabled()) {
         return new $class(function () use(&$values, $class) {
             $values = is_callable($values) ? Callback::invokeArgs($values) : $values;
             return $this->driver->getValuesByObject($values, $class::getKeys());
         });
     }
     $cacheDependencies = $query->getCacheDependencies();
     $primaryKeysCacheKey = $this->formatPrimaryKeysCacheKey($class, $query->getCacheKey());
     $primaryKey = $this->cache->load($primaryKeysCacheKey, function (&$dependencies) use(&$values, &$cacheDependencies) {
         $values = is_callable($values) ? Callback::invoke($values) : $values;
         $dependencies = Arrays::mergeTree((array) $cacheDependencies, $this->driver->getCacheDependenciesByObject($values));
         return $this->driver->getPrimaryKeyByObject($values);
     });
     $loadedValues = $this->cache->load(array($this->formatValuesCacheKey($class, $primaryKey), $primaryKeysCacheKey), function (&$dependencies) use(&$values, &$cacheDependencies, $class) {
         $values = is_callable($values) ? Callback::invoke($values) : $values;
         $dependencies = Arrays::mergeTree((array) $cacheDependencies, $this->driver->getCacheDependenciesByObject($values));
         /** @var DataTransferObject $dto */
         $dto = new $class($this->driver->getValuesByObject($values, $class::getKeys()));
         return $dto->toArray();
     });
     return new $class($loadedValues, true);
 }
Example #7
0
 public function handleAutocomplete($q)
 {
     if (!$this->callback) {
         throw new Nette\InvalidStateException('Undefined Typehad callback.');
     }
     $this->getPresenter()->sendJson(Nette\Utils\Callback::invokeArgs($this->callback, [$q]));
 }
Example #8
0
 /**
  * @param string $mask example images/<format>/<month>/<image>
  * @param IImageCallback $presenterCallback
  * @return Route
  */
 public static function createRouter($mask, IImageCallback $presenterCallback)
 {
     $filterIn = function ($params) {
         if ($params['presenter'] != 'Nette:Micro' || !isset($params['image']) || !isset($params['format'])) {
             return NULL;
         }
         return $params;
     };
     $filterOut = function ($params) use($mask) {
         if ($params['presenter'] != 'Nette:Micro' || !isset($params['image']) || !isset($params['format'])) {
             return NULL;
         }
         if ($params['image'] instanceof IFile) {
             $image = $params['image'];
             /* @var $file IFile */
             $params['image'] = $image->getName() . '.' . $image->getExt();
             if (preg_match('/<month>/', $mask)) {
                 $params['month'] = $image->getUploaded()->format('Ym');
             }
         }
         if ($params['format'] instanceof IImageFormat) {
             $params['format'] = $params['format']->getName();
         }
         return $params;
     };
     $callback = function ($image, $format) use($presenterCallback) {
         return \Nette\Utils\Callback::invokeArgs($presenterCallback, [$image, $format]);
     };
     $route = new Route($mask, [Route::PRESENTER_KEY => 'Nette:Micro', 'callback' => $callback, NULL => [Route::FILTER_IN => $filterIn, Route::FILTER_OUT => $filterOut]]);
     return $route;
 }
Example #9
0
 public function __call($name, $args)
 {
     if (isset($this->methods[strtolower($name)])) {
         return Callback::invokeArgs($this->methods[strtolower($name)], $args);
     } else {
         return parent::__call($name, $args);
     }
 }
Example #10
0
 /**
  * Returns final link for button or null.
  *
  * @param $row
  *
  * @return string|null
  */
 public function getLink($row)
 {
     if (!empty($this->linkCallback)) {
         return Callback::invokeArgs($this->linkCallback, [$row]);
     } else {
         return null;
     }
 }
Example #11
0
 /**
  * Allows calling $column->icon() instead of $column->setIcon (Same for title, class, ...)
  * @param  string $name
  * @param  array  $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     $method_setter = 'set' . ucfirst($name);
     if (method_exists($this, $method_setter)) {
         return Nette\Utils\Callback::invokeArgs([$this, $method_setter], $args);
     }
     parent::__call($name, $args);
 }
Example #12
0
 /**
  * @param $params
  * @throws \Nette\InvalidStateException
  */
 public function handleRemote($params)
 {
     if (!is_callable($this->remote)) {
         throw new Nette\InvalidStateException('Undefined Typehad callback.');
     }
     $q = array_key_exists('q', $params) ? $params['q'] : NULL;
     // call remote function with displayed key and query
     $this->presenter->sendJson(Nette\Utils\Callback::invokeArgs($this->remote, [$this->display, $q]));
 }
Example #13
0
 public function getCount($filter, $order)
 {
     if (!isset($this->limit)) {
         throw new InvalidStateException('Property limit must be set.');
     }
     if (!isset($this->offset)) {
         throw new InvalidStateException('Property offset must be set.');
     }
     $selection = Callback::invokeArgs($this->callback, [$filter, $order]);
     return $selection->count();
 }
Example #14
0
 public function formatValue($row)
 {
     if ($this->callback) {
         return Callback::invokeArgs($this->callback, [$row, $this]);
     }
     $value = $this->getChainedValue($row);
     if (!is_numeric($value)) {
         $type = is_object($value) ? get_class($value) : gettype($value);
         throw new InvalidTypeException("Expected numeric value, but  '{$type}' given from '{$this->getName()}'");
     }
     return number_format($value, $this->precision, $this->decimalSeparator, $this->thousandSeparator);
 }
Example #15
0
 public function getBodyContent($data)
 {
     $template = $this->getTemplate();
     if (array_key_exists(self::CALLBACK, $this->option)) {
         Callback::check($this->option[self::CALLBACK]);
         $args = array($data, $template);
         if (isset($this->option[self::CALLBACK_ARGS]) && is_array($this->option[self::CALLBACK_ARGS])) {
             $args = array_merge($args, $this->option[self::CALLBACK_ARGS]);
         }
         Callback::invokeArgs($this->option[self::CALLBACK], $args);
     }
     return trim($template);
 }
Example #16
0
 public function getBodyContent($data)
 {
     if (array_key_exists(self::CALLBACK, $this->option) === FALSE) {
         $this->checkColumnId($data);
         return $data[$this->option[self::ID]];
     } else {
         $args = array($data);
         if (isset($this->option[self::CALLBACK_ARGS]) && is_array($this->option[self::CALLBACK_ARGS])) {
             $args = array_merge($args, $this->option[self::CALLBACK_ARGS]);
         }
         return Callback::invokeArgs($this->option[self::CALLBACK], $args);
     }
 }
Example #17
0
 /**
  * @return mixed
  */
 public function getEntity()
 {
     if ($this->entity == NULL) {
         if ($this->entityFactory == NULL) {
             throw new InvalidStateException('Undefined entity factory.');
         }
         $this->entity = Callback::invokeArgs($this->entityFactory, [$this]);
         if (!is_object($this->entity)) {
             throw new InvalidStateException('Entity factory has to return an object.');
         }
     }
     return $this->entity;
 }
Example #18
0
 /**
  * __call() implementation.
  * @param  object
  * @param  string
  * @param  array
  * @return mixed
  * @throws MemberAccessException
  */
 public static function call($_this, $name, $args)
 {
     $class = get_class($_this);
     $isProp = self::hasProperty($class, $name);
     $methods =& self::getMethods($class);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     } elseif ($isProp && $_this->{$name} instanceof \Closure) {
         // closure in property
         return call_user_func_array($_this->{$name}, $args);
     } elseif ($isProp === 'event') {
         // calling event handlers
         if (is_array($_this->{$name}) || $_this->{$name} instanceof \Traversable) {
             foreach ($_this->{$name} as $handler) {
                 Nette\Utils\Callback::invokeArgs($handler, $args);
             }
         } elseif ($_this->{$name} !== NULL) {
             throw new UnexpectedValueException("Property {$class}::\${$name} must be array or NULL, " . gettype($_this->{$name}) . " given.");
         }
     } elseif (isset($methods[$name]) && $methods[$name] !== 0) {
         // magic @methods
         list($op, $rp, $type) = $methods[$name];
         if (!$rp) {
             throw new MemberAccessException("Magic method {$class}::{$name}() has not corresponding property \${$op}.");
         } elseif (count($args) !== ($op === 'get' ? 0 : 1)) {
             throw new InvalidArgumentException("{$class}::{$name}() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');
         } elseif ($type && $args && !self::checkType($args[0], $type)) {
             throw new InvalidArgumentException("Argument passed to {$class}::{$name}() must be {$type}, " . gettype($args[0]) . ' given.');
         }
         if ($op === 'get') {
             return $rp->getValue($_this);
         } elseif ($op === 'set') {
             $rp->setValue($_this, $args[0]);
         } elseif ($op === 'add') {
             $val = $rp->getValue($_this);
             $val[] = $args[0];
             $rp->setValue($_this, $val);
         }
         return $_this;
     } elseif ($cb = self::getExtensionMethod($class, $name)) {
         // extension methods
         array_unshift($args, $_this);
         return Nette\Utils\Callback::invokeArgs($cb, $args);
     } else {
         if (method_exists($class, $name)) {
             // called parent::$name()
             $class = 'parent';
         }
         throw new MemberAccessException("Call to undefined method {$class}::{$name}().");
     }
 }
Example #19
0
 public function __construct(IContainer $parent, $name, $description = NULL, $component = NULL)
 {
     parent::__construct($parent, $name, $description);
     $i = 0;
     while ($i <= (is_null($this->page_limit) ? self::DEFAULT_COUNT : $this->page_limit)) {
         if (!$component instanceof IContainer) {
             Callback::invokeArgs($component, array($this->parent->getParent(), $name . $i));
         } else {
             $this->parent->getParent()->addComponent($component, $name . $i);
         }
         $this->keys[] = $i;
         $i++;
     }
 }
Example #20
0
 /**
  * __call() implementation.
  * @param  object
  * @param  string
  * @param  array
  * @return mixed
  * @throws MemberAccessException
  */
 public static function call($_this, string $name, array $args)
 {
     $class = get_class($_this);
     $isProp = self::hasProperty($class, $name);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     } elseif ($isProp && $_this->{$name} instanceof \Closure) {
         // closure in property
         return call_user_func_array($_this->{$name}, $args);
     } elseif ($isProp === 'event') {
         // calling event handlers
         if (is_array($_this->{$name}) || $_this->{$name} instanceof \Traversable) {
             foreach ($_this->{$name} as $handler) {
                 Callback::invokeArgs($handler, $args);
             }
         } elseif ($_this->{$name} !== NULL) {
             throw new Nette\UnexpectedValueException("Property {$class}::\${$name} must be array or NULL, " . gettype($_this->{$name}) . ' given.');
         }
     } elseif (($methods =& self::getMethods($class)) && isset($methods[$name]) && is_array($methods[$name])) {
         // magic @methods
         list($op, $rp, $type) = $methods[$name];
         if (count($args) !== ($op === 'get' ? 0 : 1)) {
             throw new Nette\InvalidArgumentException("{$class}::{$name}() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');
         } elseif ($type && $args && !self::checkType($args[0], $type)) {
             throw new Nette\InvalidArgumentException("Argument passed to {$class}::{$name}() must be {$type}, " . gettype($args[0]) . ' given.');
         }
         if ($op === 'get') {
             return $rp->getValue($_this);
         } elseif ($op === 'set') {
             $rp->setValue($_this, $args[0]);
         } elseif ($op === 'add') {
             $val = $rp->getValue($_this);
             $val[] = $args[0];
             $rp->setValue($_this, $val);
         }
         return $_this;
     } elseif ($cb = self::getExtensionMethod($class, $name)) {
         // extension methods
         array_unshift($args, $_this);
         return Callback::invokeArgs($cb, $args);
     } else {
         $hint = self::getSuggestion(array_merge(get_class_methods($class), self::parseFullDoc($class, '~^[ \\t*]*@method[ \\t]+(?:\\S+[ \\t]+)??(\\w+)\\(~m'), array_keys(self::getExtensionMethods($class))), $name);
         if (method_exists($class, $name)) {
             // called parent::$name()
             $class = 'parent';
         }
         throw new MemberAccessException("Call to undefined method {$class}::{$name}()" . ($hint ? ", did you mean {$hint}()?" : '.'));
     }
 }
Example #21
0
 /**
  * Filter data
  * @param array $filters
  * @return self
  */
 public function filter(array $filters)
 {
     foreach ($filters as $filter) {
         if ($filter->isValueSet()) {
             if ($filter->hasConditionCallback()) {
                 $this->data = Callback::invokeArgs($filter->getConditionCallback(), [$this->data, $filter->getValue()]);
             } else {
                 $this->data = array_filter($this->data, function ($row) use($filter) {
                     return $this->applyFilter($row, $filter);
                 });
             }
         }
     }
     return $this;
 }
Example #22
0
 private function getQuery($filter, $order)
 {
     if (empty($this->queryBuilder)) {
         if (!isset($this->limit)) {
             throw new InvalidStateException('Property limit must be set.');
         }
         if (!isset($this->offset)) {
             throw new InvalidStateException('Property offset must be set.');
         }
         $this->queryBuilder = Callback::invokeArgs($this->callback, [$filter, $order]);
         $this->queryBuilder->setMaxResults($this->limit);
         $this->queryBuilder->setFirstResult($this->offset);
     }
     return new Paginator($this->queryBuilder);
 }
Example #23
0
 public function render()
 {
     $reflection = $this->getReflection();
     $className = $reflection->getName();
     $name = substr($className, strrpos($className, '\\') + 1, -strlen('Control'));
     $templatePath = dirname($reflection->getFileName()) . '/../templates/components/' . ucfirst($name) . '/default.latte';
     if (file_exists($templatePath)) {
         $this->template->setFile($templatePath);
     }
     $this->template->locale = $this->getPresenter()->locale;
     $this->template->auth = $this->auth;
     if (method_exists($this, 'beforeRender')) {
         Callback::invokeArgs([$this, 'beforeRender'], func_get_args());
     }
     $this->template->render();
 }
Example #24
0
 /**
  * @param  string $name
  * @param  array $args
  * @return void
  */
 public function __call($name, $args)
 {
     // events support
     $ref = static::getReflection();
     if (preg_match('#^on[A-Z]#', $name) && $ref->hasProperty($name)) {
         $prop = $ref->getProperty($name);
         if ($prop->isPublic() && !$prop->isStatic() && (is_array($this->{$name}) || $this->{$name} instanceof \Traversable)) {
             foreach ($this->{$name} as $cb) {
                 NCallback::invokeArgs($cb, $args);
             }
             return;
         }
     }
     $class = get_class($this);
     throw new Exception\MemberAccessException("Call to undefined method {$class}::{$name}().");
 }
Example #25
0
 public function isActive($column_name, $data)
 {
     $this->data = $data;
     if (array_key_exists(self::CALLBACK, $this->option) === FALSE) {
         return $this->data[$column_name] == $this->option[self::STATUS] ? TRUE : FALSE;
     } else {
         if (is_callable($this->option[self::CALLBACK])) {
             $args = array($data);
             if (isset($this->option[self::CALLBACK_ARGS]) && is_array($this->option[self::CALLBACK_ARGS])) {
                 $args = array_merge($args, $this->option[self::CALLBACK_ARGS]);
             }
             return Callback::invokeArgs($this->option[self::CALLBACK], $args);
         } else {
             throw new Grid_Exception('Callback in Component\\StatusButton setting is not callable.');
         }
     }
 }
Example #26
0
 /**
  * @return mixed
  * @throws MemberAccessException
  */
 public function __call($name, $args)
 {
     $class = get_class($this);
     $isProp = ObjectMixin::hasProperty($class, $name);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     } elseif ($isProp === 'event') {
         // calling event handlers
         if (is_array($this->{$name}) || $this->{$name} instanceof \Traversable) {
             foreach ($this->{$name} as $handler) {
                 Callback::invokeArgs($handler, $args);
             }
         } elseif ($this->{$name} !== NULL) {
             throw new UnexpectedValueException("Property {$class}::\${$name} must be array or NULL, " . gettype($this->{$name}) . ' given.');
         }
     } elseif ($isProp && $this->{$name} instanceof \Closure) {
         // closure in property
         trigger_error("Invoking closure in property via \$obj->{$name}() is deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
         return call_user_func_array($this->{$name}, $args);
     } elseif (($methods =& ObjectMixin::getMethods($class)) && isset($methods[$name]) && is_array($methods[$name])) {
         // magic @methods
         trigger_error("Magic methods such as {$class}::{$name}() are deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
         list($op, $rp, $type) = $methods[$name];
         if (count($args) !== ($op === 'get' ? 0 : 1)) {
             throw new InvalidArgumentException("{$class}::{$name}() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');
         } elseif ($type && $args && !ObjectMixin::checkType($args[0], $type)) {
             throw new InvalidArgumentException("Argument passed to {$class}::{$name}() must be {$type}, " . gettype($args[0]) . ' given.');
         }
         if ($op === 'get') {
             return $rp->getValue($this);
         } elseif ($op === 'set') {
             $rp->setValue($this, $args[0]);
         } elseif ($op === 'add') {
             $val = $rp->getValue($this);
             $val[] = $args[0];
             $rp->setValue($this, $val);
         }
         return $this;
     } elseif ($cb = ObjectMixin::getExtensionMethod($class, $name)) {
         // extension methods
         trigger_error("Extension methods such as {$class}::{$name}() are deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
         return Callback::invoke($cb, $this, ...$args);
     } else {
         ObjectMixin::strictCall($class, $name);
     }
 }
 /**
  * Sends response to output.
  * @return void
  */
 public function send(Nette\Http\IRequest $httpRequest, Nette\Http\IResponse $httpResponse)
 {
     $httpResponse->setContentType($this->contentType);
     $httpResponse->setHeader('Content-Disposition', ($this->forceDownload ? 'attachment' : 'inline') . '; filename="' . $this->name . '"');
     $output = NULL;
     if ($this->precalculateFileSize) {
         ob_start();
         Nette\Utils\Callback::invokeArgs($this->outputGenerator);
         $output = ob_get_clean();
         $filesize = $length = strlen($output);
     }
     if ($this->resuming && $this->precalculateFileSize) {
         $httpResponse->setHeader('Accept-Ranges', 'bytes');
         if (preg_match('#^bytes=(\\d*)-(\\d*)\\z#', $httpRequest->getHeader('Range'), $matches)) {
             list(, $start, $end) = $matches;
             if ($start === '') {
                 $start = max(0, $filesize - $end);
                 $end = $filesize - 1;
             } elseif ($end === '' || $end > $filesize - 1) {
                 $end = $filesize - 1;
             }
             if ($end < $start) {
                 $httpResponse->setCode(416);
                 // requested range not satisfiable
                 return;
             }
             $httpResponse->setCode(206);
             $httpResponse->setHeader('Content-Range', 'bytes ' . $start . '-' . $end . '/' . $filesize);
             $length = $end - $start + 1;
         } else {
             $httpResponse->setHeader('Content-Range', 'bytes 0-' . ($filesize - 1) . '/' . $filesize);
         }
     }
     if ($this->precalculateFileSize) {
         $httpResponse->setHeader('Content-Length', $length);
     }
     if (isset($start)) {
         echo substr($output, $start, $length);
     } elseif (isset($output)) {
         echo $output;
     } else {
         Nette\Utils\Callback::invoke($this->outputGenerator);
     }
 }
Example #28
0
 /**
  * __call() implementation.
  * @param  object
  * @param  string
  * @param  array
  * @return mixed
  * @throws MemberAccessException
  */
 public static function call($_this, $name, $args)
 {
     $class = get_class($_this);
     $isProp = self::hasProperty($class, $name);
     if ($name === '') {
         throw new MemberAccessException("Call to class '{$class}' method without name.");
     } elseif ($isProp === 'event') {
         // calling event handlers
         if (is_array($_this->{$name}) || $_this->{$name} instanceof \Traversable) {
             foreach ($_this->{$name} as $handler) {
                 Callback::invokeArgs($handler, $args);
             }
         } elseif ($_this->{$name} !== NULL) {
             throw new Nette\UnexpectedValueException("Property {$class}::\${$name} must be array or NULL, " . gettype($_this->{$name}) . ' given.');
         }
     } elseif ($isProp && $_this->{$name} instanceof \Closure) {
         // closure in property
         return call_user_func_array($_this->{$name}, $args);
     } elseif (($methods =& self::getMethods($class)) && isset($methods[$name]) && is_array($methods[$name])) {
         // magic @methods
         list($op, $rp, $type) = $methods[$name];
         if (count($args) !== ($op === 'get' ? 0 : 1)) {
             throw new Nette\InvalidArgumentException("{$class}::{$name}() expects " . ($op === 'get' ? 'no' : '1') . ' argument, ' . count($args) . ' given.');
         } elseif ($type && $args && !self::checkType($args[0], $type)) {
             throw new Nette\InvalidArgumentException("Argument passed to {$class}::{$name}() must be {$type}, " . gettype($args[0]) . ' given.');
         }
         if ($op === 'get') {
             return $rp->getValue($_this);
         } elseif ($op === 'set') {
             $rp->setValue($_this, $args[0]);
         } elseif ($op === 'add') {
             $val = $rp->getValue($_this);
             $val[] = $args[0];
             $rp->setValue($_this, $val);
         }
         return $_this;
     } elseif ($cb = self::getExtensionMethod($class, $name)) {
         // extension methods
         return Callback::invoke($cb, $_this, ...$args);
     } else {
         self::strictCall($class, $name, array_keys(self::getExtensionMethods($class)));
     }
 }
 /**
  * @param string $signal
  * @throws \Nette\InvalidStateException
  */
 public function signalReceived($signal)
 {
     /** @var Presenter $presenter */
     $presenter = $this->lookup('Nette\\Application\\UI\\Presenter');
     if ($signal === self::SIGNAL_NAME && $presenter->isAjax()) {
         if (!is_callable($this->dependentCallback)) {
             throw new InvalidStateException('Dependent callback not set.');
         }
         $parentsValues = array();
         foreach ($this->parents as $parent) {
             $parentsValues[$parent->getName()] = $presenter->getParameter($parent->getName());
         }
         /** @var DependentSelectBoxData $data */
         $data = Callback::invokeArgs($this->dependentCallback, array($parentsValues));
         if (!$data instanceof DependentSelectBoxData) {
             throw new \Exception('Callback for:"' . $this->getHtmlId() . '" must return DependentSelectBoxData instance!');
         }
         $items = $data->getItems();
         $value = $data->getValue();
         $presenter->payload->dependentselectbox = array('id' => $this->getHtmlId(), 'items' => $this->prepareItems($items), 'value' => $value, 'prompt' => $this->getPrompt(), 'disabledWhenEmpty' => $this->disabledWhenEmpty);
         $presenter->sendPayload();
     }
 }
Example #30
0
 /**
  * @param array|\Traversable $listeners
  * @param mixed $arg
  */
 protected function dispatchEvent($listeners, $arg = NULL)
 {
     $args = func_get_args();
     $listeners = array_shift($args);
     foreach ((array) $listeners as $handler) {
         if ($handler instanceof \Nette\Application\UI\Link) {
             /** @var \Nette\Application\UI\Link $handler */
             $refl = $handler->getReflection();
             /** @var \Nette\Reflection\ClassType $refl */
             $compRefl = $refl->getProperty('component');
             $compRefl->accessible = TRUE;
             /** @var \Nette\Application\UI\PresenterComponent $component */
             $component = $compRefl->getValue($handler);
             $component->redirect($handler->getDestination(), $handler->getParameters());
         } else {
             \Nette\Utils\Callback::invokeArgs($handler, $args);
         }
     }
 }