/** * {@inheritdoc} */ public function get($name) { try { return parent::get($name); } catch (ParameterNotFoundException $e) { // In drupal, non existing parameters are allowed. return null; } }
/** * {@inheritdoc} */ public function filterDump(AssetInterface $asset) { if (preg_match('/\\.yfp\\.js$/', $asset->getSourcePath())) { $content = $asset->getContent(); preg_match('/(\\w+)\\.yfp\\.js$/', $asset->getSourcePath(), $matches); if (isset($matches[1])) { $name = $matches[1]; $pluginName = str_replace(' ', '', ucwords(strtr($matches[1], '_-', ' '))); $config = []; if ($this->parameterBag->has("ynlo.js_plugin.{$name}")) { $config = $this->parameterBag->get("ynlo.js_plugin.{$name}"); } $jsonConfig = json_encode($config, JSON_FORCE_OBJECT); $autoRegister = null; if (strpos($content, "YnloFramework.register('{$pluginName}')") === false && strpos($content, "YnloFramework.register(\"{$pluginName}\\')") === false) { $autoRegister = "\nYnloFramework.register('{$pluginName}');"; } $settings = <<<JAVASCRIPT {$autoRegister} YnloFramework.{$pluginName}.config = \$.extend({}, YnloFramework.{$pluginName}.config, {$jsonConfig}); JAVASCRIPT; $asset->setContent($content . $settings); } } }
/** * @param UserEvent $event * @throws \Exception * @throws \Twig_Error */ public function onResettingRequestSuccess(UserEvent $event) { $user = $event->getUser(); $params = $event->getParams(); $url = $this->router->generate($params[$event::PARAM_RESETTING_EMAIL_ROUTE], array('token' => $user->getConfirmationToken()), true); $message = \Swift_Message::newInstance()->setSubject($this->translator->trans('security.resetting.request.email.subject'))->setFrom($this->parameter->get($params[$event::PARAM_RESETTING_EMAIL_FROM]))->setTo($user->getEmail())->setBody($this->twigEngine->render($params[$event::PARAM_RESETTING_EMAIL_TEMPLATE], array('complete_name' => $event->getSecureArea()->getCompleteName(), 'url' => $url))); $this->mailer->send($message); $this->flashBag->add(FlashBagEvents::MESSAGE_TYPE_SUCCESS, $this->translator->trans('security.resetting.request.check_email', array('user_email' => $user->getObfuscatedEmail()))); }
/** * @test * @dataProvider provideConfigs */ public function setLegacyPath(array $config, $path, $prepend = null, $append = null) { $bag = new ParameterBag(); $extension = new BassterLegacyBridgeExtension(); $extension->load($config, new ContainerBuilder($bag)); self::assertEquals($path, $bag->get('basster_legacy_bridge.legacy_path')); self::assertEquals($prepend, $bag->get('basster_legacy_bridge.prepend_script')); self::assertEquals($append, $bag->get('basster_legacy_bridge.append_script')); }
/** * @param ParameterBag $bag * * @return Client * @throws \Exception */ public function create($bag) { $client = new Client(); $client->setMsisdn($bag->get(self::PARAM_MSISDN)); $client->setCountry($bag->get(self::PARAM_COUNTRY)); $client->setClientDirection($bag->get(self::PARAM_DIRECTION)); $this->enManager->persist($client); $this->enManager->flush(); return $client; }
/** * {@inheritdoc} */ public function get($name) { if (0 === strpos($name, 'env(') && ')' === substr($name, -1) && 'env()' !== $name) { $env = substr($name, 4, -1); if (isset($this->envPlaceholders[$env])) { foreach ($this->envPlaceholders[$env] as $placeholder) { return $placeholder; // return first result } } if (preg_match('/\\W/', $env)) { throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); } if ($this->has($name)) { $defaultValue = parent::get($name); if (null !== $defaultValue && !is_scalar($defaultValue)) { throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar or null, but "%s" given to "%s".', gettype($defaultValue), $name)); } } $uniqueName = md5($name . uniqid(mt_rand(), true)); $placeholder = sprintf('env_%s_%s', $env, $uniqueName); $this->envPlaceholders[$env][$placeholder] = $placeholder; return $placeholder; } return parent::get($name); }
function it_casts_variable_string_in_string($request, ParameterBag $attributes) { $request->attributes = $attributes; $attributes->get('_route_params')->willReturn(['foo' => 18098, 'bar' => true, 'xyz' => 'value']); $this->cast('$foo')->shouldReturn(18098); $this->cast('$bar')->shouldReturn(true); $this->cast('$xyz')->shouldReturn('value'); $this->cast('$test')->shouldReturn('$test'); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\HttpFoundation\Session\Session $session * @param \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag $requestQuery */ function it_redirects_to_passed_redirect_uri($request, $session, $requestQuery) { $request->getSession()->willReturn($session); $request->query = $requestQuery; $requestQuery->has('redirect_uri')->willReturn(true); $requestQuery->get('redirect_uri')->willReturn('uri_to_redirect_to'); $response = $this->localeAction('qw', $request); $response->getTargetUrl()->shouldReturn('uri_to_redirect_to'); }
/** * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::get * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::set */ public function testGetSet() { $bag = new ParameterBag(array('foo' => 'bar')); $bag->set('bar', 'foo'); $this->assertEquals('foo', $bag->get('bar'), '->set() sets the value of a new parameter'); $bag->set('foo', 'baz'); $this->assertEquals('baz', $bag->get('foo'), '->set() overrides previously set parameter'); $bag->set('Foo', 'baz1'); $this->assertEquals('baz1', $bag->get('foo'), '->set() converts the key to lowercase'); $this->assertEquals('baz1', $bag->get('FOO'), '->get() converts the key to lowercase'); try { $bag->get('baba'); $this->fail('->get() throws an \\InvalidArgumentException if the key does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('\\InvalidArgumentException', $e, '->get() throws an \\InvalidArgumentException if the key does not exist'); $this->assertEquals('The parameter "baba" must be defined.', $e->getMessage(), '->get() throws an \\InvalidArgumentException if the key does not exist'); } }
/** * @param ParameterBag $bag * * @return Order */ public function create($bag) { $entity = new Order(); $entity->setApplication($bag->get(self::PARAM_APP)); $entity->setClient($this->getClient($bag)); $this->enManager->persist($entity); $this->enManager->flush(); $this->eventDispatcher->dispatch(SingUpEvents::CREATE_ORDER, new OrderCreateEvent($entity)); return $entity; }
/** * {@inheritDoc} */ public function get($name) { if (isset($GLOBALS['conf']) && array_key_exists($name, $GLOBALS['conf'])) { return $GLOBALS['conf'][$name]; } if (parent::has($name)) { return parent::get($name); } // This should be logged, somehow // trigger_error(sprintf("%s: container parameter or drupal variable is undefined", $name), E_USER_DEPRECATED); return null; }
/** * Creates a user-presentable string describing the given exception. * * @param $exception \Exception The exception to describe */ protected function exceptionToString(\Exception $exception) { if ($exception instanceof \PHPUnit_Framework_Exception) { // PHPUnit assertion exceptions do not include expected / observed info in their // messages, but expect the test listeners to format that info like the following // (see e.g. PHPUnit_TextUI_ResultPrinter::printDefectTrace) return trim(\PHPUnit_Framework_TestFailure::exceptionToString($exception)); } if ($this->parameters->get('verbose')) { return trim($exception); } return trim($exception->getMessage()); }
/** * Attempt to get an attribute from the assertion. * * @param string $name * @param null $default * @return mixed|null */ public function getAttribute($name, $default = null) { $attributeDefinition = $this->attributeDictionary->getAttributeDefinition($name); // try first by urn:mace, then by urn:oid if ($this->assertionAttributes->has($attributeDefinition->getUrnMace())) { $attribute = $this->assertionAttributes->get($attributeDefinition->getUrnMace()); } elseif ($this->assertionAttributes->has($attributeDefinition->getUrnOid())) { $attribute = $this->assertionAttributes->get($attributeDefinition->getUrnOid()); } else { return $default; } // if it is singular, it should return the single value if it has a value if ($attributeDefinition->getMultiplicity() === AttributeDefinition::MULTIPLICITY_SINGLE) { $count = count($attribute); if ($count > 1) { throw new UnexpectedValueException(sprintf('AttributeDefinition "%s" has a single-value multiplicity, yet returned' . ' "%d" values', $attributeDefinition->getName(), count($attribute))); } elseif ($count === 0) { $attribute = null; } else { $attribute = reset($attribute); } } return $attribute; }
/** * {@inheritdoc} */ public function get($name) { if (0 === strpos($name, 'env(') && ')' === substr($name, -1) && 'env()' !== $name) { $env = substr($name, 4, -1); if (isset($this->envPlaceholders[$env])) { return $this->envPlaceholders[$env][0]; } if (preg_match('/\\W/', $env)) { throw new InvalidArgumentException(sprintf('Invalid %s name: only "word" characters are allowed.', $name)); } if ($this->has($name)) { $defaultValue = parent::get($name); if (!is_scalar($defaultValue)) { throw new RuntimeException(sprintf('The default value of an env() parameter must be scalar, but "%s" given to "%s".', gettype($defaultValue), $name)); } } return $this->envPlaceholders[$env][] = sprintf('env_%s_%s', $env, md5($name . uniqid(mt_rand(), true))); } return parent::get($name); }
/** * @param string $parameterId * @return mixed */ protected function getParameter(string $parameterId) { return $this->parameterBag->get($parameterId); }
/** * Return the parameter value. * * @param string $name * @return mixed */ public function getParameter($name) { return $this->parameters->get($name); }
public function getParameter($name, $default = null) { return $this->parameters->has($name) ? $this->parameters->get($name) : $default; }
public function get($key) { return $this->config->get($key); }
/** * Given an entity parameter definition, returns associated object Manager * * 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 ObjectManager|null Object manager */ public function getManagerByEntityParameter($entityParameter) { $entityNamespace = $this->parameterBag->get($entityParameter); return $this->getManagerByEntityNamespace($entityNamespace); }
/** * @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve */ public function testResolveUnescapesValue() { $bag = new ParameterBag(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')), 'bar' => 'I\'m a %%foo%%')); $bag->resolve(); $this->assertEquals('I\'m a %foo%', $bag->get('bar'), '->resolveValue() supports % escaping by doubling it'); $this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it'); }
/** * Translates numbered message to output language. * * @param string $message message specification to translate * @param string $number choice number * @param array $parameters message parameters * * @return string */ protected final function translateChoice($message, $number, array $parameters = array()) { return $this->translator->transChoice($message, $number, $parameters, 'behat', $this->parameters->get('language')); }
public function testEscapeValue() { $bag = new ParameterBag(); $bag->add(array('foo' => $bag->escapeValue(array('bar' => array('ding' => 'I\'m a bar %foo %bar', 'zero' => null))), 'bar' => $bag->escapeValue('I\'m a %foo%'))); $this->assertEquals('I\'m a %%foo%%', $bag->get('bar'), '->escapeValue() escapes % by doubling it'); $this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %%foo %%bar', 'zero' => null)), $bag->get('foo'), '->escapeValue() escapes % by doubling it'); }