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


PHP Callback::toReflection方法代码示例

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


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

示例1: 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

示例2: run

	/**
	 * @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;
		}
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:54,代码来源:MicroPresenter.php

示例3: fireEvents

 public function fireEvents()
 {
     /** @var ObjectForm|UI\Form $this */
     if (!($submittedBy = $this->isSubmitted())) {
         return;
     }
     foreach ($this->onReceiveData ?: array() as $handler) {
         $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
         Nette\Utils\Callback::invoke($handler, $this);
     }
     $this->validate();
     if ($this->object !== NULL) {
         $this->getObjectMapper()->save($this->object, $this);
     }
     if ($submittedBy instanceof Nette\Forms\ISubmitterControl) {
         if ($this->isValid()) {
             $submittedBy->onClick($submittedBy);
         } else {
             $submittedBy->onInvalidClick($submittedBy);
         }
     }
     if ($this->object !== NULL) {
         $validateControls = $submittedBy instanceof Nette\Forms\ISubmitterControl ? $submittedBy->getValidationScope() : NULL;
         if ($validateControls === NULL || count($validateControls) > 0) {
             $this->getViolationsMapper()->validateContainer($this->object, $this, $validateControls);
         }
     }
     if ($this->onSuccess) {
         foreach ($this->onSuccess as $handler) {
             if (!$this->isValid()) {
                 $this->onError($this);
                 break;
             }
             $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
             $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
             Nette\Utils\Callback::invoke($handler, $this, $values);
         }
     } elseif (!$this->isValid()) {
         $this->onError($this);
     }
     $this->onSubmit($this);
 }
开发者ID:mike227,项目名称:n-forms,代码行数:42,代码来源:TObjectForm.php

示例4: resolveEntityClass

 /** @return string|NULL */
 private function resolveEntityClass($entity, $recursive = [])
 {
     $entity = $this->normalizeEntity($entity instanceof Statement ? $entity->getEntity() : $entity);
     if (is_array($entity)) {
         if (($service = $this->getServiceName($entity[0])) || $entity[0] instanceof Statement) {
             $entity[0] = $this->resolveEntityClass($entity[0], $recursive);
             if (!$entity[0]) {
                 return;
             } elseif (isset($this->definitions[$service]) && $this->definitions[$service]->getImplement()) {
                 // @Implement::create
                 return $entity[1] === 'create' ? $this->resolveServiceClass($service, $recursive) : NULL;
             }
         }
         try {
             $reflection = Nette\Utils\Callback::toReflection($entity[0] === '' ? $entity[1] : $entity);
             $refClass = $reflection instanceof \ReflectionMethod ? $reflection->getDeclaringClass() : NULL;
         } catch (\ReflectionException $e) {
         }
         if (isset($e) || $refClass && (!$reflection->isPublic() || $refClass->isTrait() && !$reflection->isStatic())) {
             $name = array_slice(array_keys($recursive), -1);
             throw new ServiceCreationException(sprintf("Factory '%s' used in service '%s' is not callable.", Nette\Utils\Callback::toString($entity), $name[0]));
         }
         return PhpReflection::getReturnType($reflection);
     } elseif ($service = $this->getServiceName($entity)) {
         // alias or factory
         if (Strings::contains($service, '\\')) {
             // @\Class
             return ltrim($service, '\\');
         }
         return $this->definitions[$service]->getImplement() ?: $this->resolveServiceClass($service, $recursive);
     } elseif (is_string($entity)) {
         if (!class_exists($entity) || !(new ReflectionClass($entity))->isInstantiable()) {
             $name = array_slice(array_keys($recursive), -1);
             throw new ServiceCreationException("Class {$entity} used in service '{$name['0']}' not found or is not instantiable.");
         }
         return ltrim($entity, '\\');
     }
 }
开发者ID:ondrejmirtes,项目名称:di,代码行数:39,代码来源:ContainerBuilder.php

