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


PHP Container::addService方法代码示例

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


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

示例1: signIn

 public function signIn(Nette\DI\Container $container)
 {
     $container->removeService('nette.userStorage');
     $userStorage = m::mock('Nette\\Security\\IUserStorage');
     $userStorage->shouldReceive('isAuthenticated')->once()->andReturn(true);
     $userStorage->shouldReceive('getIdentity')->once()->andReturn(new Nette\Security\Identity(1));
     $container->addService('nette.userStorage', $userStorage);
 }
开发者ID:CSHH,项目名称:website,代码行数:8,代码来源:Login.php

示例2: reloadSystemContainer

 /**
  * Reload system container.
  */
 protected function reloadSystemContainer()
 {
     /** @var $configurator Configurator */
     $configurator = $this->context->configurator;
     $class = $this->context->parameters['container']['class'] . $this->_systemContainer++;
     LimitedScope::evaluate($configurator->buildContainer($dependencies, $class));
     /** @var context Container */
     $this->context = new $class();
     $this->context->parameters = (include $this->configDir . '/settings.php') + $this->context->parameters;
     $this->context->initialize();
     $this->context->addService("configurator", $configurator);
 }
开发者ID:svobodni,项目名称:web,代码行数:15,代码来源:ModuleManager.php

示例3: invoke

 public function invoke(Container $container, Generator $faker, RepositoryContainer $orm)
 {
     $this->faker = $faker;
     $container->addService('subtitles', $container->createInstance(FakeSubtitles::class));
     $users = $this->create(50, User::class, $orm->users, [$this, 'fillUser']);
     $videos = $this->create(20, Video::class, $orm->contents, [$this, 'fillVideo']);
     $this->createComments(10, $videos, $users, $orm->contents);
     $subjects = $this->create(7, Subject::class, $orm->subjects, [$this, 'fillSubject']);
     $this->createSchemasAndBlocks($orm, $subjects, $videos);
     $this->out->writeln('flushing');
     $orm->flush();
     $this->out->writeln('<info>done</info>');
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:13,代码来源:Fake.php

示例4: doRequest

 /**
  * Makes a request.
  *
  * @param IRequest $request
  * @return BrowserKit\Response
  * @throws MissingContainerException
  */
 protected function doRequest($request)
 {
     if ($this->container === NULL) {
         throw new MissingContainerException('Container is missing, use setContainer() method to set it.');
     }
     $response = new Response();
     $this->container->removeService('httpRequest');
     $this->container->addService('httpRequest', $request);
     $this->container->removeService('httpResponse');
     $this->container->addService('httpResponse', $response);
     /** @var IPresenterFactory $presenterFactory */
     $presenterFactory = $this->container->getByType(IPresenterFactory::class);
     /** @var IRouter $router */
     $router = $this->container->getByType(IRouter::class);
     $application = new Application($presenterFactory, $router, $request, $response);
     $this->container->removeService('application');
     $this->container->addService('application', $application);
     ob_start();
     $application->run();
     $content = ob_get_clean();
     return new BrowserKit\Response($content, $response->getCode(), $response->getHeaders());
 }
开发者ID:VaclavSir,项目名称:NBrowserKit,代码行数:29,代码来源:Client.php

示例5: testDIMultiInstance

 public function testDIMultiInstance()
 {
     $key1 = 'hello';
     $value1 = new \stdClass();
     $key2 = 'Night';
     $value2 = new \stdClass();
     //register key1 in first instance, key2 in second instance
     $this->nette->addService($key1, $value1);
     $nette = new NetteContainer();
     $nette->addService($key2, $value2);
     $adapter = new NetteAdapter($nette);
     $this->container->provider($adapter);
     $this->assertInstanceOf('stdClass', $this->container->get($key1));
     $this->assertInstanceOf('stdClass', $this->container->get($key2));
 }
开发者ID:njasm,项目名称:container,代码行数:15,代码来源:NetteAdapterTest.php

示例6: boot

 public function boot(Nette\DI\Container $container, $databaseName)
 {
     $this->windows = array();
     $this->waitForSeleniumSlot();
     $this->serviceLocator = $container;
     TesterHelpers::setup();
     // ensure error & exception helpers are registered
     $this->httpServer = new HttpServer();
     $env = (array) $this->options[self::OPTION_ENV_VARIABLES] + array($this->options[self::OPTION_ENV_PREFIX] . '_DEBUG' => '0', $this->options[self::OPTION_ENV_PREFIX] . '_SELENIUM' => '1', $this->options[self::OPTION_ENV_PREFIX] . '_DATABASE' => $databaseName, $this->options[self::OPTION_ENV_PREFIX] . '_LOG_DIR' => TEMP_DIR, $this->options[self::OPTION_ENV_PREFIX] . '_TEMP_DIR' => TEMP_DIR);
     $this->httpServer->start($this->serviceLocator->expand($this->options[self::OPTION_ROUTER]), $env);
     $httpRequest = new Nette\Http\Request($this->httpServer->getUrl(), array(), array(), array(), array(), array(), 'GET');
     $this->serviceLocator->removeService('httpRequest');
     $this->serviceLocator->addService('httpRequest', $httpRequest);
     $this->sessionFactory = new SessionFactory($this->serviceLocator, $this->httpServer, $this->options);
     $this->currentSession = $this->sessionFactory->create();
     $this->currentSession->setContext($this);
     $this->windows[] = $this->currentSession;
     if ($this->options[self::OPTION_VIDEO_ENABLE]) {
         $this->videoRecorder = new VideoRecorder(TEMP_DIR);
         $this->videoRecorder->start();
     }
 }
开发者ID:kdyby,项目名称:selenium,代码行数:22,代码来源:SeleniumContext.php

示例7: request

 /**
  * @param string $method
  * @param string $path
  * @param array $headers
  * @param string|null $body
  * @return Http\Response
  */
 public function request($method, $path, array $headers = [], $body = NULL)
 {
     $this->appResponse = NULL;
     $url = new Http\UrlScript($this->baseUri . $path);
     $this->httpRequest = (new HttpRequestMock($url, NULL, [], [], [], $headers, $method, '127.0.0.1', '127.0.0.1'))->setRawBody($body);
     $this->httpResponse = new HttpResponseMock();
     // mock request & response
     $this->sl->removeService('httpRequest');
     $this->sl->addService('httpRequest', $this->httpRequest);
     $this->sl->removeService('httpResponse');
     $this->sl->addService('httpResponse', $this->httpResponse);
     /** @var Kdyby\FakeSession\Session $session */
     $session = $this->sl->getService('session');
     $session->__construct(new Http\Session($this->httpRequest, $this->httpResponse));
     /** @var Nette\Application\IPresenterFactory $presenterFactory */
     $presenterFactory = $this->sl->getByType('Nette\\Application\\IPresenterFactory');
     /** @var Application $application */
     $application = $this->sl->getByType('Nette\\Application\\Application');
     $application->__construct($presenterFactory, $this->getRouter(), $this->httpRequest, $this->httpResponse);
     $application->onResponse[] = function (Application $application, Nette\Application\IResponse $response) {
         $this->appResponse = $response;
         $this->httpResponse->setAppResponse($response);
     };
     $appRequest = $this->getRouter()->match($this->httpRequest);
     $this->onBeforeRequest($appRequest, $this->sl);
     try {
         ob_start();
         try {
             $this->appResponse = NULL;
             $application->processRequest($appRequest);
         } catch (\Exception $e) {
             $application->processException($e);
         }
         $this->httpResponse->setContent(ob_get_clean());
     } finally {
         $this->logger->log($this->httpRequest, $this->httpResponse);
     }
     return $this->httpResponse;
 }
开发者ID:kdyby,项目名称:tester-extras,代码行数:46,代码来源:RequestProcessor.php

示例8: createServiceUser

 /**
  * @return Nette\Http\User
  */
 public static function createServiceUser(DI\Container $container)
 {
     $context = new DI\Container();
     // copies services from $container and preserves lazy loading
     $context->addService('authenticator', function () use($container) {
         return $container->authenticator;
     });
     $context->addService('authorizator', function () use($container) {
         return $container->authorizator;
     });
     $context->addService('session', $container->session);
     return new Nette\Http\User($context);
 }
开发者ID:kovkus,项目名称:r-cms,代码行数:16,代码来源:Configurator.php

示例9: setRaw

 /**
  * @param string $name
  * @param PhServiceInterface $definition
  * @return object
  */
 public function setRaw($name, PhServiceInterface $definition)
 {
     return $this->container->addService($name, $definition);
 }
开发者ID:phalette,项目名称:pidic,代码行数:9,代码来源:PiDi.php

示例10: createServiceUser

	/**
	 * @param \Nette\DI\Container
	 * @return Security\User
	 */
	public static function createServiceUser(Container $container)
	{
		$context = new \Nette\DI\Container;
		$context->addService('authenticator', function() use ($container) {
			return $container->authenticator;
		});
		$context->addService('authorizator', function() use ($container) {
			return $container->authorizator;
		});
		$context->addService('session', $container->session);
		$context->addService('doctrineContainer', function() use ($container) {
			return $container->doctrineContainer;
		});
		return new Security\User($context);
	}
开发者ID:norbe,项目名称:framework,代码行数:19,代码来源:Configurator.php

示例11: create

	/**
	 * @param \Nette\DI\Container
	 * @param string
	 * @return Container
	 */
	public static function create(DI\Container $context, $sectionName = "database")
	{
		if (!isset($context->params[$sectionName])) {
			throw new \Nette\InvalidStateException("Doctrine configuration section '$sectionName' does not exist");
		}

		if (!$context->hasService('versionListener')) {
			$context->addService('versionListener', 'Nella\Doctrine\Listeners\Version', array('listener'));
		}
		if (!$context->hasService('validatorListener')) {
			$context->addService('validatorListener', function(DI\Container $context) {
				return new Listeners\Validator($context->validator);
			}, array('listener'));
		}
		if (!$context->hasService('mediaListener')) {
			$context->addService('mediaListener', function(DI\Container $context) {
				return new \Nella\Media\Listener($context->cacheStorage);
			}, array('listener'));
		}

		foreach (get_class_methods(get_called_class()) as $method) {
			if (\Nette\Utils\Strings::startsWith($method, 'createService')) {
				$name = strtolower(substr($method, 13, 1)) . substr($method, 14);
				if (!$context->hasService($name)) {
					$context->addService($name, callback(get_called_class(), $method));
				}
			}
		}
		return new static($context, $context->params[$sectionName]);
	}
开发者ID:norbe,项目名称:framework,代码行数:35,代码来源:Container.php

示例12: addMapper

 /**
  * @param string $name
  * @param IMapper|callback $mapper
  */
 public function addMapper($name, $mapper)
 {
     $this->mapperContainer->addService($name, $mapper);
 }
开发者ID:voda,项目名称:formbuilder,代码行数:8,代码来源:Builder.php

示例13: createServiceUser

 static function createServiceUser(DI\Container $container)
 {
     $context = new DI\Container();
     $context->addService('authenticator', function () use($container) {
         return $container->authenticator;
     });
     $context->addService('authorizator', function () use($container) {
         return $container->authorizator;
     });
     $context->addService('session', $container->session);
     return new Nette\Http\User($context);
 }
开发者ID:radekdostal,项目名称:Nette-ForumControl,代码行数:12,代码来源:loader.php


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