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


PHP Container::createService方法代碼示例

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


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

 public function createComponent($name)
 {
     if (isset($this->registry[$name])) {
         $component = $this->container->createService($this->registry[$name]);
         $this->onCreateComponent($component);
         return $component;
     }
 }
開發者ID:rixxi,項目名稱:component-registry,代碼行數:8,代碼來源:ComponentRegistry.php

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

示例4: createRepository

 /**
  * Create a new repository instance for an entity class.
  *
  * @param \Doctrine\ORM\EntityManagerInterface $entityManager The EntityManager instance.
  * @param Doctrine\ORM\Mapping\ClassMetadata $metadata
  * @return Doctrine\Common\Persistence\ObjectRepository
  */
 private function createRepository(EntityManagerInterface $entityManager, Doctrine\ORM\Mapping\ClassMetadata $metadata)
 {
     $defaultRepository = $entityManager->getConfiguration()->getDefaultRepositoryClassName();
     $repositoryClassName = $metadata->customRepositoryClassName ?: $defaultRepository;
     if ($repositoryClassName === $defaultRepository) {
         return new $repositoryClassName($entityManager, $metadata);
     } elseif (!($services = $this->serviceLocator->findByType($repositoryClassName))) {
         // todo: solve me in future, maybe just throw an exception?
         return new $repositoryClassName($entityManager, $metadata);
     } elseif (count($services) > 1) {
         // todo: solve me in future, maybe just throw an exception?
         return new $repositoryClassName($entityManager, $metadata);
     } else {
         return $this->serviceLocator->createService($services[0], array('entityManager' => $entityManager, 'metadata' => $metadata));
     }
 }
開發者ID:peterkrejci,項目名稱:music-collection,代碼行數:23,代碼來源:RepositoryFactory.php

示例5: __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

示例6: createRow

 /**
  * @param ActiveRow $activeRow
  * @param $tableName
  * @throws InvalidStateException
  * @return HyperRow
  */
 public function createRow(ActiveRow $activeRow, $tableName)
 {
     $className = Helpers::substituteClassWildcard($this->rowMapping, $tableName);
     $baseClass = HyperRow::class;
     if (!class_exists($className) || !is_subclass_of($className, $baseClass)) {
         throw new InvalidStateException("HyperRow class {$className} does not exist or does not extend {$baseClass}.");
     }
     $names = $this->container->findByType($className);
     if (count($names) > 1) {
         throw new InvalidStateException("Multiple services of type {$className} found: " . implode(', ', $names) . '.');
     } elseif (count($names) == 0) {
         $inst = $this->container->createInstance($className);
     } else {
         $name = array_shift($names);
         $inst = $this->container->createService($name);
     }
     /** @var HyperRow $inst */
     $inst->setFactory($this);
     $inst->setActiveRow($activeRow);
     return $inst;
 }
開發者ID:filsedla,項目名稱:hyperrow,代碼行數:27,代碼來源:Factory.php

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


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