當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Container::callInjects方法代碼示例

本文整理匯總了PHP中Nette\DI\Container::callInjects方法的典型用法代碼示例。如果您正苦於以下問題:PHP Container::callInjects方法的具體用法?PHP Container::callInjects怎麽用?PHP Container::callInjects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\DI\Container的用法示例。


在下文中一共展示了Container::callInjects方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: createPresenter

 /**
  * Creates new presenter instance.
  *
  * @param  string presenter class name
  * @return Application\IPresenter
  */
 public function createPresenter($class)
 {
     $callInjects = $this->alwaysCallInjects;
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (count($services)) {
         $presenter = $this->container->createService($services[0]);
         $callInjects = FALSE;
     } elseif (count($services = $this->container->findByType($class)) === 1) {
         $presenter = $this->container->createService($services[0]);
     } else {
         $presenter = $this->container->createInstance($class);
         $callInjects = TRUE;
     }
     if (!$presenter instanceof Application\IPresenter) {
         throw new UnexpectedValueException("Unable to create create presenter, returned value is not Nette\\Application\\IPresenter type.");
     }
     if ($callInjects) {
         $this->container->callInjects($presenter);
     }
     if ($presenter instanceof Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
         $presenter->invalidLinkMode = $this->invalidLinkMode;
     }
     return $presenter;
 }
開發者ID:librette,項目名稱:presenter-factory,代碼行數:32,代碼來源:PresenterObjectFactory.php

示例2: create

 /**
  * @return VisualPaginator
  */
 public function create()
 {
     $paginator = new VisualPaginator();
     $this->container->callInjects($paginator);
     $this->paginatorStack[] = $paginator;
     return $paginator;
 }
開發者ID:artfocus,項目名稱:visual-paginator,代碼行數:10,代碼來源:VisualPaginatorFactory.php

