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


PHP DI\Container類代碼示例

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


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

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

示例2: __construct

 public function __construct($containerFactory = NULL, Container $container = NULL)
 {
     parent::__construct($containerFactory);
     /** @var IStorage $storage */
     $storage = $container->getService('cacheStorage');
     $this->cache = new Cache($storage);
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:7,代碼來源:RepositoryContainer.php

示例3: __construct

 public function __construct(Container $container)
 {
     $p = $container->getParameters();
     foreach (['app' => 'appDir', 'backup' => 'backupDir', 'bin' => 'binDir', 'libs' => 'libsDir', 'log' => 'logDir', 'migrations' => 'migrationsDir', 'temp' => 'tempDir', 'tests' => 'testsDir', 'www' => 'wwwDir'] as $prop => $key) {
         $this->{$prop} = $p[$key];
     }
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:7,代碼來源:Paths.php

示例4: __construct

 public function __construct(Container $context)
 {
     parent::__construct();
     $secured = NULL;
     if ($context->getParameters()['tls']) {
         Route::$defaultFlags |= Route::SECURED;
         $secured = Route::SECURED;
     }
     $this[] = new StaticRouter(['Homepage:default' => 'index.php'], StaticRouter::ONE_WAY | $secured);
     $this[] = new StaticRouter(['Homepage:default' => '', 'Homepage:marathon' => 'maraton', 'Homepage:preklad' => 'preklad', 'Profile:default' => 'profil', 'Auth:in' => 'prihlaseni', 'Auth:out' => 'odhlaseni', 'Auth:registration' => 'registrace', 'Auth:resetPassword' => 'heslo', 'Text:about' => 'o-skole', 'Text:team' => 'o-skole/tym', 'Subjects:default' => 'predmety', 'File:opensearch' => 'opensearch.xml', 'File:robots' => 'robots.txt', 'Sitemap:default' => 'sitemap.xml', 'Text:tos' => 'podminky', 'Text:privacy' => 'soukromi'], $secured);
     $this[] = new Route('vyhledavani/?hledat=<query>', 'Search:results');
     $this[] = new Route('vyhledavani/cviceni', 'Search:blueprints');
     $this[] = new Route('schema/[<action \\D+>/]<schemaId \\d+>[-<slug>]', 'Schema:default');
     $this[] = new Route('blok/[<action \\D+>/][<schemaId \\d+>/]<blockId \\d+>[-<slug>]', 'Block:default');
     $this[] = new Route('video/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<videoId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Video:default');
     $this[] = new Route('cviceni/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blueprintId \\d+>[-<slug>]', 'Blueprint:default');
     $this[] = new Route('tabule/[<action \\D+>/][[<schemaId \\d+>/]<blockId \\d+>/]<blackboardId \\d+>[-<slug>]?zacatek=<startAtTime \\d+>', 'Blackboard:default');
     // old links
     $this[] = new Route('video/<youtubeId>', 'Video:youtube');
     $this[] = new Redirect('dobrovolnici', 'https://wiki.khanovaskola.cz/doku.php?id=dobrovolnici');
     $this[] = new Redirect('dobrovolnici/preklad', 'https://wiki.khanovaskola.cz/doku.php?id=jaknato');
     $this[] = new Redirect('dobrovolnici/pravidla-prekladu', 'https://wiki.khanovaskola.cz/doku.php?id=pravidla');
     $this[] = new Redirect('o-skole/projekty', 'https://wiki.khanovaskola.cz/doku.php?id=start');
     $this[] = new Redirect('kontakt', 'https://wiki.khanovaskola.cz/doku.php?id=tym');
     $this[] = $context->createInstance(Routers\OldVideo::class);
     $this[] = $context->createInstance(Routers\OldCategory::class);
     $this[] = $context->createInstance(Routers\OldBlog::class);
     $this[] = new Route('<presenter>/<action \\D+>[/<id>]', 'Homepage:default');
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:29,代碼來源:Router.php

示例5: create

 public static function create(DI\Container $container)
 {
     $robotLoader = $container->getService('robotLoader');
     //$cacheStorage = $container->getService('cacheStorage');
     $shortcutsManager = new \ShortcutsManager($robotLoader);
     return $shortcutsManager;
 }
開發者ID:bazo,項目名稱:Tatami,代碼行數:7,代碼來源:ShortcutsManagerFactory.php

示例6: getUser

 /**
  * @return \Nette\Security\User
  */
 private function getUser()
 {
     if (!$this->user) {
         $this->user = $this->container->getByType(User::class);
     }
     return $this->user;
 }
開發者ID:venne,項目名稱:files,代碼行數:10,代碼來源:FileListener.php

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

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

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

示例10: doRequest

 /**
  * @param Request $request
  * @return Response
  */
 public function doRequest($request)
 {
     $_COOKIE = $request->getCookies();
     $_SERVER = $request->getServer();
     $_FILES = $request->getFiles();
     $_SERVER['REQUEST_METHOD'] = $method = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = $uri = str_replace('http://localhost', '', $request->getUri());
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     if ($method === 'HEAD' || $method === 'GET') {
         $_GET = $request->getParameters();
         $_POST = [];
     } else {
         $_POST = $request->getParameters();
         $_GET = [];
     }
     $httpRequest = $this->container->getByType(IRequest::class);
     $httpResponse = $this->container->getByType(IResponse::class);
     if (!$httpRequest instanceof HttpRequest || !$httpResponse instanceof HttpResponse) {
         throw new Exception('Arachne\\Codeception\\DI\\CodeceptionExtension is not used or conflicts with another extension.');
     }
     $httpRequest->reset();
     $httpResponse->reset();
     try {
         ob_start();
         $this->container->getByType(Application::class)->run();
         $content = ob_get_clean();
     } catch (Exception $e) {
         ob_end_clean();
         throw $e;
     }
     $code = $httpResponse->getCode();
     $headers = $httpResponse->getHeaders();
     return new Response($content, $code, $headers);
 }
開發者ID:Northys,項目名稱:Codeception,代碼行數:38,代碼來源:Nette.php

示例11: createNew

 public function createNew($arguments = array())
 {
     /** @var BaseFileEntity $entity */
     $entity = parent::createNew($arguments);
     $entity->setUser($this->container->getByType('Nette\\Security\\User'));
     return $entity;
 }
開發者ID:svobodni,項目名稱:web,代碼行數:7,代碼來源:AbstractFileRepository.php

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

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

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

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


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