本文整理汇总了PHP中Nette\Utils\Callback::closure方法的典型用法代码示例。如果您正苦于以下问题:PHP Callback::closure方法的具体用法?PHP Callback::closure怎么用?PHP Callback::closure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Callback
的用法示例。
在下文中一共展示了Callback::closure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
}
}
示例2: addContentMenu
/**
* @param string $name
* @param callable $callback
*/
public function addContentMenu($name, $callback)
{
if (isset($this->contentMenu[$name])) {
throw new InvalidArgumentException(sprintf('Content menu \'%s\' is already exists.', $name));
}
$this->contentMenu[$name] = Callback::closure($callback);
}
示例3: load
/**
* Reads the specified item from the cache or generate it.
* @param mixed key
* @param callable
* @return mixed|NULL
*/
public function load($key, $fallback = NULL)
{
$data = $this->storage->read($this->generateKey($key));
if ($data === NULL && $fallback) {
return $this->save($key, Callback::closure($fallback));
}
return $data;
}
示例4: __construct
/**
* @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;
}
}
示例5: getPanel
/**
* Renders HTML code for custom panel.
* @return string
*/
public function getPanel()
{
if (!$this->resources) {
return null;
}
$esc = \Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml');
$click = function ($o, $c = false) {
return \Tracy\Dumper::toHtml($o, ['collapse' => $c]);
};
ob_start();
include __DIR__ . '/panel.phtml';
return ob_get_clean();
}
示例6: getPanel
/**
* @return string
*/
public function getPanel()
{
if (!$this->calls) {
return NULL;
}
ob_start();
$esc = function ($s) {
return htmlSpecialChars($s, ENT_QUOTES, 'UTF-8');
};
$click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) {
return \Tracy\Dumper::toHtml($o, array('collapse' => $c));
} : Callback::closure('\\Tracy\\Helpers::clickableDump');
$totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
require __DIR__ . '/panel.phtml';
return ob_get_clean();
}
示例7: getPanel
/**
* @return string
*/
public function getPanel()
{
if (!$this->calls) {
return NULL;
}
ob_start();
if (class_exists('Latte\\Runtime\\Filters')) {
$esc = Nette\Utils\Callback::closure('Latte\\Runtime\\Filters::escapeHtml');
} else {
$esc = 'Nette\\Templating\\Helpers::escapeHtml';
}
$click = class_exists('\\Tracy\\Dumper') ? function ($o, $c = FALSE) {
return \Tracy\Dumper::toHtml($o, array('collapse' => $c));
} : '\\Tracy\\Helpers::clickableDump';
$totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
require __DIR__ . '/panel.phtml';
return ob_get_clean();
}
示例8: getClosure
public function getClosure()
{
return PHP_VERSION_ID < 50400 ? Nette\Utils\Callback::closure($this->value) : parent::getClosure();
}
示例9: render
/** @return void */
public function render()
{
$template = $this->createTemplate();
$template->grid = $this;
$template->defaultTemplate = __DIR__ . '/DataGrid.latte';
$template->setFile($this->templateFile === NULL ? $this->templateFile = $template->defaultTemplate : $this->templateFile);
$grid = $this;
$latte = $template->getLatte();
$latte->addFilter('translate', $this->translate);
$latte->addFilter('primaryToString', $this->getRecord()->primaryToString);
$latte->addFilter('getValue', $this->getRecord()->getValue);
$latte->addFilter('sortLink', function (Components\Column $c, $m = Helpers::SORT_LINK_SINGLE) use($grid) {
return Helpers::createSortLink($grid, $c, $m);
});
$this->isControlInvalid() && $this->redraw(FALSE, 'flashes');
$template->form = $template->_form = $form = $this['form'];
$this->presenter->payload->twiGrid['forms'][$form->elementPrototype->id] = (string) $form->getAction();
$template->columns = $this->getColumns();
$template->dataLoader = NCallback::closure($this, 'getData');
$template->csrfToken = Helpers::getCsrfToken($this->session, $this->sessNamespace);
$template->rowActions = $this->getRowActions();
$template->hasRowActions = $template->rowActions !== NULL;
$template->groupActions = $this->getGroupActions();
$template->hasGroupActions = $template->groupActions !== NULL;
$template->hasFilters = $this->filterFactory !== NULL;
$template->hasInlineEdit = $this->ieContainerFactory !== NULL;
$template->iePrimary = $this->iePrimary;
$template->isPaginated = $this->itemsPerPage !== NULL;
$template->columnCount = count($template->columns) + ($template->hasGroupActions ? 1 : 0) + ($template->hasFilters || $template->hasRowActions ? 1 : 0);
$template->render();
}
示例10: setExtensionMethod
/**
* Adds a method to class.
* @param string
* @param string
* @param mixed callable
* @return void
*/
public static function setExtensionMethod($class, $name, $callback)
{
$name = strtolower($name);
self::$extMethods[$name][$class] = Nette\Utils\Callback::closure($callback);
self::$extMethods[$name][''] = NULL;
}
示例11: ucfirst
/**
* __get() implementation.
* @param object
* @param string property name
* @return mixed property value
* @throws MemberAccessException if the property is not defined.
*/
public static function &get($_this, string $name)
{
$class = get_class($_this);
$uname = ucfirst($name);
$methods =& self::getMethods($class);
if ($name === '') {
throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
} elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
// property getter
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
if ($methods[$m] === TRUE) {
return $_this->{$m}();
} else {
$val = $_this->{$m}();
return $val;
}
} elseif (isset($methods[$name])) {
// public method as closure getter
if (preg_match('#^(is|get|has)([A-Z]|$)#', $name) && !(new \ReflectionMethod($class, $name))->getNumberOfRequiredParameters()) {
$source = '';
foreach (debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
if (isset($item['file']) && dirname($item['file']) !== __DIR__) {
$source = " in {$item['file']}:{$item['line']}";
break;
}
}
trigger_error("Did you forget parentheses after {$name}{$source}?", E_USER_WARNING);
}
$val = Callback::closure($_this, $name);
return $val;
} elseif (isset($methods['set' . $uname])) {
// strict class
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
} else {
// strict class
$hint = self::getSuggestion(array_merge(array_keys(get_class_vars($class)), self::parseFullDoc($class, '~^[ \\t*]*@property(?:-read)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
throw new MemberAccessException("Cannot read an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
}
}
示例12: getPanel
/**
* @return string
*/
public function getPanel()
{
if (!$this->queries) {
return NULL;
}
$esc = function ($s) {
return htmlSpecialChars($s, ENT_QUOTES, 'UTF-8');
};
$click = class_exists('Tracy\\Dumper') ? function ($o, $c = FALSE, $d = 4) {
return Dumper::toHtml($o, array(Dumper::COLLAPSE => $c, Dumper::DEPTH => $d, Dumper::TRUNCATE => 2000));
} : Nette\Utils\Callback::closure('Tracy\\Helpers::clickableDump');
$totalTime = $this->totalTime ? sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : 'none';
$extractData = function ($object) {
if ($object instanceof Elastica\Request) {
$data = $object->getData();
} elseif ($object instanceof Elastica\Response) {
$data = $object->getData();
} else {
return array();
}
if ($object instanceof Elastica\Request) {
$json = Json::decode((string) $object);
return $json->data;
}
try {
return !is_array($data) ? Json::decode($data, Json::FORCE_ARRAY) : $data;
} catch (Nette\Utils\JsonException $e) {
try {
return array_map(function ($row) {
return Json::decode($row, Json::FORCE_ARRAY);
}, explode("\n", trim($data)));
} catch (Nette\Utils\JsonException $e) {
return $data;
}
}
};
$processedQueries = array();
$allQueries = $this->queries;
foreach ($allQueries as $authority => $requests) {
/** @var Elastica\Request[] $item */
foreach ($requests as $i => $item) {
$processedQueries[$authority][$i] = $item;
if (isset($item[3])) {
continue;
// exception, do not re-execute
}
if (stripos($item[0]->getPath(), '_search') === FALSE || $item[0]->getMethod() !== 'GET') {
continue;
// explain only search queries
}
if (!is_array($data = $extractData($item[0]))) {
continue;
}
try {
$response = $this->client->request($item[0]->getPath(), $item[0]->getMethod(), $item[0]->getData(), array('explain' => 1) + $item[0]->getQuery());
// replace the search response with the explained response
$processedQueries[$authority][$i][1] = $response;
} catch (\Exception $e) {
// ignore
}
}
}
ob_start();
require __DIR__ . '/panel.phtml';
return ob_get_clean();
}
示例13:
/**
* @param $name
* @throws MemberAccessException
* @return mixed
*/
public function &__get($name)
{
if (!isset($this->autowireProperties[$name])) {
return parent::__get($name);
}
if (empty($this->autowireProperties[$name]['value'])) {
if (!empty($this->autowireProperties[$name]['factory'])) {
$factory = Callback::closure($this->autowirePropertiesLocator->getService($this->autowireProperties[$name]['factory']), 'create');
$this->autowireProperties[$name]['value'] = Callback::invokeArgs($factory, $this->autowireProperties[$name]['arguments']);
} else {
$this->autowireProperties[$name]['value'] = $this->autowirePropertiesLocator->getByType($this->autowireProperties[$name]['type']);
}
}
return $this->autowireProperties[$name]['value'];
}
示例14: ucfirst
/**
* __get() implementation.
* @param object
* @param string property name
* @return mixed property value
* @throws MemberAccessException if the property is not defined.
*/
public static function &get($_this, $name)
{
$class = get_class($_this);
$uname = ucfirst($name);
$methods =& self::getMethods($class);
if ($name === '') {
throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
} elseif (isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
// property getter
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
if ($methods[$m] === TRUE) {
return $_this->{$m}();
} else {
$val = $_this->{$m}();
return $val;
}
} elseif (isset($methods[$name])) {
// public method as closure getter
$val = Callback::closure($_this, $name);
return $val;
} elseif (isset($methods['set' . $uname])) {
// strict class
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
} else {
// strict class
$hint = self::getSuggestion(array_merge(array_keys(get_class_vars($class)), self::parseFullDoc($class, '~^[ \\t*]*@property(?:-read)?[ \\t]+(?:\\S+[ \\t]+)??\\$(\\w+)~m')), $name);
throw new MemberAccessException("Cannot read an undeclared property {$class}::\${$name}" . ($hint ? ", did you mean \${$hint}?" : '.'));
}
}
示例15: ucfirst
/**
* @return mixed property value
* @throws MemberAccessException if the property is not defined.
*/
public function &__get($name)
{
$class = get_class($this);
$uname = ucfirst($name);
if ($prop = ObjectMixin::getMagicProperty($class, $name)) {
// property getter
if (!($prop & 0b1)) {
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
}
$m = ($prop & 0b10 ? 'get' : 'is') . $uname;
if ($prop & 0b100) {
// return by reference
return $this->{$m}();
} else {
$val = $this->{$m}();
return $val;
}
} elseif ($name === '') {
throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
} elseif (($methods =& ObjectMixin::getMethods($class)) && isset($methods[$m = 'get' . $uname]) || isset($methods[$m = 'is' . $uname])) {
// old property getter
trigger_error("Add annotation @property for {$class}::\${$name} or use {$m}()" . ObjectMixin::getSource(), E_USER_DEPRECATED);
if ($methods[$m] === 0) {
$methods[$m] = (new \ReflectionMethod($class, $m))->returnsReference();
}
if ($methods[$m] === TRUE) {
return $this->{$m}();
} else {
$val = $this->{$m}();
return $val;
}
} elseif (isset($methods[$name])) {
// public method as closure getter
trigger_error("Accessing methods as properties via \$obj->{$name} is deprecated" . ObjectMixin::getSource(), E_USER_DEPRECATED);
$val = Callback::closure($this, $name);
return $val;
} elseif (isset($methods['set' . $uname])) {
// property getter
throw new MemberAccessException("Cannot read a write-only property {$class}::\${$name}.");
} else {
ObjectMixin::strictGet($class, $name);
}
}