示例3: createPresenter

 /**
  * Create new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $presenter = $this->container->createInstance($this->getPresenterClass($name));
     $this->container->callInjects($presenter);
     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;
 }
開發者ID:radeksimko,項目名稱:nette,代碼行數:14,代碼來源:PresenterFactory.php

示例4: createMapper

 /**
  * @param IRepository $repository
  * @internal param $IRepository
  * @return IMapper
  */
 public function createMapper(IRepository $repository)
 {
     $class = $this->getMapperClass($repository);
     /** @var Mappers\Mapper $mapper */
     $mapper = new $class($repository);
     $this->container->callInjects($mapper);
     $mapper->registerEvents($repository->getEvents());
     return $mapper;
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:14,代碼來源:MapperFactory.php

示例5: execute

 public function execute(File $sql)
 {
     $version = (int) basename($sql->name, '.php');
     $class = "App\\Migrations\\Migration{$version}";
     extract($this->getParameters());
     include $sql->getPath();
     /** @var Migration $migration */
     $migration = new $class();
     $this->container->callInjects($migration);
     $migration->run();
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:11,代碼來源:PhpClass.php

示例6: createPresenter

 /**
  * Creates new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $class = $this->getPresenterClass($name);
     if (count($services = $this->container->findByType($class)) === 1) {
         $presenter = $this->container->createService($services[0]);
     } else {
         $presenter = $this->container->createInstance($class);
     }
     $this->container->callInjects($presenter);
     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;
 }
開發者ID:pdostal,項目名稱:nette-blog,代碼行數:19,代碼來源:PresenterFactory.php

示例7: doRunCommand

 protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
 {
     if ($this->serviceLocator) {
         $this->serviceLocator->callInjects($command);
     }
     return parent::doRunCommand($command, $input, $output);
 }
開發者ID:kdyby,項目名稱:console,代碼行數:7,代碼來源:Application.php

示例8: __invoke

 /**
  * @return Nette\Application\IPresenter
  */
 public function __invoke($class)
 {
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new Nette\Application\InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->touchToRefresh) {
             touch($this->touchToRefresh);
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         if ($presenter instanceof Nette\Application\UI\Presenter && $presenter->invalidLinkMode === NULL) {
             $presenter->invalidLinkMode = $this->invalidLinkMode;
         }
         return $presenter;
     }
     return $this->container->createService($services[0]);
 }
開發者ID:Richmond77,項目名稱:learning-nette,代碼行數:21,代碼來源:PresenterFactoryCallback.php

示例9: runTest

 public function runTest($name, array $args = [])
 {
     $this->container->callInjects($this);
     $this->setUp();
     try {
         call_user_func_array([$this, $name], $args);
     } catch (\Exception $e) {
         // method does not exist
     }
     try {
         $this->tearDown();
     } catch (\Exception $tearDownEx) {
         throw isset($e) ? $e : $tearDownEx;
     }
     if (isset($e)) {
         throw $e;
     }
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:18,代碼來源:TestCase.php

示例10: createPresenter

 /**
  * Creates new presenter instance.
  * @param  string  presenter name
  * @return IPresenter
  */
 public function createPresenter($name)
 {
     $class = $this->getPresenterClass($name);
     $services = array_keys($this->container->findByTag('nette.presenter'), $class);
     if (count($services) > 1) {
         throw new InvalidPresenterException("Multiple services of type {$class} found: " . implode(', ', $services) . '.');
     } elseif (!$services) {
         if ($this->autoRebuild) {
             $rc = new \ReflectionClass($this->container);
             @unlink($rc->getFileName());
             // @ file may not exists
         }
         $presenter = $this->container->createInstance($class);
         $this->container->callInjects($presenter);
         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;
     }
     return $this->container->createService($services[0]);
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:26,代碼來源:PresenterFactory.php

示例11: injectDependencies

 public function injectDependencies(IEntity $entity)
 {
     $this->container->callInjects($entity);
     return $entity;
 }
開發者ID:Zarganwar,項目名稱:orm,代碼行數:5,代碼來源:EntityDependencyProvider.php

示例12: __construct

 public function __construct(Nette\DI\Container $sl)
 {
     parent::__construct();
     $sl->callInjects($this);
     $this->run(new Nette\Application\Request('Front:LinkGenerator', 'GET', array('action' => 'default')));
 }
開發者ID:kdyby,項目名稱:selenium,代碼行數:6,代碼來源:LinkGeneratorPresenter.php

示例13: process


//.........這裏部分代碼省略.........
             // just in case
             if (!$request->hasFlag(Nette\Application\Request::SECURED) && $this->isInProductionMode()) {
                 $this->tokenManager->invalidateToken($tokenHash);
                 $this->terminateWithError(self::ERROR_INVALID_REQUEST, "Secured connection required", 400);
             }
             if (!$this->attemptLogger->getRemainingAttempts(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress())) {
                 $this->terminateWithError(OAuth2ResourceProvider::ERROR_MAXIMUM_ATTEMPTS_EXCEEDED, 'Maximum number of authorization attempts exceeded.', 403);
             }
             $token = $this->tokenManager->getToken($tokenHash);
             if (!$token) {
                 $this->attemptLogger->logFail(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress());
                 $this->httpResponse->addHeader('WWW-Authenticate', 'Bearer realm="' . $this->link() . '"');
                 $this->terminateWithError(OAuth2ResourceProvider::ERROR_INVALID_GRANT, 'Given authorization token is not valid.', 401);
             }
             $this->attemptLogger->logSuccess(self::ATTEMPT_IP_TOKEN, $this->httpRequest->getRemoteAddress());
             if (isset($token->parameters->userIdentity)) {
                 $this->user->login(User::AUTHN_METHOD_INVALID, User::AUTHN_SOURCE_ALL, $token->parameters->userIdentity);
             }
             if (isset($token->parameters->client)) {
                 $this->client = $token->parameters->client;
             }
         }
     }
     // Find request handler ------------------------------------------------
     // Gather resource path
     $parameters = $request->getParameters();
     $resourcePath = isset($parameters[self::PARAM_KEY_PATH]) ? trim($parameters[self::PARAM_KEY_PATH]) : NULL;
     if (!$resourcePath) {
         $this->terminateWithError(self::ERROR_INVALID_REQUEST, "No resource path given.", 400);
     }
     // Request router expects leading slash
     if ($resourcePath[0] != '/') {
         $resourcePath = "/{$resourcePath}";
     }
     // Request router: find resource handler
     try {
         /** @var vBuilder\RestApi\Request */
         $this->resourceRequest = $handlerRequest = $this->requestRouter->createRequest($this->httpRequest->getMethod(), $resourcePath);
     } catch (RequestException $e) {
         $this->terminateWithError(self::ERROR_INVALID_REQUEST, $e->getMessage(), $e->getCode() == RequestException::METHOD_NOT_ALLOWED ? 405 : 404);
     }
     // Request authorization -----------------------------------------------
     $handlerMethodAnnotations = $handlerRequest->getMethodReflection()->getAnnotations();
     if (!isset($handlerMethodAnnotations['NoAuthorization']) || !$handlerMethodAnnotations['NoAuthorization'][0]) {
         if (!$this->client) {
             $this->httpResponse->addHeader('WWW-Authenticate', 'Bearer realm="' . $this->link() . '"');
             $this->terminateWithError(self::ERROR_UNAUTHORIZED, 'Requested resource requires authorization. Please add Authorization header with correct security token.', 401);
         }
     }
     // Decode POST data ----------------------------------------------------
     if ($this->httpRequest->isPost()) {
         $cType = $this->httpRequest->getHeader('Content-Type');
         if (strcasecmp($cType, 'application/json') === 0) {
             try {
                 $this->postData = Nette\Utils\Json::decode(file_get_contents('php://input'), Nette\Utils\Json::FORCE_ARRAY);
             } catch (Nette\Utils\JsonException $e) {
                 $this->terminateWithError(self::ERROR_INVALID_REQUEST, "Malformed POST data (JSON expected).", 400);
             }
         } elseif (strcasecmp($cType, 'application/x-www-form-urlencoded') === 0) {
             $this->postData = $this->httpRequest->getPost();
         } elseif ($cType === NULL) {
             $this->terminateWithError(self::ERROR_INVALID_REQUEST, "Missing Content-Type header, which is mandatory for POST requests.", 400);
         } else {
             $this->terminateWithError(self::ERROR_INVALID_REQUEST, "Request content type of POST data is not supported.", 415);
         }
     }
     // Create resource instance and prepare all dependencies ---------------
     $class = $handlerRequest->getResourceClassName();
     $resource = new $class();
     $resource->presenter = $this;
     $this->systemContainer->callInjects($resource);
     // Prepare and order invoke parameters ---------------------------------
     $mReflection = $handlerRequest->getMethodReflection();
     $invokeParams = array();
     $requestParams = $handlerRequest->getParameters();
     $definedParams = $mReflection->getParameters();
     $index = 0;
     foreach ($definedParams as $pReflection) {
         $index++;
         // Parameter not given in URL?
         if (!isset($requestParams[$pReflection->getName()])) {
             // Default value where available
             if ($pReflection->isDefaultValueAvailable()) {
                 $invokeParams[$pReflection->getName()] = $pReflection->getDefaultValue();
                 continue;
             }
             $this->terminateWithError(self::ERROR_INVALID_REQUEST, "Missing #{$index} parameter for resource handler {$class}::" . $mReflection->getName() . '().', 400);
         }
         $invokeParams[$pReflection->getName()] = $requestParams[$pReflection->getName()];
     }
     // Perform startup
     $resource->startup();
     // Invoke handler method on resource instance
     $responsePayload = $mReflection->invokeArgs($resource, $invokeParams);
     // Automatically set HTTP 204 No Content if necessary
     if ($responsePayload === NULL && $this->httpResponse->getCode() == 200) {
         $this->httpResponse->setCode(204);
     }
     return $responsePayload === NULL ? $this->createResponse() : $this->createResponse($responsePayload);
 }
開發者ID:vbuilder,項目名稱:framework,代碼行數:101,代碼來源:Presenter.php


注:本文中的Nette\DI\Container::callInjects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。