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


PHP Container::getByType方法代码示例

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


在下文中一共展示了Container::getByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

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

示例2: createEntity

 /** @inheritdoc */
 public function createEntity($entityClass, $arg = null)
 {
     if ($factory = $this->container->getByType($this->resolveEntityFactory($entityClass), false)) {
         return $factory->create($arg);
     }
     return new $entityClass($arg);
 }
开发者ID:echo511,项目名称:leanmapper,代码行数:8,代码来源:EntityFactory.php

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

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

示例5: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $login = $input->getArgument('login');
     $password = $input->getArgument('password');
     $this->container->getByType('App\\Model\\UserManager')->add($login, $password);
     $output->writeln("User {$login} was added.");
 }
开发者ID:bazo,项目名称:satis-gui,代码行数:7,代码来源:CreateUser.php

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

示例7: configure

 public function configure(Template $template)
 {
     // translator
     if (($translator = $this->container->getByType('Nette\\Localization\\ITranslator', FALSE)) !== NULL) {
         $template->setTranslator($translator);
     }
     $template->registerHelperLoader(array($this->container->venne->helpers, "loader"));
 }
开发者ID:svobodni,项目名称:web,代码行数:8,代码来源:TemplateConfigurator.php

示例8: __construct

 /**
  * BasePresenterTester constructor.
  * @param string $presenterName  - etc. 'Front:GoodsChange:Goods'
  */
 public function __construct($presenterName)
 {
     $this->presenterName = $presenterName;
     $this->container = (require __DIR__ . '/../../../../app/bootstrap.php');
     $this->linkGenerator = $this->container->getByType('Nette\\Application\\LinkGenerator');
     $this->presenterFactory = $this->container->getByType('Nette\\Application\\IPresenterFactory');
     $this->authenticator = new Authenticator();
 }
开发者ID:krajcikondra,项目名称:netteTesterExtension,代码行数:12,代码来源:BasePresenterTester.php

示例9: createFromContainer

 public static function createFromContainer(Container $context)
 {
     /** @var EntityManager $em */
     $em = $context->getByType(EntityManager::class);
     /** @var Configuration $conf */
     $conf = $context->getByType(Configuration::class);
     return new self($em, $conf, $context->getParameters()['tempDir']);
 }
开发者ID:instante,项目名称:php-test-suite,代码行数:8,代码来源:DoctrineTester.php

示例10: create

 public function create() : Broker
 {
     $tagToService = function (array $tags) {
         return array_map(function (string $serviceName) {
             return $this->container->getService($serviceName);
         }, array_keys($tags));
     };
     $phpClassReflectionExtension = $this->container->getByType(PhpClassReflectionExtension::class);
     return new Broker(array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::PROPERTIES_CLASS_REFLECTION_EXTENSION_TAG))), array_merge([$phpClassReflectionExtension], $tagToService($this->container->findByTag(self::METHODS_CLASS_REFLECTION_EXTENSION_TAG))), $tagToService($this->container->findByTag(self::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG)), $this->container->getByType(FunctionReflectionFactory::class));
 }
开发者ID:phpstan,项目名称:phpstan,代码行数:10,代码来源:BrokerFactory.php

示例11: getServices

 /**
  * @return array
  */
 public function getServices()
 {
     if ($this->services) {
         return $this->services;
     }
     $services = [];
     foreach ($this->emails as $email) {
         $services[$email] = $this->container->getByType($email);
     }
     return $this->services = $services;
 }
开发者ID:WebChemistry,项目名称:Emails,代码行数:14,代码来源:Provider.php

示例12: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = $this->container->getByType('Nette\\Database\\Connection');
     try {
         $db->query(self::USERS_TABLE_DDL);
         $db->query(self::PACKAGES_TABLE_DDL);
         $output->writeln('App installed');
     } catch (\PDOException $e) {
         $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
     }
 }
开发者ID:bazo,项目名称:satis-gui,代码行数:11,代码来源:Install.php

示例13: getPanel

 public function getPanel()
 {
     $app = $this->container->getByType('Nette\\Application\\Application');
     $presenter = $app->getPresenter();
     $link = '/sallyx-bridges-stream-wrappers-nette-presenters/redis';
     if ($presenter !== NULL) {
         $link = $presenter->link(':SallyxBridgesStreamWrappersNettePresenters:Redis:');
     }
     $jsScript = file_get_contents(__DIR__ . '/assets/main.js');
     $jsScript = str_replace(array('%redisPresenterLink%', '%scheme%'), array($link, $this->scheme), $jsScript);
     return '<h1>Redis stream wrapper ' . $this->scheme . '://</h1>' . '<div class="nette-inner tracy-inner">' . '<style type="text/css">' . file_get_contents(__DIR__ . '/assets/style.css') . '</style>' . '<div class="sallyx-streamWrappers-fileBrowser ' . $this->scheme . '"></div>' . '<script type="text/javascript">' . $jsScript . '</script>' . '</div>';
 }
开发者ID:sallyx,项目名称:redis-php-stream-wrapper,代码行数:12,代码来源:Panel.php

示例14: addUrlGenerators

 /**
  * @param Builder $hateoasBuilder
  */
 private function addUrlGenerators(Builder &$hateoasBuilder)
 {
     if (!empty($this->config['urlGenerators'])) {
         $hasDefault = false;
         foreach ($this->config['urlGenerators'] as $name => $generator) {
             if (is_numeric($name) && !$hasDefault) {
                 $name = null;
                 $hasDefault = true;
             }
             $hateoasBuilder->setUrlGenerator($name, $this->container->getByType($generator));
         }
     }
 }
开发者ID:klimesf,项目名称:nette-hateoas,代码行数:16,代码来源:HateoasBuilder.php

示例15: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('building package.json...');
     $packages = explode(' ', $input->getArgument('packages'));
     $builder = $this->container->getByType('App\\Model\\Builder');
     $builder->build($packages, function ($type, $buffer) use($output) {
         if ($type === Process::ERR) {
             $output->writeln(sprintf('<error>%s</error>', $buffer));
         } else {
             $output->writeln(sprintf('<info>%s</info>', $buffer));
         }
     });
     $output->writeln('built package.json');
 }
开发者ID:bazo,项目名称:satis-gui,代码行数:14,代码来源:Build.php


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