check() public static method

public static check ( $callable, $syntax = FALSE ) : callable
return callable
Example #1
0
 /**
  * @param string   $name
  * @param string   $caption
  * @param callable $callback
  */
 public function __construct($name, $caption, $callback)
 {
     $this->name = $name;
     $this->caption = $caption;
     Callback::check($callback);
     $this->callback = $callback;
 }
Example #2
0
 public function getHeaderContent()
 {
     if (array_key_exists(self::CALLBACK, $this->option)) {
         Callback::check($this->option[self::CALLBACK]);
     }
     return $this->getTranslator() ? $this->getTranslator()->translate($this->option[self::HEADER]) : $this->option[self::HEADER];
 }
Example #3
0
 public function addCallbackItem($name, $description, $callback)
 {
     $this->check($name);
     Callback::check($callback);
     $item = new CallbackItem($this, $name, $description, $callback);
     $this->items[$name] = $item;
     return $item;
 }
 public function setQueues(array $queues)
 {
     $this->queues = array();
     foreach ($queues as $name => $queue) {
         if (!isset($queue['callback'])) {
             throw new InvalidArgumentException("The queue '{$name}' is missing a callback.");
         }
         Callback::check($queue['callback']);
         $this->queues[$name] = $queue;
     }
 }
Example #5
0
 public function addMacro($name, $begin, $end = NULL, $attr = NULL)
 {
     foreach (array($begin, $end, $attr) as $arg) {
         if ($arg && !is_string($arg)) {
             Nette\Utils\Callback::check($arg);
         }
     }
     $this->macros[$name] = array($begin, $end, $attr);
     $this->compiler->addMacro($name, $this);
     return $this;
 }
Example #6
0
 /**
  * @param  NSelection $selection
  * @param  string|callable $entity
  * @param  string $refTable
  * @param  string $refColumn
  */
 public function __construct(NSelection $selection, $entity, $refTable = NULL, $refColumn = NULL)
 {
     $this->selection = $selection;
     $this->refTable = $refTable;
     $this->refColumn = $refColumn;
     try {
         NCallback::check($entity);
         $this->entity = NCallback::closure($entity);
     } catch (\Exception $e) {
         $this->entity = $entity;
     }
 }
Example #7
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 #8
0
	/**
	 * @return Nette\Application\IResponse
	 */
	public function run(Application\Request $request)
	{
		$this->request = $request;

		if ($this->httpRequest && $this->router && !$this->httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
			$refUrl = clone $this->httpRequest->getUrl();
			$url = $this->router->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
			if ($url !== NULL && !$this->httpRequest->getUrl()->isEqual($url)) {
				return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
			}
		}

		$params = $request->getParameters();
		if (!isset($params['callback'])) {
			throw new Application\BadRequestException('Parameter callback is missing.');
		}
		$params['presenter'] = $this;
		$callback = $params['callback'];
		$reflection = Nette\Utils\Callback::toReflection(Nette\Utils\Callback::check($callback));
		$params = Application\UI\PresenterComponentReflection::combineArgs($reflection, $params);

		if ($this->context) {
			foreach ($reflection->getParameters() as $param) {
				if ($param->getClassName()) {
					unset($params[$param->getPosition()]);
				}
			}

			$params = Nette\DI\Helpers::autowireArguments($reflection, $params, $this->context);
			$params['presenter'] = $this;
		}

		$response = call_user_func_array($callback, $params);

		if (is_string($response)) {
			$response = array($response, array());
		}
		if (is_array($response)) {
			list($templateSource, $templateParams) = $response;
			$response = $this->createTemplate()->setParameters($templateParams);
			if (!$templateSource instanceof \SplFileInfo) {
				$response->getLatte()->setLoader(new Latte\Loaders\StringLoader);
			}
			$response->setFile($templateSource);
		}
		if ($response instanceof Application\UI\ITemplate) {
			return new Responses\TextResponse($response);
		} else {
			return $response;
		}
	}
 /**
  * @param  mixed   class, object, callable
  * @param  string  method
  * @return \Closure
  */
 public static function closure($callable, $m = NULL)
 {
     if ($m !== NULL) {
         $callable = array($callable, $m);
     } elseif ($callable instanceof \Closure) {
         return $callable;
     }
     self::check($callable, TRUE);
     $_callable_ = $callable;
     return function () use($_callable_) {
         Callback::check($_callable_);
         return call_user_func_array($_callable_, func_get_args());
     };
 }
Example #10
0
 /**
  * @param array|\Traversable $array
  * @param callable $callback
  * @return array
  */
 public static function flatMapAssoc($array, $callback)
 {
     Callback::check($callback);
     $result = array();
     $walker = function ($array, $keys = array()) use(&$walker, &$result, $callback) {
         foreach ($array as $key => $value) {
             $currentKeys = $keys + array(count($keys) => $key);
             if (is_array($value)) {
                 $walker($value, $currentKeys);
                 continue;
             }
             $result[] = $callback($value, $currentKeys);
         }
         return $result;
     };
     return $walker($array);
 }
Example #11
0
 /**
  * Adds a filter callback.
  * @param  callable
  * @return self
  */
 public function addFilter($filter)
 {
     Nette\Utils\Callback::check($filter);
     $this->rules[] = $rule = new Rule();
     $rule->control = $this->control;
     $rule->validator = function (IControl $control) use($filter) {
         $control->setValue(call_user_func($filter, $control->getValue()));
         return TRUE;
     };
     return $this;
 }
Example #12
0
 /**
  * @param string|callable $callback
  * @return self
  */
 public function setRowIdentifierCallback($callback)
 {
     Callback::check($callback);
     $this->rowIdentifierCallback = $callback;
     return $this;
 }
