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


PHP Container::getService方法代碼示例

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


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

示例1: getWallet

 /**
  * @param string $name
  * @return Wallet
  */
 public function getWallet($name)
 {
     if (!isset($this->serviceMap[$name])) {
         throw new \Nette\InvalidArgumentException("Unknown wallet {$name}.");
     }
     return $this->serviceLocator->getService($this->serviceMap[$name]);
 }
開發者ID:brosland,項目名稱:blockchain,代碼行數:11,代碼來源:Blockchain.php

示例2: getModel

 /**
  * getter for specified model
  *
  * @param string $name name of model
  * @return BaseModel
  * @throws \InvalidArgumentException
  */
 public function getModel($name)
 {
     if ($this->container->hasService($name)) {
         return $this->container->getService($name);
     }
     throw new \InvalidArgumentException("Model '{$name}' not found.");
 }
開發者ID:b4nan,項目名稱:doctrine,代碼行數:14,代碼來源:BaseModelLoader.php

示例3: getWallet

 /**
  * @param string $name
  * @return \Blocktrail\SDK\Wallet
  * @throws \Nette\InvalidArgumentException
  */
 public function getWallet($name = self::DEFAULT_NAME)
 {
     if (!isset($this->walletsServiceMap[$name])) {
         throw new \Nette\InvalidArgumentException("Unknown wallet '{$name}'.");
     }
     return $this->serviceLocator->getService($this->walletsServiceMap[$name]);
 }
開發者ID:brosland,項目名稱:blocktrail,代碼行數:12,代碼來源:Blocktrail.php

示例4: runMigrations

 /**
  * Vytvoří DB a naplní testovacími daty.
  */
 public function runMigrations()
 {
     if (!$this->context->parameters['migrations']['enabled']) {
         return;
     }
     $connection = $this->context->getService('dibiConnection');
     $dbNamePrefix = $this->context->parameters['testDbPrefix'] . date('Ymd_His') . '_' . rand(1, 1000) . '_';
     $i = 1;
     do {
         $dbName = $dbNamePrefix . $i;
         $i++;
     } while ($connection->query('SHOW DATABASES WHERE %n', 'Database', ' = %s', $dbName)->count());
     $connection->query('CREATE DATABASE %n COLLATE=utf8_czech_ci', $dbName);
     $connection->query('USE %n', $dbName);
     $migrationsPath = $this->context->parameters['wwwDir'] . '/' . $this->context->parameters['migrations']['path'];
     $finder = new Migration\Finders\MultipleDirectories();
     $finder->addDirectory($migrationsPath . '/struct');
     $finder->addDirectory($migrationsPath . '/data');
     $migrations = $this->createRunner($connection);
     ob_start();
     $migrations->run($finder, FALSE, TRUE);
     $result = ob_get_clean();
     if (substr(strip_tags($result), -2) !== 'OK') {
         throw new \Exception('Migrace neproběhly v pořádku: ' . $result);
     }
     $this->context->parameters['testDbName'] = $dbName;
 }
開發者ID:clevis,項目名稱:migration,代碼行數:30,代碼來源:MigrationsLoader.php

示例5: getLoginProviderByName

 /**
  * @param string $name
  * @return \Venne\Security\ILoginProvider
  */
 public function getLoginProviderByName($name)
 {
     if (!isset($this->loginProviders[$name])) {
         throw new InvalidArgumentException(sprintf('Social login name \'%s\' has not been registered.', $name));
     }
     return $this->context->getService($this->loginProviders[$name]);
 }
開發者ID:venne,項目名稱:venne,代碼行數:11,代碼來源:SecurityManager.php

示例6: getLoginProviderByName

 /**
  * @param $name
  * @return ILoginProvider
  * @throws InvalidArgumentException
  */
 public function getLoginProviderByName($name)
 {
     if (!isset($this->loginProviders[$name])) {
         throw new InvalidArgumentException("Social login name '{$name}' has not been registered.");
     }
     return $this->content->getService($this->loginProviders[$name]);
 }
開發者ID:svobodni,項目名稱:web,代碼行數:12,代碼來源:SecurityManager.php

示例7: __construct

 public function __construct(Context $context, Container $container, EntityManager $entityManager)
 {
     $this->context = $context;
     $this->container = $container;
     $this->em = $entityManager;
     $this->cache = $this->container->getService('cacheStorage');
 }
開發者ID:rutrader,項目名稱:nette-blog,代碼行數:7,代碼來源:BasePresenter.php