示例5: validate

 /**
  * Performs the server side validation.
  * @param  IControl[]
  * @return void
  */
 public function validate(array $controls = NULL)
 {
     foreach ($controls === NULL ? $this->getComponents() : $controls as $control) {
         $control->validate();
     }
     if ($this->onValidate !== NULL) {
         if (!is_array($this->onValidate) && !$this->onValidate instanceof \Traversable) {
             throw new Nette\UnexpectedValueException('Property Form::$onValidate must be array or Traversable, ' . gettype($this->onValidate) . ' given.');
         }
         foreach ($this->onValidate as $handler) {
             $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
             $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
             Nette\Utils\Callback::invoke($handler, $this, $values);
         }
     }
     $this->validated = TRUE;
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:22,代码来源:Container.php

示例6: fireEvents

 /**
  * Fires submit/click events.
  * @return void
  */
 public function fireEvents()
 {
     if (!$this->isSubmitted()) {
         return;
     } elseif (!$this->getErrors()) {
         $this->validate();
     }
     if ($this->submittedBy instanceof ISubmitterControl) {
         if ($this->isValid()) {
             $this->submittedBy->onClick($this->submittedBy);
         } else {
             $this->submittedBy->onInvalidClick($this->submittedBy);
         }
     }
     if (!$this->isValid()) {
         $this->onError($this);
     } elseif ($this->onSuccess !== NULL) {
         if (!is_array($this->onSuccess) && !$this->onSuccess instanceof \Traversable) {
             throw new Nette\UnexpectedValueException('Property Form::$onSuccess must be array or Traversable, ' . gettype($this->onSuccess) . ' given.');
         }
         foreach ($this->onSuccess as $handler) {
             $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
             $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
             Nette\Utils\Callback::invoke($handler, $this, $values);
             if (!$this->isValid()) {
                 $this->onError($this);
                 break;
             }
         }
     }
     $this->onSubmit($this);
 }
开发者ID:Richmond77,项目名称:learning-nette,代码行数:36,代码来源:Form.php

示例7: callMethod

 /**
  * Calls method using autowiring.
  * @return mixed
  */
 public function callMethod($function, array $args = array())
 {
     return call_user_func_array($function, Helpers::autowireArguments(Nette\Utils\Callback::toReflection($function), $args, $this));
 }
开发者ID:Richmond77,项目名称:learning-nette,代码行数:8,代码来源:Container.php

示例8: validate

 /**
  * Performs the server side validation.
  * @param  IControl[]
  * @return void
  */
 public function validate(array $controls = NULL)
 {
     foreach ($controls === NULL ? $this->getComponents() : $controls as $control) {
         $control->validate();
     }
     foreach ($this->onValidate ?: [] as $handler) {
         $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
         $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
         Nette\Utils\Callback::invoke($handler, $this, $values);
     }
     $this->validated = TRUE;
 }
开发者ID:nubium,项目名称:forms,代码行数:17,代码来源:Container.php

示例9: callMethod

 /**
  * Calls method using autowiring.
  * @return mixed
  */
 public function callMethod(callable $function, array $args = [])
 {
     return $function(...Helpers::autowireArguments(Nette\Utils\Callback::toReflection($function), $args, $this));
 }
开发者ID:Northys,项目名称:di,代码行数:8,代码来源:Container.php

示例10: handleMarkers

 /**
  * Send markers to template as JSON
  * @internal
  */
 public function handleMarkers()
 {
     foreach ($this->onMarkers as $handler) {
         $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
         Nette\Utils\Callback::invoke($handler, $this, $params);
     }
     $this->getPresenter()->sendResponse(new JsonResponse((array) $this->markers));
 }
开发者ID:jasin755,项目名称:maps,代码行数:12,代码来源:MapAPI.php

示例11: 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(Callback::toReflection($function), func_get_args());
         $data = $cache->load($key);
         if ($data === NULL) {
             $data = $cache->save($key, Callback::invokeArgs($function, $key[1]), $dependencies);
         }
         return $data;
     };
 }
开发者ID:cujan,项目名称:atlashornin,代码行数:18,代码来源:Cache.php

示例12: resolveClass

 private function resolveClass($name, $recursive = array())
 {
     if (isset($recursive[$name])) {
         throw new ServiceCreationException('Circular reference detected for services: ' . implode(', ', array_keys($recursive)) . '.');
     }
     $recursive[$name] = TRUE;
     $def = $this->definitions[$name];
     $factory = $def->factory->entity;
     if ($def->class) {
         return $def->class;
     } elseif (is_array($factory)) {
         // method calling
         if ($service = $this->getServiceName($factory[0])) {
             if (Strings::contains($service, '\\')) {
                 // @\Class
                 $factory[0] = $service;
             } else {
                 $factory[0] = $this->resolveClass($service, $recursive);
                 if (!$factory[0]) {
                     return;
                 }
                 if ($this->definitions[$service]->implement && $factory[1] === 'create') {
                     return $def->class = $factory[0];
                 }
             }
         }
         if (!is_callable($factory)) {
             throw new ServiceCreationException("Factory '" . Nette\Utils\Callback::toString($factory) . "' is not callable.");
         }
         try {
             $reflection = Nette\Utils\Callback::toReflection($factory);
         } catch (\ReflectionException $e) {
             throw new ServiceCreationException("Missing factory '" . Nette\Utils\Callback::toString($factory) . "'.");
         }
         $def->class = preg_replace('#[|\\s].*#', '', $reflection->getAnnotation('return'));
         if ($def->class && $reflection instanceof \ReflectionMethod) {
             $def->class = Reflection\AnnotationsParser::expandClassName($def->class, $reflection->getDeclaringClass());
         }
     } elseif ($service = $this->getServiceName($factory)) {
         // alias or factory
         if (!$def->implement) {
             $def->autowired = FALSE;
         }
         if (Strings::contains($service, '\\')) {
             // @\Class
             return $def->class = $service;
         }
         if ($this->definitions[$service]->implement) {
             $def->autowired = FALSE;
         }
         return $def->class = $this->definitions[$service]->implement ?: $this->resolveClass($service, $recursive);
     } else {
         return $def->class = $factory;
         // class name
     }
 }
