当前位置: 首页>>代码示例>>PHP>>正文


PHP Utils\Callback类代码示例

本文整理汇总了PHP中Nette\Utils\Callback的典型用法代码示例。如果您正苦于以下问题:PHP Callback类的具体用法?PHP Callback怎么用?PHP Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Callback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportRules

 /**
  * @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;
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:32,代码来源:Helpers.php

示例2: dispatch

 /**
  * @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.");
     }
 }
开发者ID:minetro,项目名称:mobilni-platby,代码行数:30,代码来源:CallbackDispatcher.php

示例3: __construct

 /**
  * @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;
 }
开发者ID:mike227,项目名称:n-datagrid,代码行数:12,代码来源:Action.php

示例4: createRouter

 /**
  * @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;
 }
开发者ID:brosland,项目名称:media,代码行数:36,代码来源:ImageRouterFactory.php

示例5: handleAutocomplete

 public function handleAutocomplete($q)
 {
     if (!$this->callback) {
         throw new Nette\InvalidStateException('Undefined Typehad callback.');
     }
     $this->getPresenter()->sendJson(Nette\Utils\Callback::invokeArgs($this->callback, [$q]));
 }
开发者ID:nextras,项目名称:forms,代码行数:7,代码来源:Typeahead.php

示例6: formatValue

 public function formatValue($row)
 {
     if ($this->callback) {
         return Callback::invokeArgs($this->callback, [$row, $this]);
     }
     return $this->getChainedValue($row);
 }
开发者ID:joseki,项目名称:datagrid,代码行数:7,代码来源:TextColumn.php

示例7: getBodyContent

 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;
 }
开发者ID:mesour,项目名称:datagrid,代码行数:26,代码来源:Image.php

示例8: __construct

 /**
  * @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);
         }
     }
 }
开发者ID:f3l1x,项目名称:nette-plugins,代码行数:30,代码来源:CallbackPanel.php

示例9: filter

 /**
  * 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;
 }
开发者ID:ublaboo,项目名称:datagrid,代码行数:40,代码来源:FilterableDataSource.php

示例10: addCallbackItem

 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;
 }
开发者ID:mesour,项目名称:datagrid,代码行数:8,代码来源:SubItem.php

示例11: __call

 /**
  * 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);
 }
开发者ID:JakubKontra,项目名称:datagrid,代码行数:14,代码来源:Object.php

示例12: __call

 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);
     }
 }
开发者ID:JanTvrdik,项目名称:nextras-orm,代码行数:8,代码来源:TestMapper.php

示例13: getLink

 /**
  * 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;
     }
 }
开发者ID:janlavicka,项目名称:datagrid,代码行数:15,代码来源:Action.php

示例14: deny

 /**
  * 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);
 }
开发者ID:arachne,项目名称:security,代码行数:19,代码来源:Permission.php

示例15: validate

 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);
 }
开发者ID:sw2eu,项目名称:form-factory,代码行数:9,代码来源:Form.php


注:本文中的Nette\Utils\Callback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。