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"; }
/** * @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()); }
/** * @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()); }
/** * 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))); }
/** * @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); }
/** * {@inheritdoc} */ public function has($id) { if (array_key_exists($id, $this->mocked)) { return true; } return parent::has($id); }
/** * 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; }
/** * {@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); }
/** * @param string $id * * @return boolean */ public function has($id) { if (array_key_exists($id, self::$mockedServices)) { return true; } return parent::has($id); }
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()); }
/** * 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; }
/** * 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; }
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; }
/** * {@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; }
/** * @param string $id * * @return boolean */ public function has($id) { return $this->hasMock($id) || parent::has($id); }
/** * Returns true if the given service is defined. * * Wrapper for ContainerBuilder::has method. * * @param string $id The service identifier * @return boolean True if the service is defined, false otherwise */ public function hasService($id) { return parent::has($id); }
/** * Returns true if the given service is defined. * * @param string $id The service identifier * * @return Boolean true if the service is defined, false otherwise */ public function has($id) { return isset($this->definitions[$id]) || isset($this->aliases[$id]) || parent::has($id); }
/** * {@inheritDoc} */ public function has($name) { return $this->container->has($name); }
/** * Loads the given resource. If the resource is already registered and the status * is STATUS_BOOTSTRAP an Enlight_Exception is thrown. * The resource is initial by the Enlight_Bootstrap_InitResource event. * If this event doesn't exist for the given resource, the resource is initialed * by call_user_func. * After the resource is initialed the event Enlight_Bootstrap_AfterInitResource is * fired. In case an exception is thrown by initializing the resource, * Enlight sets the status STATUS_NOT_FOUND for the resource in the resource status list. * In case the resource successfully initialed the resource has the status STATUS_LOADED * * @param string $name * @throws \Exception * @throws \Enlight_Exception * @return bool */ public function load($name) { $name = $this->getNormalizedId($name); if (isset($this->resourceStatus[$name])) { switch ($this->resourceStatus[$name]) { case self::STATUS_BOOTSTRAP: throw new \Enlight_Exception('Resource "' . $name . '" can\'t resolve all dependencies'); case self::STATUS_NOT_FOUND: return false; case self::STATUS_ASSIGNED: case self::STATUS_LOADED: return true; default: break; } } try { $this->resourceStatus[$name] = self::STATUS_BOOTSTRAP; $event = false; if (parent::has('events')) { $event = parent::get('events')->notifyUntil('Enlight_Bootstrap_InitResource_' . $name, array('subject' => $this)); } if ($event) { $this->resourceList[$name] = $event->getReturn(); } elseif (parent::has($name)) { $this->resourceList[$name] = parent::get($name); } if (parent::has('events')) { parent::get('events')->notify('Enlight_Bootstrap_AfterInitResource_' . $name, array('subject' => $this)); } } catch (\Exception $e) { $this->resourceStatus[$name] = self::STATUS_EXCEPTION; throw $e; } if (isset($this->resourceList[$name]) && $this->resourceList[$name] !== null) { $this->resourceStatus[$name] = self::STATUS_LOADED; return true; } else { $this->resourceStatus[$name] = self::STATUS_NOT_FOUND; return false; } }
public function testSetWithNullResetTheService() { $sc = new Container(); $sc->set('foo', null); $this->assertFalse($sc->has('foo'), '->set() with null service resets the service'); }
function it_does_nothing_if_no_injectables_service_was_defined(Container $container) { $container->has(InjectableCompilerPass::INJECTABLES_SERVICE_ID)->willReturn(false); $container->get(Argument::any())->shouldNotBeCalled(); }
/** * Returns true if the given service is defined. * * @param string $id The service identifier * * @return bool true if the service is defined, false otherwise */ public function has($id) { $id = strtolower($id); return isset($this->definitions[$id]) || isset($this->aliasDefinitions[$id]) || parent::has($id); }
/** * Return true, if current configuration is supported. * * @param ParamConverter $configuration * @return boolean */ public function supports(ParamConverter $configuration) { $options = $this->getOptions($configuration); return $this->container->has($options['service']) && !empty($options['method']); }
/** * @group legacy */ public function testEnterChildScopeRecursively() { $container = new Container(); $container->addScope(new Scope('foo')); $container->addScope(new Scope('bar', 'foo')); $container->enterScope('foo'); $container->enterScope('bar'); $this->assertTrue($container->isScopeActive('bar')); $this->assertFalse($container->has('a')); $a = new \stdClass(); $container->set('a', $a, 'bar'); $scoped = $this->getField($container, 'scopedServices'); $this->assertTrue(isset($scoped['bar']['a'])); $this->assertSame($a, $scoped['bar']['a']); $this->assertTrue($container->has('a')); $container->enterScope('bar'); $scoped = $this->getField($container, 'scopedServices'); $this->assertFalse(isset($scoped['a'])); $this->assertTrue($container->isScopeActive('foo')); $this->assertTrue($container->isScopeActive('bar')); $this->assertFalse($container->has('a')); $container->leaveScope('bar'); $this->assertTrue($container->isScopeActive('foo')); $this->assertTrue($container->isScopeActive('bar')); $this->assertTrue($container->has('a')); }
/** * @Then it should contain services from both files */ public function itShouldContainServicesFromBothFiles() { expect($this->generatedContainer->has('my_service1'))->toBe(true); expect($this->generatedContainer->has('my_service2'))->toBe(true); }