作者:rostenkowsk
项目:nett
/**
* @return array
*/
public static function exportRules(Rules $rules, $json = TRUE)
{
$payload = array();
foreach ($rules as $rule) {
if (!is_string($op = $rule->validator)) {
if (!Nette\Utils\Callback::isStatic($op)) {
continue;
}
$op = Nette\Utils\Callback::toString($op);
}
if ($rule->branch) {
$item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'rules' => static::exportRules($rule->branch, FALSE), 'control' => $rule->control->getHtmlName());
if ($rule->branch->getToggles()) {
$item['toggle'] = $rule->branch->getToggles();
}
} else {
$item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => Validator::formatMessage($rule, FALSE));
}
if (is_array($rule->arg)) {
foreach ($rule->arg as $key => $value) {
$item['arg'][$key] = $value instanceof IControl ? array('control' => $value->getHtmlName()) : $value;
}
} elseif ($rule->arg !== NULL) {
$item['arg'] = $rule->arg instanceof IControl ? array('control' => $rule->arg->getHtmlName()) : $rule->arg;
}
$payload[] = $item;
}
return $json ? $payload ? Nette\Utils\Json::encode($payload) : NULL : $payload;
}
作者:minetr
项目:mobilni-platb
/**
* @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.");
}
}
作者:mike22
项目:n-datagri
/**
* @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;
}
作者:broslan
项目:medi
/**
* @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;
}
作者:nextra
项目:form
public function handleAutocomplete($q)
{
if (!$this->callback) {
throw new Nette\InvalidStateException('Undefined Typehad callback.');
}
$this->getPresenter()->sendJson(Nette\Utils\Callback::invokeArgs($this->callback, [$q]));
}
作者:josek
项目:datagri
public function formatValue($row)
{
if ($this->callback) {
return Callback::invokeArgs($this->callback, [$row, $this]);
}
return $this->getChainedValue($row);
}
作者:mesou
项目:datagri
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;
}
作者:f3l1
项目:nette-plugin
/**
* @param Container $container
* @param array $callbacks [optional]
*/
public function __construct(Container $container, $callbacks = [])
{
$this->container = $container;
/** @var $httpRequest Request */
$request = $container->getService("httpRequest");
// Determine production/development mode
$this->active = !Debugger::$productionMode;
// # Clean cache
$this->callbacks["cache"] = ['name' => "Clear cache", 'callback' => Callback::closure($this, "clearCache"), 'args' => [[Cache::ALL => TRUE]]];
// # Clean session
$this->callbacks["session"] = ['name' => "Clear session", 'callback' => Callback::closure($this, "clearSession"), 'args' => []];
// # Clean logs
$this->callbacks["logs"] = ['name' => "Clear logs", 'callback' => Callback::closure($this, "clearLogs"), 'args' => [[Cache::ALL => TRUE]]];
// Merge custom callbacks
$this->callbacks = array_merge($this->callbacks, $callbacks);
// Check signal receiver
if ($this->active && ($cb = $request->getQuery("callback-do", FALSE))) {
if ($cb === "all") {
$this->onCallbacksCall();
$this->invokeCallbacks();
} else {
$this->onCallbackCall($cb);
$this->invokeCallback($cb);
}
}
}
作者:ublabo
项目:datagri
/**
* 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;
}
作者:mesou
项目:datagri
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;
}
作者:JakubKontr
项目:datagri
/**
* 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);
}
作者:JanTvrdi
项目:nextras-or
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);
}
}
作者:janlavick
项目:datagri
/**
* 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;
}
}
作者:arachn
项目:securit
/**
* Denies one or more Roles access to [certain $privileges upon] the specified Resource(s).
* If $assertion is provided, then it must return TRUE in order for rule to apply.
*
* @param string|array|Permission::ALL $roles
* @param string|array|Permission::ALL $resources
* @param string|array|Permission::ALL $privileges
* @param callable $assertion
* @return self
*/
public function deny($roles = self::ALL, $resources = self::ALL, $privileges = self::ALL, $assertion = null)
{
if ($assertion !== null) {
$assertion = function () use($assertion) {
return Callback::invoke($assertion, $this->identity, $this->getQueriedResource(), $this->getQueriedRole());
};
}
return parent::deny($roles, $resources, $privileges, $assertion);
}
作者:sw2e
项目:form-factor
public function validate(array $controls = NULL)
{
foreach ($this->beforeValidate ?: [] as $handler) {
$params = Callback::toReflection($handler)->getParameters();
$values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
$this->values = Callback::invoke($handler, $this, $values);
}
parent::validate($controls);
}
作者:venn
项目:data-transfe
private function loadRows()
{
if (is_callable($this->rows)) {
$this->rows = Callback::invoke($this->rows);
if (!is_array($this->rows)) {
throw new \Nette\InvalidStateException(sprintf('Rows must be array of values or callable array source, %s given.', gettype($this->rows)));
}
}
}
作者:vojty
项目:typeahea
/**
* @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]));
}
作者:HotelQuickl
项目:RabbitM
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;
}
}
作者:pecinao
项目:doctrine-mappe
/**
* Get throw getter
*
* @param string $propertyName
* @param object $entity
* @return null
*/
protected function invokeGetter($propertyName, $entity)
{
$getterName = ['get' . ucfirst($propertyName), 'is' . ucfirst($propertyName)];
$value = NULL;
foreach ($getterName as $getter) {
if (method_exists($entity, $getter) && $value === NULL) {
$value = Callback::invoke([$entity, $getter]);
}
}
return $value;
}
作者:janlavick
项目:datagri
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();
}