/** * 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; }
/** * 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; }
/** * @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(); }
/** * 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); } }