开发者ID:rostenkowski,项目名称:nette,代码行数:56,代码来源:ContainerBuilder.php

示例13: fireEvents

 /**
  * Fires submit/click events.
  * @return void
  */
 public function fireEvents()
 {
     if (!$this->isSubmitted()) {
         return;
     } elseif (!$this->getErrors()) {
         $this->validate();
     }
     if ($this->submittedBy instanceof ISubmitterControl) {
         if ($this->isValid()) {
             $this->submittedBy->onClick($this->submittedBy);
         } else {
             $this->submittedBy->onInvalidClick($this->submittedBy);
         }
     }
     if (!$this->isValid()) {
         $this->onError($this);
     } elseif ($this->onSuccess) {
         foreach ($this->onSuccess as $handler) {
             $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
             $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
             Nette\Utils\Callback::invoke($handler, $this, $values);
             if (!$this->isValid()) {
                 $this->onError($this);
                 break;
             }
         }
     }
     $this->onSubmit($this);
 }
开发者ID:bombush,项目名称:NatsuCon,代码行数:33,代码来源:Form.php

示例14: renderListeners

 private function renderListeners($ids)
 {
     static $addIcon;
     if (empty($addIcon)) {
         $addIcon = '<img width="18" height="18" src="data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/add.png')) . '" title="Listener" />';
     }
     $registeredClasses = $this->getClassMap();
     $h = 'htmlspecialchars';
     $shortFilename = function (Nette\Reflection\GlobalFunction $refl) {
         $title = '.../' . basename($refl->getFileName()) . ':' . $refl->getStartLine();
         if ($editor = Tracy\Helpers::editorUri($refl->getFileName(), $refl->getStartLine())) {
             return sprintf(' defined at <a href="%s">%s</a>', htmlspecialchars($editor), $title);
         }
         return ' defined at ' . $title;
     };
     $s = '';
     foreach ($ids as $id) {
         if (is_callable($id)) {
             $s .= '<tr><td width=18>' . $addIcon . '</td><td><pre class="nette-dump"><span class="nette-dump-object">' . Callback::toString($id) . ($id instanceof \Closure ? $shortFilename(Callback::toReflection($id)) : '') . '</span></span></th></tr>';
             continue;
         }
         if (!$this->sl->isCreated($id) && ($class = array_search($id, $registeredClasses, TRUE))) {
             $s .= '<tr><td width=18>' . $addIcon . '</td><td><pre class="nette-dump"><span class="nette-dump-object">' . $h(Nette\Reflection\ClassType::from($class)->getName()) . '</span></span></th></tr>';
         } else {
             try {
                 $s .= '<tr><td width=18>' . $addIcon . '</td><td>' . self::dumpToHtml($this->sl->getService($id)) . '</th></tr>';
             } catch (\Exception $e) {
                 $s .= "<tr><td colspan=2>Service {$id} cannot be loaded because of exception<br><br>\n" . (string) $e . '</td></th>';
             }
         }
     }
     return $s;
 }
开发者ID:peterkrejci,项目名称:music-collection,代码行数:33,代码来源:Panel.php

示例15: fireEvents

 public function fireEvents()
 {
     /** @var EntityForm|UI\Form $this */
     if (!($submittedBy = $this->isSubmitted())) {
         return;
     }
     $this->validate();
     if ($this->isValid()) {
         $this->getEntityMapper()->save($this->entity, $this);
     }
     $this->getViolationsMapper()->validateContainer($this, $this->entity);
     if ($submittedBy instanceof Nette\Forms\ISubmitterControl) {
         if ($this->isValid()) {
             $submittedBy->onClick($submittedBy);
         } else {
             $submittedBy->onInvalidClick($submittedBy);
         }
     }
     if ($this->onSuccess) {
         foreach ($this->onSuccess as $handler) {
             if (!$this->isValid()) {
                 $this->onError($this);
                 break;
             }
             $params = Nette\Utils\Callback::toReflection($handler)->getParameters();
             $values = isset($params[1]) ? $this->getValues($params[1]->isArray()) : NULL;
             Nette\Utils\Callback::invoke($handler, $this, $values);
         }
     } elseif (!$this->isValid()) {
         $this->onError($this);
     }
     $this->onSubmit($this);
 }
开发者ID:kuba1999,项目名称:DoctrineForms,代码行数:33,代码来源:EntityForm.php


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