本文整理汇总了PHP中Symfony\Component\DependencyInjection\Container::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::has方法的具体用法?PHP Container::has怎么用?PHP Container::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Container
的用法示例。
在下文中一共展示了Container::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: let
public function let(ArticleService $articleService, AuthorService $authorService, CacheService $cacheService, Container $container, ArticleRepository $articleRepository, LanguageRepository $languageRepository, ArticleTypeRepository $articleTypeRepository, PublicationRepository $publicationRepository, IssueRepository $issueRepository, SectionRepository $sectionRepository, AuthorTypeRepository $authorTypeRepository, EntityManager $entityManager, Request $request, FormFactory $formFactory, FormBuilder $formBuilder, Form $form, FormView $formView, User $user, UserService $userService, Article $article, Publication $publication, ArticleType $articleType, Issue $issue, Section $section, Language $language, Author $author, AuthorType $authorType, AbstractQuery $query, SecurityContext $security, TokenStorage $tokenStorage, TokenInterface $token, Router $router)
{
$container->get('em')->willReturn($entityManager);
$container->get('request')->willReturn($request);
$container->get('user')->willReturn($userService);
$container->get('form.factory')->willReturn($formFactory);
$container->get('newscoop_newscoop.article_service')->willReturn($articleService);
$container->get('author')->willReturn($authorService);
$container->get('newscoop.cache')->willReturn($cacheService);
$container->get('router')->willReturn($router);
$formBuilder->getForm(Argument::cetera())->willReturn($form);
$formFactory->create(Argument::cetera())->willReturn($form);
$form->createView()->willReturn($formView);
$form->handleRequest(Argument::cetera())->willReturn(true);
$form->isValid()->willReturn(true);
$security->getToken()->willReturn($token);
$container->get('security.context')->willReturn($security);
$container->has('security.context')->willReturn(true);
$container->has('security.token_storage')->willReturn(true);
$container->get('security.token_storage')->willReturn($tokenStorage);
$this->setContainer($container);
$entityManager->getRepository('Newscoop\\Entity\\Article')->willReturn($articleRepository);
$entityManager->getRepository('Newscoop\\Entity\\Language')->willReturn($languageRepository);
$entityManager->getRepository('Newscoop\\Entity\\ArticleType')->willReturn($articleTypeRepository);
$entityManager->getRepository('Newscoop\\Entity\\Publication')->willReturn($publicationRepository);
$entityManager->getRepository('Newscoop\\Entity\\Issue')->willReturn($issueRepository);
$entityManager->getRepository('Newscoop\\Entity\\Section')->willReturn($sectionRepository);
$entityManager->getRepository('Newscoop\\Entity\\AuthorType')->willReturn($authorTypeRepository);
$articleRepository->getArticle(Argument::cetera())->willReturn($query);
$entityManager->flush(Argument::any())->willReturn(true);
$userService->getCurrentUser()->willReturn($user);
$number = 64;
$language = "en";
}
示例2: testToolbarConfig
/**
* @dataProvider getDebugModes
*/
public function testToolbarConfig($debug)
{
$this->container->setParameter('kernel.debug', $debug);
$extension = new WebProfilerExtension();
$extension->load(array(array('toolbar' => $debug)), $this->container);
$this->assertTrue($debug === $this->container->has('web_profiler.debug_toolbar'), '->load() registers web_profiler.debug_toolbar only when toolbar is true');
$this->assertSaneContainer($this->getDumpedContainer());
}
示例3: testToolbarConfig
/**
* @dataProvider getDebugModes
*/
public function testToolbarConfig($toolbarEnabled, $interceptRedirects, $listenerInjected, $listenerEnabled)
{
$extension = new WebProfilerExtension();
$extension->load(array(array('toolbar' => $toolbarEnabled, 'intercept_redirects' => $interceptRedirects)), $this->container);
$this->assertSame($listenerInjected, $this->container->has('web_profiler.debug_toolbar'));
if ($listenerInjected) {
$this->assertSame($listenerEnabled, $this->container->get('web_profiler.debug_toolbar')->isEnabled());
}
$this->assertSaneContainer($this->getDumpedContainer());
}
示例4: resolveFacadeInstance
/**
* Resolves the provided accessor into an object instance.
*
* @param object|string $accessor
*
* @return object
*/
private static function resolveFacadeInstance($accessor)
{
if (is_object($accessor)) {
return $accessor;
}
if (isset(static::$facadeInstances[$accessor])) {
return static::$facadeInstances[$accessor];
}
if (static::$container->has($accessor)) {
return static::$facadeInstances[$accessor] = static::$container->get($accessor);
}
throw new \LogicException(sprintf('Unknown facade accessor "%s"', print_r($accessor, true)));
}
示例5: setupDependencies
/**
* @param $class
*/
public function setupDependencies($class)
{
if (!$this->container->has(InjectableCompilerPass::INJECTABLES_SERVICE_ID)) {
return;
}
$references = $this->container->get(InjectableCompilerPass::INJECTABLES_SERVICE_ID)->references;
if (!isset($references[get_class($class)])) {
return;
}
if (!in_array('__dependencies', get_class_methods($class))) {
return;
}
$services = $this->getServices($references[get_class($class)]);
call_user_func_array([$class, '__dependencies'], $services);
}
示例6: has
/**
* {@inheritdoc}
*/
public function has($id)
{
if (array_key_exists($id, $this->mocked)) {
return true;
}
return parent::has($id);
}
示例7: validateImportConfiguration
/**
* Valide la configuration du fichier import.yml.
*
* @return bool
*
* @throws \Exception En cas d'erreur de configuration.
*/
private function validateImportConfiguration()
{
$configuration = $this->configuration;
// Vérification des handlers
if (empty($configuration['handlers'])) {
throw new \Exception($this->getExceptionMessage(array('handlers'), "Aucun handler n'est défini."));
}
if (!is_array($configuration['handlers'])) {
throw new \Exception($this->getExceptionMessage(array('handlers'), "Doit être un tableau."));
}
foreach ($configuration['handlers'] as $type => $handlers) {
if (!in_array($type, array('mouvements', 'pleins'))) {
throw new \Exception($this->getExceptionMessage(array('handlers', $type), "Les types de handler autorisés sont [mouvements] et [pleins], pas [{$type}]."));
}
if (!is_array($handlers)) {
throw new \Exception($this->getExceptionMessage(array('handlers', $type), "Doit être un tableau."));
}
foreach ($handlers as $identifier => $handler) {
$hasService = $this->container->has("comptes_bundle.import.{$type}.{$identifier}");
if (!$hasService) {
throw new \Exception($this->getExceptionMessage(array('handlers', $type, $identifier), "Aucun service correspondant à [comptes_bundle.import.{$type}.{$identifier}]."));
}
if (!key_exists('name', $handler)) {
throw new \Exception($this->getExceptionMessage(array('handlers', $type, $identifier, 'name'), "Paramètre manquant."));
}
if (!key_exists('extension', $handler)) {
throw new \Exception($this->getExceptionMessage(array('handlers', $type, $identifier, 'extension'), "Paramètre manquant."));
}
}
}
return true;
}
示例8: get
/**
* {@inheritdoc}
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if (parent::has($id)) {
return parent::get($id, $invalidBehavior);
}
return $this->injector->getInstance($id);
}
示例9: has
/**
* @param string $id
*
* @return boolean
*/
public function has($id)
{
if (array_key_exists($id, self::$mockedServices)) {
return true;
}
return parent::has($id);
}
示例10: buildForPreprocessor
public function buildForPreprocessor(Request $request, Route $preprocessorRoute)
{
// NO RabbitMQ case here: preprocessor are called synchronously.
// Localhost case
if ($preprocessorRoute->getDefault('_http_host') === $request->getHttpHost()) {
$this->logger->info("InternalForwarder built for preprocessor: Localhost forwarder.", ['host' => $request->getHttpHost()]);
return $this->container->get('prestashop.public_writer.protocol.internal_forwarder.localhost');
}
// HTTP forward case
if ($this->container->has('prestashop.saas.protocol.internal_forwarder.http')) {
$this->logger->info("InternalForwarder built for forward: HTTP forwarder.", ['host' => $preprocessorRoute->getDefault('_http_host')]);
return $this->container->get('prestashop.saas.protocol.internal_forwarder.http');
}
// Error case: localhost case was not matching, but there is no other forwarder available.
$this->logger->error("InternalForwarder built for preprocessor: NO forwarder found to reach distant host.", ['host' => $request->getHttpHost()]);
throw new \ErrorException("InternalForwarder building for preprocessor: NO forwarder found to reach distant host: " . $request->getHttpHost());
}
示例11: createDefaultContainer
/**
* Create the default container containing all basic services.
*
* @param array $services Array of services to provide.
*
* @return Container
*/
protected function createDefaultContainer($services = [])
{
$container = new Container();
foreach ($services as $name => $service) {
$container->set($name, $service);
}
if (!$container->has('event_dispatcher')) {
$container->set('event_dispatcher', new EventDispatcher());
}
if (!$container->has('tenside.home')) {
$home = $this->getMock(HomePathDeterminator::class, ['homeDir']);
$home->method('homeDir')->willReturn($this->getTempDir());
$container->set('tenside.home', $home);
}
if (!$container->has('tenside.config')) {
$container->set('tenside.config', TensideJsonConfigFactory::create($container->get('tenside.home')));
}
if (!$container->has('tenside.taskfactory')) {
$container->set('tenside.taskfactory', new ComposerTaskFactory($container->get('tenside.home')));
}
if (!$container->has('tenside.tasks')) {
$container->set('tenside.tasks', TaskListFactory::create($container->get('tenside.home'), $container->get('tenside.taskfactory')));
}
if (!$container->has('tenside.composer_json')) {
$container->set('tenside.composer_json', ComposerJsonFactory::create($container->get('tenside.home')));
}
if (!$container->has('tenside.status')) {
$tenside = new InstallationStatusDeterminator($container->get('tenside.home'));
$container->set('tenside.status', $tenside);
}
return $container;
}
示例12: getUser
/**
* Get a user from the Security Context
*
* @return \Symforce\DiscuzBundle\Entity\User | null
*
* @throws \LogicException If SecurityBundle is not available
*
* @see Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUser()
*/
protected function getUser()
{
if (!$this->_container->has('security.context')) {
throw new \LogicException('The SecurityBundle is not registered in your application.');
}
if (null === ($token = $this->_container->get('security.context')->getToken())) {
return;
}
if (!is_object($user = $token->getUser())) {
return;
}
return $user;
}
示例13: createFilter
public function createFilter(Container $container)
{
if ($class = $this->class) {
if (!class_exists($class)) {
throw new \Exception('Unknown class ' . $class . ' configured with the Webfactory\\Bundle\\LegacyIntegrationBundle\\Integration\\Annotation\\Filter annotation.');
}
$filter = new $class();
}
if ($service = $this->service) {
if (!$container->has($service)) {
throw new \Exception('Unknown service ' . $service . ' configured with the Webfactory\\Bundle\\LegacyIntegrationBundle\\Integration\\Annotation\\Filter annotation.');
}
$filter = $container->get($service);
}
if (!$filter instanceof FilterInterface) {
throw new \Exception("Class " . get_class($filter) . ' configured with the Webfactory\\Bundle\\LegacyIntegrationBundle\\Integration\\Annotation\\Filter annotation is not a Webfactory\\Bundle\\LegacyIntegrationBundle\\Integration\\Filter.');
}
return $filter;
}
示例14: get
/**
* {@inheritdoc}
*/
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
{
if (parent::has($id)) {
return parent::get($id, $invalidBehavior);
}
if (!$this->fallbackContainer) {
return false;
}
try {
$entry = $this->fallbackContainer->get($id);
// Stupid hack for Symfony's ContainerAwareInterface
if ($entry instanceof ContainerAwareInterface) {
$entry->setContainer($this);
}
return $entry;
} catch (NotFoundException $e) {
if ($invalidBehavior === self::EXCEPTION_ON_INVALID_REFERENCE) {
throw new ServiceNotFoundException($id);
}
}
return null;
}
示例15: has
/**
* @param string $id
*
* @return boolean
*/
public function has($id)
{
return $this->hasMock($id) || parent::has($id);
}