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


PHP Container::findByType方法代码示例

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


在下文中一共展示了Container::findByType方法的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: __construct

 public function __construct(Container $container)
 {
     $this->connections = array_keys($container->findByTag(OrmExtension::TAG_CONNECTION));
     $this->defaultConnection = $container->findByType('Doctrine\\DBAL\\Connection');
     $this->managers = array_keys($container->findByTag(OrmExtension::TAG_ENTITY_MANAGER));
     $this->defaultManager = $container->findByType('Doctrine\\ORM\\EntityManager');
     $this->container = $container;
 }
开发者ID:chiriacbogdan,项目名称:Doctrine,代码行数:8,代码来源:ManagerRegistry.php

示例3: findByTypeForFactory

 /**
  * @param string $type
  * @return string|bool
  */
 private function findByTypeForFactory($type)
 {
     if (method_exists($this->autowireComponentFactoriesLocator, 'findByType')) {
         $found = $this->autowireComponentFactoriesLocator->findByType($type);
         return reset($found);
     }
     $type = ltrim(strtolower($type), '\\');
     return !empty($this->autowireComponentFactoriesLocator->classes[$type]) ? $this->autowireComponentFactoriesLocator->classes[$type] : FALSE;
 }
开发者ID:kdyby,项目名称:autowired,代码行数:13,代码来源:AutowireComponentFactories.php

示例4: actionView

 public function actionView(int $id = NULL)
 {
     $repositories = array_combine(array_map('crc32', array_map('get_class', $repositories = array_map([$this->container, 'getService'], $this->container->findByType(Nextras\Orm\Repository\IRepository::class)))), $repositories);
     if ($id === NULL) {
         $this->generateIndex(array_filter($repositories, [$this, 'getLinkProperties']));
     } elseif (isset($repositories[$id])) {
         $this->generateUrlSet($this->repository = $repositories[$id]);
     } else {
         $this->error();
     }
 }
开发者ID:ytnuk,项目名称:sitemap,代码行数:11,代码来源:Presenter.php

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

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

示例7: registerAddPaymentButtonsUsingDependencyContainer

 /**
  * Registers 'addPaymentButtons' & 'addPaymentButton' methods to form using DI container
  *
  * @param Container $container
  */
 public static function registerAddPaymentButtonsUsingDependencyContainer(Container $container)
 {
     $binder = $container->getByType(Binder::class);
     $services = $container->findByType(AbstractPaymentService::class);
     foreach ($services as $service) {
         self::registerAddPaymentButtons($binder, $container->getService($service));
     }
 }
开发者ID:markette,项目名称:gopay,代码行数:13,代码来源:Helpers.php

示例8: findServicesOfType

 /**
  * @param string $type
  * @param Container $container
  * @return object[]
  */
 public static function findServicesOfType($type, Container $container)
 {
     $services = array();
     foreach ($container->findByType($type) as $name) {
         $services[] = $container->getService($name);
     }
     return $services;
 }
开发者ID:darkknightik,项目名称:nette-injects-extension,代码行数:13,代码来源:Helpers.php

示例9: __construct

 public function __construct(Container $container)
 {
     $this->container = $container;
     $listeners = $this->container->findByType('\\Phoenix\\Events\\IEventListener');
     foreach ($listeners as $class) {
         $reflection = ClassType::from($container->getService($class));
         foreach ($reflection->getMethods() as $method) {
             if ($method->hasAnnotation(self::ANNOTATION_EVENT_LISTENER)) {
                 $event = (string) $method->getAnnotation(self::ANNOTATION_EVENT_LISTENER);
                 if (!isset($this->eventListeners[$event])) {
                     $this->eventListeners[$event] = [];
                 }
                 $this->eventListeners[$event][] = new EventListenerWrapper($container->getService($class), $method);
             }
         }
     }
 }
开发者ID:phoenixcms,项目名称:core,代码行数:17,代码来源:EventManager.php

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

示例11: createConfigFromNetteDatabase

 public static function createConfigFromNetteDatabase(Container $container, $defaults = [])
 {
     $config = $defaults;
     $config['environments']['default_database'] = 'default';
     foreach ($container->findByType(Connection::class) as $connectionServiceName) {
         $parts = explode(".", $connectionServiceName);
         $environment = $parts[1];
         /** @var Connection $connection */
         $connection = $container->getService($connectionServiceName);
         $dbname = self::getDsnValue('dbname', $connection->getDsn());
         $config['environments'][$environment] = ['name' => $dbname, 'connection' => $connection->getPdo()];
     }
     return new Config($config);
 }
开发者ID:echo511,项目名称:nette-phinx-integration,代码行数:14,代码来源:ConfigFactory.php

示例12: __construct

 public function __construct(Container $container)
 {
     foreach ($container->findByType(IManager::class) as $name) {
         $this->register($container->getService($name));
     }
 }
开发者ID:ondrs,项目名称:upload-manager,代码行数:6,代码来源:ManagerContainer.php

示例13: findByType

 /**
  * @param string $class
  * @return string[]
  */
 public function findByType($class)
 {
     return $this->container->findByType($class);
 }
开发者ID:phalette,项目名称:pidic,代码行数:8,代码来源:PiDi.php


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