本文整理汇总了PHP中Nette\Callback类的典型用法代码示例。如果您正苦于以下问题:PHP Callback类的具体用法?PHP Callback怎么用?PHP Callback使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Callback类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: run
/**
* @return Nette\Application\IResponse
*/
public function run(Application\Request $request)
{
$this->request = $request;
$httpRequest = $this->context->getByType('Nette\\Http\\IRequest');
if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
$refUrl = clone $httpRequest->getUrl();
$url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
if ($url !== NULL && !$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 = new Nette\Callback($params['callback']);
$response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params));
if (is_string($response)) {
$response = array($response, array());
}
if (is_array($response)) {
if ($response[0] instanceof \SplFileInfo) {
$response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]);
} else {
$response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]);
}
}
if ($response instanceof Nette\Templating\ITemplate) {
return new Responses\TextResponse($response);
} else {
return $response;
}
}
开发者ID:svobodni,项目名称:web,代码行数:37,代码来源:MicroPresenter.php
示例2: attached
public function attached($presenter)
{
parent::attached($presenter);
$this->column = $this->lookup('Brabijan\\Datagrid\\Renderer')->getColumn($this->columnId);
if ($this->templateRowCallback) {
$this->templateRowCallback->invokeArgs(array($this));
}
}
开发者ID:brabijan,项目名称:datagrid,代码行数:8,代码来源:Column.php
示例3: setDisabled
/**
* @param $callback
* @return $this
* @throws \movi\InvalidArgumentException
*/
public function setDisabled($callback)
{
if (!is_callable($callback)) {
throw new InvalidArgumentException('Callback is not callable');
}
$this->disabled = Callback::create($callback);
return $this;
}
开发者ID:peterzadori,项目名称:movi,代码行数:13,代码来源:Boolean.php
示例4: loader
/**
* @param $helper
* @return callable
* @throws \movi\InvalidArgumentException
*/
public function loader($helper)
{
if (isset($this->helpers[$helper])) {
return Callback::create($this->helpers[$helper], 'process');
} else {
return false;
}
}
开发者ID:peterzadori,项目名称:movi,代码行数:13,代码来源:Helpers.php
示例5: onSuccess
public function onSuccess(Form $form)
{
if (!Callback::create($this->checkConnection)->invoke() || !$this->schemaManager->tablesExist('users')) {
return;
}
$presenter = $form->presenter;
$logEntity = new LogEntity($this->user instanceof UserEntity ? $this->user : NULL, 'Venne\\Forms\\Form', NULL, LogEntity::ACTION_OTHER);
$logEntity->setType($presenter->link('this'));
$logEntity->setMessage('Configuration has been updated');
$this->logRepository->save($logEntity);
}
开发者ID:svobodni,项目名称:web,代码行数:11,代码来源:FormLogListener.php
示例6: signalReceived
public function signalReceived($signal)
{
$query = $this->form->presenter->request->parameters['q'];
if (!$this->suggestCallback) {
throw new InvalidArgumentException("Property 'suggestCallback' is not defined.");
}
$data = Callback::create($this->suggestCallback)->invoke($query);
if (!is_array($data)) {
throw new InvalidArgumentException("Data from suggestCallback must be array.");
}
$this->form->getPresenter()->sendResponse(new JsonResponse(array('results' => $data, 'more' => FALSE)));
}
开发者ID:svobodni,项目名称:web,代码行数:12,代码来源:TagsInput.php
示例7: getMPDF
/**
* Returns mPDF object
* @return mPDFExtended
*/
public function getMPDF() {
if(!$this->mPDF instanceof mPDF) {
if($this->createMPDF instanceof Callback && $this->createMPDF->isCallable()) {
$mpdf = $this->createMPDF->invoke($this);
if(!($mpdf instanceof \mPDF)) {
throw new \Nette\InvalidStateException("Callback function createMPDF must return mPDF object!");
}
$this->mPDF = $mpdf;
}else
throw new \Nette\InvalidStateException("Callback createMPDF is not callable or is not instance of Nette\Callback!");
}
return $this->mPDF;
}
开发者ID:Johnik010,项目名称:rezervace,代码行数:17,代码来源:PDFResponse.php
示例8: log
/**
* Logs message or exception to file and sends email notification.
* @param string|array
* @param int one of constant INFO, WARNING, ERROR (sends email), CRITICAL (sends email)
* @return bool was successful?
*/
public function log($message, $priority = self::INFO)
{
if (!is_dir($this->directory)) {
throw new Nette\DirectoryNotFoundException("Directory '{$this->directory}' is not found or is not directory.");
}
if (is_array($message)) {
$message = implode(' ', $message);
}
$res = error_log(trim($message) . PHP_EOL, 3, $this->directory . '/' . strtolower($priority) . '.log');
if (($priority === self::ERROR || $priority === self::CRITICAL) && $this->email && $this->mailer && @filemtime($this->directory . '/email-sent') + self::$emailSnooze < time() && @file_put_contents($this->directory . '/email-sent', 'sent')) {
Nette\Callback::create($this->mailer)->invoke($message, $this->email);
}
return $res;
}
开发者ID:anagio,项目名称:woocommerce,代码行数:20,代码来源:Logger.php
示例9: render
public function render()
{
if ($this->customTemplate === NULL) {
$this->template->setFile(__DIR__ . '/control.latte');
} else {
$this->template->setFile($this->customTemplate);
$this->template->extend = __DIR__ . '/control.latte';
}
$this->template->rows = array_keys($this->getData());
if ($this->isPaginatorEnabled()) {
$this->template->paginationPosition = $this->paginationPositions;
$this->template->paginator = $this->paginator;
} else {
$this->template->paginationPosition = Renderer::PAGINATION_NONE;
}
if ($this->templateHelpersCallback) {
$this->templateHelpersCallback->invokeArgs(array($this->template));
}
$this->template->showFilter = ($this->filterManualRender == FALSE and $this->filterFormFactory !== NULL);
$this->template->showHeaders = !$this->hideDatagridHeaders;
$this->template->render();
}
开发者ID:brabijan,项目名称:datagrid,代码行数:22,代码来源:Renderer.php
示例10: call
/**
* __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) {
Nette\Callback::create($handler)->invokeArgs($args);
}
} elseif ($_this->{$name} !== NULL) {
throw new UnexpectedValueException("Property {$class}::\${$name} must be array or NULL, " . gettype($_this->{$name}) . " given.");
}
} elseif ($cb = Reflection\ClassType::from($_this)->getExtensionMethod($name)) {
// extension methods
array_unshift($args, $_this);
return $cb->invokeArgs($args);
} else {
throw new MemberAccessException("Call to undefined method {$class}::{$name}().");
}
}
开发者ID:cujan,项目名称:atlas-mineralov-a-hornin,代码行数:31,代码来源:ObjectMixin.php
示例11: handleSave
public function handleSave(Form $form)
{
if ($form->hasSaveButton() && $form->isSubmitted() === $form->getSaveButton()) {
try {
$this->mapper->entityManager->getRepository(get_class($form->data))->save($form->data);
} catch (\Exception $e) {
$ok = true;
if (is_array($this->onCatchError) || $this->onCatchError instanceof \Traversable) {
foreach ($this->onCatchError as $handler) {
if (\Nette\Callback::create($handler)->invokeArgs(array($form, $e))) {
$ok = false;
break;
}
}
} elseif ($this->onCatchError !== NULL) {
$class = get_class($this);
throw new \Nette\UnexpectedValueException("Property {$class}::onCatchError must be array or NULL, " . gettype($this->onCatchError) . " given.");
}
if ($ok) {
throw $e;
}
}
}
}
开发者ID:svobodni,项目名称:web,代码行数:24,代码来源:FormFactory.php
示例12: handleSetParent
public function handleSetParent($from = NULL, $to = NULL, $dropmode = NULL)
{
Callback::create($this->dropCallback)->invoke($from, $to, $dropmode);
}
开发者ID:svobodni,项目名称:web,代码行数:4,代码来源:BrowserControl.php
示例13: 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);
if (!isset(self::$methods[$class])) {
self::$methods[$class] = array_flip(get_class_methods($class));
// public (static and non-static) methods
}
if ($name === '') {
throw new MemberAccessException("Cannot read a class '{$class}' property without name.");
} elseif (isset(self::$methods[$class][$m = 'get' . $uname]) || isset(self::$methods[$class][$m = 'is' . $uname])) {
// property getter
$val = $_this->{$m}();
return $val;
} elseif (isset(self::$methods[$class][$name])) {
// public method as closure getter
$val = Callback::create($_this, $name);
return $val;
} else {
// strict class
$type = isset(self::$methods[$class]['set' . $uname]) ? 'a write-only' : 'an undeclared';
throw new MemberAccessException("Cannot read {$type} property {$class}::\${$name}.");
}
}
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:33,代码来源:ObjectMixin.php
示例14: callMethod
/**
* Calls method using autowiring.
* @param mixed class, object, function, callable
* @param array arguments
* @return mixed
*/
public function callMethod($function, array $args = array())
{
$callback = new Nette\Callback($function);
return $callback->invokeArgs(Helpers::autowireArguments($callback->toReflection(), $args, $this));
}
开发者ID:vrtak-cz,项目名称:nette-doctrine-sandbox,代码行数:11,代码来源:Container.php
示例15: formatStatement
/**
* Formats PHP code for class instantiating, function calling or property setting in PHP.
* @return string
* @internal
*/
public function formatStatement(Statement $statement, $self = NULL)
{
$entity = $this->normalizeEntity($statement->entity);
$arguments = $statement->arguments;
if (is_string($entity) && Strings::contains($entity, '?')) {
// PHP literal
return $this->formatPhp($entity, $arguments, $self);
} elseif ($service = $this->getServiceName($entity)) {
// factory calling or service retrieving
if ($this->definitions[$service]->shared) {
if ($arguments) {
throw new ServiceCreationException("Unable to call service '{$entity}'.");
}
return $this->formatPhp('$this->getService(?)', array($service));
}
$params = array();
foreach ($this->definitions[$service]->parameters as $k => $v) {
$params[] = preg_replace('#\\w+$#', '\\$$0', is_int($k) ? $v : $k) . (is_int($k) ? '' : ' = ' . PhpHelpers::dump($v));
}
$rm = new Nette\Reflection\GlobalFunction(create_function(implode(', ', $params), ''));
$arguments = Helpers::autowireArguments($rm, $arguments, $this);
return $this->formatPhp('$this->?(?*)', array(Container::getMethodName($service, FALSE), $arguments), $self);
} elseif ($entity === 'not') {
// operator
return $this->formatPhp('!?', array($arguments[0]));
} elseif (is_string($entity)) {
// class name
if ($constructor = Nette\Reflection\ClassType::from($entity)->getConstructor()) {
$this->addDependency($constructor->getFileName());
$arguments = Helpers::autowireArguments($constructor, $arguments, $this);
} elseif ($arguments) {
throw new ServiceCreationException("Unable to pass arguments, class {$entity} has no constructor.");
}
return $this->formatPhp("new {$entity}" . ($arguments ? '(?*)' : ''), array($arguments), $self);
} elseif (!Validators::isList($entity) || count($entity) !== 2) {
throw new Nette\InvalidStateException("Expected class, method or property, " . PhpHelpers::dump($entity) . " given.");
} elseif ($entity[0] === '') {
// globalFunc
return $this->formatPhp("{$entity['1']}(?*)", array($arguments), $self);
} elseif (Strings::contains($entity[1], '$')) {
// property setter
Validators::assert($arguments, 'list:1', "setup arguments for '" . Nette\Callback::create($entity) . "'");
if ($this->getServiceName($entity[0], $self)) {
return $this->formatPhp('?->? = ?', array($entity[0], substr($entity[1], 1), $arguments[0]), $self);
} else {
return $this->formatPhp($entity[0] . '::$? = ?', array(substr($entity[1], 1), $arguments[0]), $self);
}
} elseif ($service = $this->getServiceName($entity[0], $self)) {
// service method
if ($this->definitions[$service]->class) {
$arguments = $this->autowireArguments($this->definitions[$service]->class, $entity[1], $arguments);
}
return $this->formatPhp('?->?(?*)', array($entity[0], $entity[1], $arguments), $self);
} else {
// static method
$arguments = $this->autowireArguments($entity[0], $entity[1], $arguments);
return $this->formatPhp("{$entity['0']}::{$entity['1']}(?*)", array($arguments), $self);
}
}
开发者ID:BroukPytlik,项目名称:agility,代码行数:64,代码来源:ContainerBuilder.php
示例16: exportRules
/**
* @return array
*/
protected static function exportRules($rules)
{
$payload = array();
foreach ($rules as $rule) {
if (!is_string($op = $rule->operation)) {
$op = new Nette\Callback($op);
if (!$op->isStatic()) {
continue;
}
}
if ($rule->type === Rule::VALIDATOR) {
$item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'msg' => $rules->formatMessage($rule, FALSE));
} elseif ($rule->type === Rule::CONDITION) {
$item = array('op' => ($rule->isNegative ? '~' : '') . $op, 'rules' => self::exportRules($rule->subRules), 'control' => $rule->control->getHtmlName());
if ($rule->subRules->getToggles()) {
$item['toggle'] = $rule->subRules->getToggles();
}
}
if (is_array($rule->arg)) {
foreach ($rule->arg as $key => $value) {
$item['arg'][$key] = $value instanceof IControl ? (object) array('control' => $value->getHtmlName()) : $value;
}
} elseif ($rule->arg !== NULL) {
$item['arg'] = $rule->arg instanceof IControl ? (object) array('control' => $rule->arg->getHtmlName()) : $rule->arg;
}
$payload[] = $item;
}
return $payload;
}
开发者ID:vrtak-cz,项目名称:nette-doctrine-sandbox,代码行数:32,代码来源:BaseControl.php
示例17: wrap
/**
* Caches results of function/method calls.
* @param mixed
* @param array dependencies
* @return Closure
*/
public function wrap($function, array $dependencies = NULL)
{
$cache = $this;
return function () use($cache, $function, $dependencies) {
$key = array($function, func_get_args());
$data = $cache->load($key);
if ($data === NULL) {
$data = $cache->save($key, Nette\Callback::create($function)->invokeArgs($key[1]), $dependencies);
}
return $data;
};
}
开发者ID:beejhuff,项目名称:PHP-Security,代码行数:18,代码来源:Cache.php
示例18: invoke
/**
* @return RegistrationControl
*/
public function invoke($userType, $mode, $loginProviderMode, $roles, $emailSender, $emailFrom, $emailSubject, $emailText)
{
return Callback::create($this->factory)->invoke($userType, $mode, $loginProviderMode, $roles, $emailSender, $emailFrom, $emailSubject, $emailText);
}
开发者ID:svobodni,项目名称:web,代码行数:7,代码来源:RegistrationControlFactory.php
示例19: macroUse
/**
* {use class MacroSet}
*/
public function macroUse(MacroNode $node, PhpWriter $writer)
{
Nette\Callback::create($node->tokenizer->fetchWord(), 'install')->invoke($this->getCompiler())->initialize();
}
开发者ID:vrtak-cz,项目名称:nette-doctrine-sandbox,代码行数:7,代码来源:CoreMacros.php
示例20: createComponentNavbarForm
protected function createComponentNavbarForm()
{
$_this = $this;
$form = $this->navbarForms[$this->formName];
$entity = $form->getEntityFactory() ? Callback::create($form->getEntityFactory())->invoke() : $this->repository->createNew();
$form = $form->getFactory()->invoke($entity);
$form->onSuccess[] = $this->navbarFormSuccess;
$form->onError[] = $this->navbarFormError;
if ($this->mode == self::MODE_PLACE) {
$form->addSubmit('_cancel', 'Cancel')->setValidationScope(FALSE)->onClick[] = function () use($_this) {
$_this->redirect('this', array('formName' => NULL, 'mode' => NULL));
};
}
return $form;
}
开发者ID:venne,项目名称:cms-module,代码行数:15,代码来源:AdminGrid.php
注:本文中的Nette\Callback类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论