Example #13
0
 public function setPagination($itemsPerPage, $itemsCountCallback = NULL)
 {
     if ($itemsPerPage === FALSE) {
         $this->paginator = NULL;
         $this->paginatorItemsCountCallback = NULL;
     } else {
         if ($itemsCountCallback === NULL) {
             throw new \InvalidArgumentException('Items count callback must be set.');
         }
         Callback::check($itemsCountCallback);
         $this->paginator = new Paginator();
         $this->paginator->itemsPerPage = $itemsPerPage;
         $this->paginatorItemsCountCallback = $itemsCountCallback;
     }
 }
Example #14
0
 /**
  * @param string $caption column's textual caption
  * @param string $format date format supported by $func
  * @param string $func function to format date
  */
 public function __construct($caption = NULL, $format = '%x', $func = 'strftime')
 {
     parent::__construct($caption);
     $this->format = $format;
     $this->func = \Nette\Utils\Callback::check($func);
 }
Example #15
0
 public function setFilterFormFactory($filterFormFactory)
 {
     Callback::check($filterFormFactory);
     $this->filterFormFactory = $filterFormFactory;
 }
Example #16
0
 /**
  * @param callback|NULL $rowLinkCallback
  * @return $this
  */
 public function setRowLinkCallback($rowLinkCallback)
 {
     if ($rowLinkCallback !== NULL) {
         Callback::check($rowLinkCallback);
     }
     $this->rowLinkCallback = $rowLinkCallback;
     return $this;
 }
Example #17
0
 public function __construct(\Traversable $iterator, $callback)
 {
     parent::__construct($iterator);
     $this->callback = Nette\Utils\Callback::check($callback);
 }
Example #18
0
 protected function successCallback()
 {
     if ($this->delete && $this->defaultValue) {
         $this->storage->delete($this->defaultValue);
         $this->defaultValue = NULL;
     }
     if ($this->value instanceof FileUpload && $this->value->isOk()) {
         // Upload
         $image = $this->value->toImage();
         foreach (array_merge($this->onBeforeSave, $this->onUpload) as $callback) {
             Callback::check($callback);
             $image = $callback($image);
             if (!$image instanceof Image) {
                 throw new ImageStorageException('Callback must return value instance of Nette\\Utils\\Image');
             }
         }
         $this->uploadedImage = $this->value = $this->storage->saveImage($image, $this->value->getSanitizedName(), $this->namespace, function ($image) {
             foreach ($this->onSave as $callback) {
                 Callback::check($callback);
                 $callback($image);
             }
         });
     } else {
         $this->value = $this->defaultValue;
     }
     $this->checkbox->setImageName($this->value);
 }
Example #19
0
 /**
  * @param callable $callback
  */
 public function addFormatter($callback)
 {
     Callback::check($callback);
     $this->formatters[] = $callback;
 }
 public function inTransaction($callback, array $args = [])
 {
     Callback::check($callback);
     $this->connection->begin();
     try {
         $result = Callback::invokeArgs($callback, $args);
     } catch (\Exception $e) {
         $this->connection->rollback();
         throw $e;
     }
     $this->connection->commit();
     return $result;
 }
 public function __construct($callback)
 {
     $this->callback = Callback::check($callback);
 }
Example #22
0
 public function addCondition($callback)
 {
     Callback::check($callback);
     $this->condition = $callback;
 }
Example #23
0
 /**
  * @param mixed $callback
  */
 public function setCallback($callback)
 {
     Callback::check($callback);
     $this->callback = $callback;
 }
 /**
  * @param callable
  * @return void
  */
 public function execute($callback)
 {
     $this->callbacks[] = Callback::check($callback);
 }
Example #25
0
 /**
  * Registers callback as template compile-time filter.
  * @param  callable
  * @return self
  */
 public function registerFilter($callback)
 {
     if ($callback instanceof Latte\Engine) {
         // back compatibility
         $this->latte = $callback;
     } elseif (is_array($callback) && $callback[0] instanceof Latte\Engine) {
         $this->latte = $callback[0];
     } elseif (strpos(Callback::toString($callback), 'Latte\\Engine') !== FALSE) {
         $this->latte = TRUE;
     } elseif ($this->latte) {
         throw new Nette\DeprecatedException('Adding filters after Latte is not possible.');
     } else {
         $this->filters[] = Callback::check($callback);
     }
     return $this;
 }
Example #26
0
 /**
  * Appends input string filter callback.
  * @param  callable
  * @return self
  * @deprecated
  */
 public function addFilter($filter)
 {
     $this->filters[] = Nette\Utils\Callback::check($filter);
     return $this;
 }
Example #27
0
 /**
  * @param callable
  */
 public function __construct($factory)
 {
     parent::__construct();
     $this->factory = Nette\Utils\Callback::check($factory);
 }
Example #28
0
 /**
  * Adds a method to class.
  * @param  string
  * @param  string
  * @param  mixed   callable
  * @return void
  */
 public static function setExtensionMethod(string $class, string $name, callable $callback)
 {
     $name = strtolower($name);
     self::$extMethods[$name][$class] = Callback::check($callback);
     self::$extMethods[$name][''] = NULL;
 }
Example #29
0
 /**
  * Registers callback as template compile-time filter.
  * @param  callable
  * @return self
  */
 public function registerFilter($callback)
 {
     $this->filters[] = Callback::check($callback);
     return $this;
 }
Example #30
0
 /**
  * @param int|NULL $index
  * @param callable $item
  */
 public function offsetSet($index, $item)
 {
     Callback::check($item, TRUE);
     if ($index === NULL) {
         // append
         $this->listeners[] = $item;
     } else {
         // replace
         $this->listeners[$index] = $item;
     }
 }