public function fetchConfigurationValue(string $configPath) { if (null === $this->parameterBag) { throw new \LogicException('Parameter bag should be injected with setter method first'); } return $this->parameterBag->get($configPath); }
function it_gets_credentials(Request $request, ParameterBagInterface $headersBag) { $headersBag->has('Authorization')->shouldBeCalled()->willReturn(true); $headersBag->get('Authorization')->shouldBeCalled()->willReturn('Bearer bearer-token'); $request->headers = $headersBag; $this->getCredentials($request)->shouldReturn('bearer-token'); }
function it_sets_the_request_attribute_from_the_current_time(GetResponseEvent $event, ParameterBagInterface $attributesParameterBag) { $request = new Request([], [], [], [], [], []); $request->attributes = $attributesParameterBag->getWrappedObject(); $event->getRequest()->willReturn($request); $attributesParameterBag->set('_tolerance_request_time', Argument::type('float'))->shouldBeCalled(); $this->onRequest($event); }
function it_joins_slack(ContainerInterface $container, Request $request, ParameterBagInterface $bag) { $container->getParameter('slack_org')->shouldBeCalled()->willReturn('slack-org'); $container->getParameter('slack_apiKey')->shouldBeCalled()->willReturn('slack-api-key'); $bag->get('email'); $request->query = $bag; $request->get('email')->shouldBeCalled()->willReturn('*****@*****.**'); $this->joinSlackAction($request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }
/** * Gets a config. * * @param string $name The config name * * @return mixed The config value */ public function get($key, $default = null) { try { return $this->parameterBag->get($key); } catch (ParameterNotFoundException $e) { if (null !== $default) { return $default; } } throw $e; }
function it_gets_credentials(Request $request, ParameterBagInterface $parameterBag, ParameterBagInterface $attributesBag, SessionInterface $session) { $parameterBag->get('_email')->shouldBeCalled()->willReturn('*****@*****.**'); $parameterBag->get('_password')->shouldBeCalled()->willReturn('111111'); $attributesBag->get('_route')->shouldBeCalled()->willReturn('bengor_user_user_security_login_check'); $request->request = $parameterBag; $request->attributes = $attributesBag; $request->getSession()->shouldBeCalled()->willReturn($session); $session->set(Security::LAST_USERNAME, '*****@*****.**')->shouldBeCalled(); $this->getCredentials($request)->shouldReturnAnInstanceOf(LogInUserCommand::class); }
public function setUp() { $this->asset = $this->getMock('Assetic\\Asset\\AssetInterface'); $parameters = array('foo' => 'foo value', 'bar' => 'bar value', 'foo.bar' => 'foo dot bar value', 'null' => null, 'quotes' => '"aren\'t quotes wonderful"', 'array' => array('test' => 'something')); $this->parameterBag = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBagInterface'); $this->parameterBag->expects($this->any())->method('get')->will($this->returnCallback(function ($key) use($parameters) { return $parameters[$key]; })); $this->parameterBag->expects($this->any())->method('has')->will($this->returnCallback(function ($key) use($parameters) { return array_key_exists($key, $parameters); })); }
function it_enable_action(ContainerInterface $container, Request $request, ParameterBagInterface $bag, UserCommandBus $commandBus, Session $session, FlashBagInterface $flashBag, Router $router, Translator $translator) { $request->query = $bag; $bag->get('confirmation-token')->shouldBeCalled()->willReturn('confirmation-token'); $container->get('bengor_user.user.command_bus')->shouldBeCalled()->willReturn($commandBus); $commandBus->handle(Argument::type(EnableUserCommand::class))->shouldBeCalled(); $container->get('translator')->shouldBeCalled()->willReturn($translator); $container->has('session')->shouldBeCalled()->willReturn(true); $container->get('session')->shouldBeCalled()->willReturn($session); $session->getFlashBag()->shouldBeCalled()->willReturn($flashBag); $container->get('router')->shouldBeCalled()->willReturn($router); $router->generate('bengor_user_user_homepage', [], UrlGeneratorInterface::ABSOLUTE_PATH)->shouldBeCalled()->willReturn('/'); $this->enableAction($request, 'user', 'bengor_user_user_homepage'); }
function it_login_action(Request $request, ContainerInterface $container, AuthorizationCheckerInterface $authorizationChecker, AuthenticationUtils $helper, ParameterBagInterface $parameterBag, TwigEngine $templating, Response $response) { $container->get('security.authorization_checker')->shouldBeCalled()->willReturn($authorizationChecker); $authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')->shouldBeCalled()->willReturn(false); $container->get('security.authentication_utils')->shouldBeCalled()->willReturn($helper); $helper->getLastUsername()->shouldBeCalled()->willReturn('*****@*****.**'); $helper->getLastAuthenticationError()->shouldBeCalled()->willReturn('error'); $parameterBag->get('_route')->shouldBeCalled()->willReturn('login'); $request->attributes = $parameterBag; $container->has('templating')->shouldBeCalled()->willReturn(true); $container->get('templating')->shouldBeCalled()->willReturn($templating); $templating->renderResponse('@BenGorUser/security/login.html.twig', ['last_email' => '*****@*****.**', 'error' => 'error', 'login_check' => 'login_check'], null)->shouldBeCalled()->willReturn($response); $this->loginAction($request, 'admin')->shouldReturn($response); }
/** * Loads a parameter given the format "namespace.key" * * @param string $configurationIdentifier Configuration identifier * @param string $defaultValue Default value * * @return null|string|boolean Configuration parameter value * * @throws ConfigurationParameterNotFoundException Configuration parameter not found * @throws Exception Configuration cannot be resolved */ public function get($configurationIdentifier, $defaultValue = null) { /** * Checks if the value is defined in the configuration elements */ if (!array_key_exists($configurationIdentifier, $this->configurationElements)) { if (!is_null($defaultValue)) { return $defaultValue; } throw new ConfigurationParameterNotFoundException(); } $valueIsCached = $this->cache->contains($configurationIdentifier); /** * The value is cached, so we can securely return its value. * We must unserialize the value if needed */ if (false !== $valueIsCached) { return $this->cache->fetch($configurationIdentifier); } list($configurationNamespace, $configurationKey) = $this->splitConfigurationKey($configurationIdentifier); $configurationLoaded = $this->loadConfiguration($configurationNamespace, $configurationKey); if (!$configurationLoaded instanceof ConfigurationInterface) { $configurationElement = $this->configurationElements[$configurationIdentifier]; $configurationValue = isset($configurationElement['reference']) ? $this->parameterBag->get($configurationElement['reference']) : $configurationElement['default_value']; if (empty($configurationValue) && !$configurationElement['can_be_empty']) { $message = $configurationElement['empty_message'] ?: 'The configuration element "' . $configurationIdentifier . '" cannot be resolved'; throw new Exception($message); } $configurationLoaded = $this->createConfigurationInstance($configurationIdentifier, $configurationNamespace, $configurationKey, $configurationValue); $this->flushConfiguration($configurationLoaded); } $configurationValueUnserialized = $this->flushConfigurationToCache($configurationLoaded, $configurationIdentifier); return $configurationValueUnserialized; }
/** * @return array */ private function getIgnoredServicePatterns() { try { return (array) $this->parameterBag->resolveValue("%autowiring.ignored_services%"); } catch (ParameterNotFoundException $exception) { return []; } }
/** * Extracts filter type parameters from dom-node. * * @param \DOMXPath $xpath * @param \DOMNode $propertyNode * * @return array */ protected function getFilterTypeParameters(\DOMXPath $xpath, \DOMNode $propertyNode) { $parameters = []; foreach ($xpath->query('x:filter-type-parameters/x:parameter', $propertyNode) as $parameterNode) { $key = XmlUtil::getValueFromXPath('@key', $xpath, $parameterNode); $parameters[$key] = $this->parameterBag->resolveValue(trim($parameterNode->nodeValue)); } return $parameters; }
/** * {@inheritdoc} */ public function load($file, $type = null) { $path = $this->locator->locate($file); if (!class_exists('Symfony\\Component\\Yaml\\Parser')) { throw new \RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.'); } if (!stream_is_local($path)) { throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $path)); } if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('File "%s" not found.', $path)); } if (null === $this->yamlParser) { $this->yamlParser = new YamlParser(); } try { $parsedConfig = $this->yamlParser->parse(file_get_contents($path)); } catch (ParseException $e) { throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e); } if ($this->parameterBag) { $parsedConfig = $this->parameterBag->resolveValue($parsedConfig); } $collection = new RouteCollection(); $collection->addResource(new FileResource($path)); // empty file if (null === $parsedConfig) { return $collection; } // not an array if (!is_array($parsedConfig)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $path)); } foreach ($parsedConfig as $name => $config) { $this->validate($config, $name, $path); if (isset($config['resource'])) { $this->parseImport($collection, $config, $path, $file); } else { $this->parseRoute($collection, $name, $config, $path); } } return $collection; }
/** * @param string $eventName * @param array $values * @param string|null $tracker * @return string */ public function tcEvent($eventName, $values = array(), $tracker = null) { if (is_null($tracker)) { $tracker = $this->defaultEvent; } $function = $this->events[$tracker]['function']; $event = new Track($tracker, $eventName, array_merge($this->datalayer->all(), $values)); $this->dispatcher->dispatch('tc_event', $event); return sprintf("%s('%s', %s);", $function, $eventName, $this->serializeWithValues($values)); }
/** * {@inheritdoc} */ public function load($resource, $type = null) { $path = $this->locator->locate($resource); $content = $this->loadFile($path); // empty file if (null === $content) { return; } // imports $this->parseImports($content, $path); $content = $this->parameterBag->resolveValue($content); foreach ($content as $namespace => $values) { if (in_array($namespace, ['imports'])) { continue; } if (isset($this->container[$namespace]) && is_array($values)) { $values = $this->merge($this->container[$namespace], $values); } $this->container[$namespace] = $values; } return $content; }
function it_listens_interactive_login(InteractiveLoginEvent $interactiveLoginEvent, TokenInterface $token, UserInterface $user, Request $request, SessionInterface $session, ParameterBagInterface $parameterBag, ClientManagerInterface $clientManager, ClientInterface $client, OAuth2 $oauthServer, Response $response) { $interactiveLoginEvent->getAuthenticationToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn($user); $interactiveLoginEvent->getRequest()->shouldBeCalled()->willReturn($request); $parameterBag->get('_username')->shouldBeCalled()->willReturn('*****@*****.**'); $parameterBag->get('_password')->shouldBeCalled()->willReturn('123456'); $request->request = $parameterBag; $request->getSession()->shouldBeCalled()->willReturn($session); $session->set('_email', '*****@*****.**')->shouldBeCalled(); $session->set('_password', '123456')->shouldBeCalled(); $clientManager->findClientBy(['secret' => 'client-secret'])->shouldBeCalled()->willReturn($client); $client->getId()->shouldBeCalled()->willReturn('the-id'); $client->getRandomId()->shouldBeCalled()->willReturn('random-id'); $session->get('_email')->shouldBeCalled()->willReturn('*****@*****.**'); $session->get('_password')->shouldBeCalled()->willReturn('123456'); $oauthServer->grantAccessToken(Argument::type('Symfony\\Component\\HttpFoundation\\Request'))->shouldBeCalled()->willReturn($response); $response->getContent()->shouldBeCalled()->willReturn('the response content'); $session->remove('_email')->shouldBeCalled()->willReturn('*****@*****.**'); $session->remove('_password')->shouldBeCalled()->willReturn('123456'); $session->replace(['access_token' => null, 'refresh_token' => null])->shouldBeCalled(); $this->onInteractiveLogin($interactiveLoginEvent); }
/** * Retrieve a value. * * @param string $path The path of the value. * * @return array|null */ public function get($path) { // special case, root element. if ($path === static::PATH_SEPARATOR) { return $this->data; } $chunks = $this->splitPath($path); $scope = $this->data; if (empty($chunks)) { return null; } while (null !== ($sub = array_shift($chunks))) { if (isset($scope[$sub])) { $scope = $scope[$sub]; } else { return null; } } return $this->parameterBag->resolveValue($scope); }
/** * @inheritdoc */ public function hash() { return serialize($this->parameterBag->all()); }
function it_registers_successfully(Request $request, ParameterBagInterface $bag, ContainerInterface $container, UserRepository $repository, UserInterface $user, HandlerInterface $handler, FormInterface $form, EventDispatcherInterface $eventDispatcher, FormEvent $event, UserManager $userManager, TokenStorageInterface $context, TokenInterface $token, RouterInterface $router) { $request->query = $bag; $bag->get('token')->shouldBeCalled()->willReturn(null); $request->getMethod()->shouldBeCalled()->willReturn('POST'); $bag->get('email')->shouldBeCalled()->willReturn('*****@*****.**'); $container->get('kreta_user.repository.user')->shouldBeCalled()->willReturn($repository); $repository->findOneBy(['email' => '*****@*****.**'], false)->shouldBeCalled()->willReturn($user); $container->get('kreta_user.form_handler.registration')->shouldBeCalled()->willReturn($handler); $handler->createForm($user)->shouldBeCalled()->willReturn($form); $form->setData($user)->shouldBeCalled()->willReturn($form); $form->handleRequest($request)->shouldBeCalled()->willReturn($form); $form->isValid()->shouldBeCalled()->willReturn(true); $user->setEnabled(true)->shouldBeCalled()->willReturn($user); $user->setConfirmationToken(null)->shouldBeCalled()->willReturn($user); $container->get('event_dispatcher')->shouldBeCalled()->willReturn($eventDispatcher); $eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, Argument::type('FOS\\UserBundle\\Event\\FormEvent'))->shouldBeCalled()->willReturn($event); $container->get('fos_user.user_manager')->shouldBeCalled()->willReturn($userManager); $userManager->updateUser($user)->shouldBeCalled(); $eventDispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, Argument::type('FOS\\UserBundle\\Event\\FilterUserResponseEvent'))->shouldBeCalled()->willReturn($event); $container->has('security.token_storage')->shouldBeCalled()->willReturn(true); $container->get('security.token_storage')->shouldBeCalled()->willReturn($context); $context->getToken()->shouldBeCalled()->willReturn($token); $token->getUser()->shouldBeCalled()->willReturn($user); $eventDispatcher->dispatch(AuthorizationEvent::NAME, Argument::type('Kreta\\Bundle\\UserBundle\\Event\\AuthorizationEvent'))->shouldBeCalled()->willReturn($event); $container->get('router')->shouldBeCalled()->willReturn($router); $router->generate('kreta_web_homepage', [], false)->shouldBeCalled()->willReturn('http://kreta.io/'); $this->registerAction($request); }
function it_does_not_render_because_invitation_token_does_not_exist(ParameterBagInterface $bag, Request $request, ContainerInterface $container, UserOfInvitationTokenHandler $handler) { $bag->get('invitation-token')->willReturn('invitation-token'); $request->query = $bag; $invitationTokenQuery = new UserOfInvitationTokenQuery('invitation-token'); $container->get('bengor_user.user.by_invitation_token_query')->shouldBeCalled()->willReturn($handler); $handler->__invoke($invitationTokenQuery)->shouldBeCalled()->willThrow(UserDoesNotExistException::class); $this->shouldThrow(NotFoundHttpException::class)->duringByInvitationAction($request, 'user', 'main', SignUpByInvitationType::class); }
function it_does_not_change_password_because_token_does_not_exist(ParameterBagInterface $bag, Request $request, ContainerInterface $container, UserOfRememberPasswordTokenHandler $handler) { $request->query = $bag; $bag->get('remember-password-token')->shouldBeCalled()->willReturn('remember-password-token'); $rememberPasswordTokenQuery = new UserOfRememberPasswordTokenQuery('remember-password-token'); $container->get('bengor_user.user.by_remember_password_token_query')->shouldBeCalled()->willReturn($handler); $handler->__invoke($rememberPasswordTokenQuery)->shouldBeCalled()->willThrow(UserDoesNotExistException::class); $this->shouldThrow(NotFoundHttpException::class)->duringByRequestRememberPasswordAction($request, 'user', 'bengor_user_user_homepage'); }
/** * Gets a parameter. * * @param string $name The parameter name * @param string $default The default value * * @return mixed The parameter value */ public function getParameter($name = null, $default = null) { return $this->parameterBag->has($name) ? $this->parameterBag->get($name) : $default; }
/** * @param string $value * * @return string */ protected function resolveParameter($value) { return $this->parameterBag->resolveValue($value); }
/** * @inheritdoc */ public function __construct(ParameterBagInterface $parameterBag = null) { // This is not elegant, but it works. parent::__construct(new DrupalFrozenParameterBag($parameterBag->all())); $this->services['service_container'] = $this; }
/** * {@inheritDoc} */ public function collect(Request $request, Response $response, \Exception $exception = null) { $this->data['values'] = $this->datalayer->all(); }
/** * @param string $name * * @return bool */ public function hasParameter($name) { return $this->parameterBag->has('mautic.' . $name); }
protected function tearDown() { $this->params->clear(); }
/** * Sets a parameter. * * @param string $name The parameter name * @param mixed $value The parameter value */ public function setParameter($name, $value) { $this->parameterBag->set($name, $value); }
/** * Given an entity parameter definition, returns associated repository. * * This method is only useful when your entities namespaces are defined as * a parameter, very useful when you want to provide a way of overriding * entities easily * * @param string $entityParameter Entity Parameter * * @return ObjectRepository Repository */ public function getRepositoryByEntityParameter($entityParameter) { $entityNamespace = $this->parameterBag->get($entityParameter); return $this->getRepositoryByEntityNamespace($entityNamespace); }