示例8: create

 /**
  * @return CDNLoader
  */
 public function create()
 {
     $compiler = $this->container->getService('cdnloader.compiler');
     $httpRequest = $this->container->getService('httpRequest');
     $loader = new CDNLoader($compiler, $httpRequest);
     return $loader;
 }
開發者ID:Lawondyss,項目名稱:CDNLoader,代碼行數:10,代碼來源:CDNLoaderFactory.php

示例9: getRpcServer

 /**
  * @param string $name
  * @return RpcServer
  */
 public function getRpcServer($name)
 {
     if (!isset($this->rpcServers[$name])) {
         throw new InvalidArgumentException("Unknown RPC server {$name}");
     }
     return $this->serviceLocator->getService($this->rpcServers[$name]);
 }
開發者ID:petrnemec,項目名稱:RabbitMq,代碼行數:11,代碼來源:Registry.php

示例10: run

 /**
  * @return Nette\Application\IResponse
  */
 public function run(Application\Request $request)
 {
     $this->request = $request;
     $httpRequest = $this->context->getByType('Nette\\Http\\IRequest');
     if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) {
         $refUrl = clone $httpRequest->getUrl();
         $url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath()));
         if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) {
             return new Responses\RedirectResponse($url, Http\IResponse::S301_MOVED_PERMANENTLY);
         }
     }
     $params = $request->getParameters();
     if (!isset($params['callback'])) {
         throw new Application\BadRequestException("Parameter callback is missing.");
     }
     $params['presenter'] = $this;
     $callback = new Nette\Callback($params['callback']);
     $response = $callback->invokeArgs(Application\UI\PresenterComponentReflection::combineArgs($callback->toReflection(), $params));
     if (is_string($response)) {
         $response = array($response, array());
     }
     if (is_array($response)) {
         if ($response[0] instanceof \SplFileInfo) {
             $response = $this->createTemplate('Nette\\Templating\\FileTemplate')->setParameters($response[1])->setFile($response[0]);
         } else {
             $response = $this->createTemplate('Nette\\Templating\\Template')->setParameters($response[1])->setSource($response[0]);
         }
     }
     if ($response instanceof Nette\Templating\ITemplate) {
         return new Responses\TextResponse($response);
     } else {
         return $response;
     }
 }
開發者ID:svobodni,項目名稱:web,代碼行數:37,代碼來源:MicroPresenter.php

示例11: __construct

 public function __construct(\Nette\DI\Container $container)
 {
     $this->container = $container;
     $this->connection = $container->getService('leanMapper.connection');
     $this->entityFactory = $container->getService('entityFactory');
     $this->mapper = $container->getService('standardMapper');
     $this->transaction = $container->getService('transaction');
 }
開發者ID:blitzik,項目名稱:vycetky,代碼行數:8,代碼來源:BaseFacadeTest.php

示例12: create

 /**
  * @return MapperMatrix
  */
 public function create()
 {
     $matrix = new MapperMatrix();
     foreach ($this->container->findByTag('echo511.leanmapper.mapper') as $serviceName => $tagAttributes) {
         $matrix->addMapper($this->container->getService($serviceName));
     }
     return $matrix;
 }
開發者ID:echo511,項目名稱:leanmapper,代碼行數:11,代碼來源:MapperMatrixFactory.php

示例13: initializeListener

 /**
  * @param string $eventName
  */
 private function initializeListener($eventName)
 {
     foreach ($this->listenerIds[$eventName] as $serviceName) {
         $subscriber = $this->container->getService($serviceName);
         /** @var Doctrine\Common\EventSubscriber $subscriber */
         $this->addEventSubscriber($subscriber);
     }
     unset($this->listenerIds[$eventName]);
 }
開發者ID:BianoCZ,項目名稱:Events,代碼行數:12,代碼來源:LazyEventManager.php

示例14: create

 public function create() : Registry
 {
     $tagToService = function (array $tags) {
         return array_map(function (string $serviceName) {
             return $this->container->getService($serviceName);
         }, array_keys($tags));
     };
     return new Registry($tagToService($this->container->findByTag(self::RULE_TAG)));
 }
開發者ID:phpstan,項目名稱:phpstan,代碼行數:9,代碼來源:RegistryFactory.php

示例15: getInstance

 /**
  * {@inheritDoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $name = $constraint->validatedBy();
     if (!isset($this->validators[$name])) {
         $this->validators[$name] = new $name();
     } elseif (is_string($this->validators[$name])) {
         $this->validators[$name] = $this->serviceLocator->getService($this->validators[$name]);
     }
     return $this->validators[$name];
 }
開發者ID:kdyby,項目名稱:validator,代碼行數:13,代碼來源:ConstraintValidatorFactory.php


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