本文整理汇总了PHP中Nette\DI\Container::callMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::callMethod方法的具体用法?PHP Container::callMethod怎么用?PHP Container::callMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\DI\Container
的用法示例。
在下文中一共展示了Container::callMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPresenter
/**
* Create new presenter instance.
* @param string presenter name
* @return IPresenter
*/
public function createPresenter($name)
{
$presenter = $this->container->createInstance($this->getPresenterClass($name));
foreach (array_reverse(get_class_methods($presenter)) as $method) {
if (substr($method, 0, 6) === 'inject') {
$this->container->callMethod(array($presenter, $method));
}
}
if ($presenter instanceof UI\Presenter && $presenter->invalidLinkMode === NULL) {
$presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? UI\Presenter::INVALID_LINK_WARNING : UI\Presenter::INVALID_LINK_SILENT;
}
return $presenter;
}
示例2: createPresenter
/**
* Create new presenter instance.
* @param string presenter name
* @return IPresenter
*/
public function createPresenter($name)
{
$presenterName = $this->formatServiceNameFromPresenter($name);
if (isset($this->presentersByName[$presenterName])) {
$presenter = $this->container->getService($presenterName);
$presenter = $presenter instanceof Callback ? $presenter->invoke() : $presenter;
} else {
if (isset($this->presentersByName[$presenterName . 'Factory'])) {
$presenter = $this->container->getService($presenterName . 'Factory')->invoke();
} else {
return parent::createPresenter($name);
}
}
foreach (array_reverse(get_class_methods($presenter)) as $method) {
if (substr($method, 0, 6) === 'inject') {
$this->container->callMethod(array($presenter, $method));
}
}
return $presenter;
}
示例3: onMessage
/**
* @param ConnectionInterface $from
* @param string $msg
* @throws BadRequestException
* @throws InvalidArgumentException
*/
public function onMessage(ConnectionInterface $from, $msg)
{
$request = $this->router->match($msg);
if (is_null($request)) {
throw new BadRequestException('Invalid message - router cant create request.');
}
if (!$request instanceof Request) {
throw new InvalidArgumentException('Route must return Ale\\Ratchet\\Request.');
}
$className = $request->getControl();
if (!$className || !class_exists($className)) {
throw new BadRequestException('Control class "' . $className . '" not found.');
}
if (!is_subclass_of($className, 'Ale\\Ratchet\\UI\\Control')) {
throw new BadRequestException($className . ' must be subclass of Ale\\Ratchet\\UI\\Control.');
}
$handleName = $request->getHandle();
if (!$handleName) {
throw new BadRequestException('Handle cannot be empty.');
}
if (!method_exists($className, $handleName)) {
throw new BadRequestException('Method "' . $handleName . '" not found in class "' . $className . '".');
}
$control = new $className($this->connectionStorage);
/** @var \Ale\Ratchet\UI\Control $control */
foreach (array_reverse(get_class_methods($control)) as $method) {
if (substr($method, 0, 6) === 'inject') {
$this->container->callMethod(array($control, $method));
}
}
$control->startup();
if (!$this->tryCall($control, $handleName, $request->getParams())) {
throw new InvalidArgumentException('Handle method "' . $handleName . '" of "' . $className . '" must be callable.');
}
$control->shutdown();
}
示例4: callInjects
/**
* Calls all methods starting with with "inject" using autowiring.
* @return void
*/
public static function callInjects(DI\Container $container, $service)
{
if (!is_object($service)) {
throw new Nette\InvalidArgumentException(sprintf('Service must be object, %s given.', gettype($service)));
}
foreach (array_reverse(self::getInjectMethods($service)) as $method) {
$container->callMethod([$service, $method]);
}
foreach (self::getInjectProperties(get_class($service)) as $property => $type) {
self::checkType($service, $property, $type, $container);
$service->{$property} = $container->getByType($type);
}
}