Checks if a parameter exists.
public hasParameter ( string $name ) : boolean | ||
$name | string | The parameter name |
return | boolean | The presence of parameter in container |
/** * Override this method in your own implementation to configure the Cassandra cluster instance. */ protected function initializeCluster() { // contact points can an array or a string, optionally having multiple // comma-separated node host names / IP addresses $contactPoints = $this->container->getParameter('cassandra_cluster.contact_points'); if (!is_array($contactPoints)) { $contactPoints = implode($contactPoints, ','); foreach ($contactPoints as &$contactPoint) { $contactPoint = trim($contactPoint); } } $cluster = \Cassandra::cluster(); if (PHP_VERSION_ID < 50600) { call_user_func_array(array($cluster, "withContactPoints"), $contactPoints); } else { // PHP > 5.6 implements variadic parameters $cluster->withContactPoints(...$contactPoints); } $cluster->withPersistentSessions(true); // always use persistent connections but be explicit about it if ($this->container->hasParameter('cassandra_cluster.credentials.username') && $this->container->hasParameter('cassandra_cluster.credentials.password')) { $username = $this->container->getParameter('cassandra_cluster.credentials.username'); $password = $this->container->getParameter('cassandra_cluster.credentials.password'); $cluster->withCredentials($username, $password); } $this->cluster = $cluster->build(); }
/** * @param string $parameter * * @return mixed */ public static function getParameter($parameter) { if (self::$container->hasParameter($parameter)) { return self::$container->getParameter($parameter); } return false; }
/** * @covers ::knowsDependency * @covers ::__construct */ public function testKnowsDependency() { $this->container->hasParameter('known_dependency')->willReturn(true); $this->container->hasParameter('unknown_dependency')->willReturn(false); $this->assertTrue($this->sut->knowsDependency('known_dependency')); $this->assertFalse($this->sut->knowsDependency('unknown_dependency')); }
/** * @dataProvider parametersProvider * * @param string $node Array key from parametersProvider * @param string $value Array value from parametersProvider */ public function testParameter($node, $value) { $name = 'liip_functional_test.' . $node; $this->assertNotNull($this->container); $this->assertTrue($this->container->hasParameter($name), $name . ' parameter is not defined.'); $this->assertSame($value, $this->container->getParameter($name)); }
/** * @param $type * @param null $parent * @return string * @throws Exception */ public function buildMenu($type, $parent = null) { $templater = $this->container->get('templating'); $templates = $this->container->hasParameter(self::MENUBUNDLE_TEMPLATES) ? $this->container->getParameter(self::MENUBUNDLE_TEMPLATES) : array(); $template = isset($templates[$type]) ? $templates[$type] : self::DEFAULT_TEMPLATE; return $templater->render($template, array('items' => $this->getSource()->getTree($type, $parent), 'type' => $type)); }
public function __invoke(Request $request) { if ($this->container->hasParameter('partkeepr.auth.allow_password_change') && $this->container->getParameter('partkeepr.auth.allow_password_change') === false) { throw new PasswordChangeNotAllowedException(); } $user = $this->userService->getUser(); if (!$request->request->has('oldpassword') && !$request->request->has('newpassword')) { throw new \Exception('old password and new password need to be specified'); } $FOSUser = $this->userManager->findUserByUsername($user->getUsername()); if ($FOSUser !== null) { $encoder = $this->encoderFactory->getEncoder($FOSUser); $encoded_pass = $encoder->encodePassword($request->request->get('oldpassword'), $FOSUser->getSalt()); if ($FOSUser->getPassword() != $encoded_pass) { throw new OldPasswordWrongException(); } $this->userManipulator->changePassword($user->getUsername(), $request->request->get('newpassword')); } else { if ($user->isLegacy()) { if ($user->getPassword() !== md5($request->request->get('oldpassword'))) { throw new OldPasswordWrongException(); } $user->setNewPassword($request->request->get('newpassword')); $this->userService->syncData($user); } else { throw new \Exception('Cannot change password for LDAP users'); } } $user->setPassword(''); $user->setNewPassword(''); return $user; }
public function onKernelRequest(GetResponseEvent $event) { if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { try { $controller = $event->getRequest()->attributes->get('_controller'); if (strstr($controller, '::')) { //Check if its a "real controller" not assetic for example $generatorYaml = $this->getGeneratorYml($controller); $generator = $this->getGenerator($generatorYaml); $generator->setGeneratorYml($generatorYaml); $generator->setBaseGeneratorName($this->getBaseGeneratorName($controller)); $generator->build(); } } catch (NotAdminGeneratedException $e) { //Lets the word running this is not an admin generated module } } if ($this->container->hasParameter('admingenerator.twig')) { $twig_params = $this->container->getParameter('admingenerator.twig'); if (isset($twig_params['date_format'])) { $this->container->get('twig')->getExtension('core')->setDateFormat($twig_params['date_format'], '%d days'); } if (isset($twig_params['number_format'])) { $this->container->get('twig')->getExtension('core')->setNumberFormat($twig_params['number_format']['decimal'], $twig_params['number_format']['decimal_point'], $twig_params['number_format']['thousand_separator']); } } }
/** * * @param ContainerInterface $container * @param array $templateConfigs */ public function __construct(ContainerInterface $container, array $templateConfigs) { $this->container = $container; $this->templateConfigs = $templateConfigs; $this->debugMode = $container->hasParameter('notifications.debug') ? $container->getParameter('notifications.debug') : false; $this->allowedRecipients = $container->hasParameter('notifications.allowed_recipients') ? $container->getParameter('notifications.allowed_recipients') : array(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $currency = new Currency(); $currency->setLabel('EUR'); $basket = new Basket(); $basket->setCurrency($currency); $basket->setProductPool($this->getProductPool()); $products = array($this->getReference('php_plush_blue_goodie_product'), $this->getReference('php_plush_green_goodie_product'), $this->getReference('travel_japan_small_product'), $this->getReference('travel_japan_medium_product'), $this->getReference('travel_japan_large_product'), $this->getReference('travel_japan_extra_large_product'), $this->getReference('travel_quebec_small_product'), $this->getReference('travel_quebec_medium_product'), $this->getReference('travel_quebec_large_product'), $this->getReference('travel_quebec_extra_large_product'), $this->getReference('travel_paris_small_product'), $this->getReference('travel_paris_medium_product'), $this->getReference('travel_paris_large_product'), $this->getReference('travel_paris_extra_large_product'), $this->getReference('travel_switzerland_small_product'), $this->getReference('travel_switzerland_medium_product'), $this->getReference('travel_switzerland_large_product'), $this->getReference('travel_switzerland_extra_large_product')); $nbCustomers = $this->container->hasParameter("sonata.fixtures.customer.fake") ? (int) $this->container->getParameter("sonata.fixtures.customer.fake") : 20; for ($i = 1; $i <= $nbCustomers; $i++) { $customer = $this->generateCustomer($manager, $i); $customerProducts = array(); $orderProductsKeys = array_rand($products, rand(1, count($products))); if (is_array($orderProductsKeys)) { foreach ($orderProductsKeys as $orderProductKey) { $customerProducts[] = $products[$orderProductKey]; } } else { $customerProducts = array($products[$orderProductsKeys]); } $order = $this->createOrder($basket, $customer, $customerProducts, $manager, $i); $this->createTransaction($order, $manager); $this->createInvoice($order, $manager); if (!($i % 10)) { $manager->flush(); } } $manager->flush(); }
/** * {@inheritDoc} */ public function getRoles() { if ($this->container->hasParameter('dms.permission.role_provider')) { $customRoleProvider = $this->container->get($this->container->getParameter('dms.permission.role_provider')); $roles = $customRoleProvider->getRoles(); } else { $roles = $this->container->getParameter('dms.permission.roles'); } return $roles; }
/** * @return CacheProviderDecorator */ private function buildCache(array $tagParameters) { $cache = null; if (isset($tagParameters['cache'])) { $cache = $this->container->get($tagParameters['cache']); } elseif ($this->container->hasParameter('openclassrooms.service_proxy.default_cache')) { $cache = $this->container->get($this->container->getParameter('openclassrooms.service_proxy.default_cache')); } return $cache; }
/** * @param string $bridge * @return bool */ public function isEnabled($bridge) { if (!array_key_exists($bridge, self::$bridges)) { return false; } if (!$this->container->hasParameter('fos_message.bridges.states.' . $bridge)) { return false; } return (bool) $this->container->getParameter('fos_message.bridges.states.' . $bridge); }
public static function configureMigrations(ContainerInterface $container, Configuration $configuration) { if (!$configuration->getMigrationsDirectory()) { $dir = $container->getParameter('doctrine_migrations.dir_name'); if (!file_exists($dir)) { mkdir($dir, 0777, true); } $configuration->setMigrationsDirectory($dir); } else { $dir = $configuration->getMigrationsDirectory(); // class Kernel has method getKernelParameters with some of the important path parameters $pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir'); foreach ($pathPlaceholderArray as $pathPlaceholder) { if ($container->hasParameter($pathPlaceholder) && preg_match('/\\%' . $pathPlaceholder . '\\%/', $dir)) { $dir = str_replace('%' . $pathPlaceholder . '%', $container->getParameter($pathPlaceholder), $dir); } } if (!file_exists($dir)) { mkdir($dir, 0777, true); } $configuration->setMigrationsDirectory($dir); } if (!$configuration->getMigrationsNamespace()) { $configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace')); } if (!$configuration->getName()) { $configuration->setName($container->getParameter('doctrine_migrations.name')); } // For backward compatibility, need use a table from parameters for overwrite the default configuration if (!$configuration->getMigrationsTableName() || !$configuration instanceof AbstractFileConfiguration) { $configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name')); } // Migrations is not register from configuration loader if (!$configuration instanceof AbstractFileConfiguration) { $configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory()); } if ($container->hasParameter('doctrine_migrations.organize_migrations')) { $organizeMigrations = $container->getParameter('doctrine_migrations.organize_migrations'); switch ($organizeMigrations) { case Configuration::VERSIONS_ORGANIZATION_BY_YEAR: $configuration->setMigrationsAreOrganizedByYear(true); break; case Configuration::VERSIONS_ORGANIZATION_BY_YEAR_AND_MONTH: $configuration->setMigrationsAreOrganizedByYearAndMonth(true); break; case false: break; default: throw new InvalidConfigurationException('Unrecognized option "' . $organizeMigrations . '" under "organize_migrations"'); } } self::injectContainerToMigrations($container, $configuration->getMigrations()); }
/** * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) { if ($container->hasParameter('build_commit_tag')) { $tag = $container->getParameter('build_commit_tag'); } if ($container->hasParameter('build_commit_hash')) { $hash = $container->getParameter('build_commit_hash'); } if ($container->hasParameter('build_commit_branch')) { $branch = $container->getParameter('build_commit_branch'); } $this->addRequirement(isset($tag), "Git commit tag", isset($tag) ? $tag : 'NONE', false, [true, false, true]); $this->addRequirement(isset($hash), "Git commit hash", isset($hash) ? $hash : 'NONE', false, [true, false, true]); $this->addRequirement(isset($branch), "Git Branch", isset($branch) ? $branch : 'NONE', false, [true, false, true]); }
public function __get($name) { if (strpos($name, 'setting_') === 0) { $name = str_replace('setting_', '', $name); if (!array_key_exists($name, $this->schema)) { trigger_error(sprintf('Property %s does not exist in dynamic settings.', $name)); } return $this->parametersStorage->get($this->schema[$name]['key']); } elseif (strpos($name, 'default_setting_') === 0) { $name = str_replace('default_setting_', '', $name); if (!array_key_exists($name, $this->schema)) { trigger_error(sprintf('Property %s does not exist in dynamic settings.', $name)); } return $this->schema[$name]['default']; } elseif (strpos($name, 'form_') === 0) { $name = str_replace('form_', '', $name); return $this->formName($name); } elseif (strpos($name, 'real_') === 0) { $value = $this->schema[$this->keyDict[$name]]['default']; if ($this->parametersStorage->has($name)) { $value = $this->parametersStorage->get($name); } return $value; } elseif (array_key_exists($name, $this->keyDict)) { $parameterName = $this->containerInjectionManager->getParametersName($name); if (!$this->container->hasParameter($parameterName)) { throw new \InvalidArgumentException(); } $value = $this->container->getParameter($parameterName); return $value; } trigger_error(sprintf('Property %s does not exist in dynamic settings.', $name)); }
/** * @param \Symfony\Component\DependencyInjection\ContainerInterface $container * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrine * @param \Doctrine\Common\Persistence\ObjectManager $manager * @param \Behat\Behat\Hook\Scope\ScenarioScope $event * @param \Behat\Gherkin\Node\FeatureNode $feature * @param \Behat\Gherkin\Node\ScenarioNode $scenario * @param \Knp\FriendlyContexts\Alice\Loader\Yaml $loader * @param \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory $metadataFactory * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $userMetadata * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $placeMetadata * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $productMetadata */ function let($container, $doctrine, $manager, $event, $loader, $feature, $scenario, $metadataFactory, $userMetadata, $placeMetadata, $productMetadata) { $doctrine->getManager()->willReturn($manager); $feature->getTags()->willReturn(['alice(Place)', 'admin']); $scenario->getTags()->willReturn(['alice(User)']); $event->getFeature()->willReturn($feature); $event->getScenario()->willReturn($scenario); $loader->load('user.yml')->willReturn([]); $loader->load('product.yml')->willReturn([]); $loader->load('place.yml')->willReturn([]); $loader->getCache()->willReturn([]); $loader->clearCache()->willReturn(null); $fixtures = ['User' => 'user.yml', 'Product' => 'product.yml', 'Place' => 'place.yml']; $config = ['alice' => ['fixtures' => $fixtures, 'dependencies' => []]]; $container->has(Argument::any())->willReturn(true); $container->hasParameter(Argument::any())->willReturn(true); $container->get('friendly.alice.loader.yaml')->willReturn($loader); $container->get('doctrine')->willReturn($doctrine); $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures); $container->getParameter('friendly.alice.dependencies')->willReturn([]); $manager->getMetadataFactory()->willReturn($metadataFactory); $metadataFactory->getAllMetadata()->willReturn([$userMetadata, $placeMetadata, $productMetadata]); $userMetadata->getName()->willReturn('User'); $placeMetadata->getName()->willReturn('Place'); $productMetadata->getName()->willReturn('Product'); $this->initialize($config, $container); }
/** * @param $resourceOwnerName * @return \OAuth\Common\Service\ServiceInterface * @throws Exception */ public function createService($resourceOwnerName) { if (!isset(ResourceOwners::$all[$resourceOwnerName])) { throw new Exception('Resource owner ' . $resourceOwnerName . ' is not available'); } if (isset($this->serviceCache[$resourceOwnerName])) { return $this->serviceCache[$resourceOwnerName]; } $lowerResourceOwnerName = $string = strtolower(preg_replace('/(?<=\\w)(?=[A-Z])/', "_\$1", $resourceOwnerName)); $paramName = 'apinnecke_oauth.resource_owners.' . $lowerResourceOwnerName . '.callback_url'; if (!$this->container->hasParameter($paramName) || !($callbackUrl = $this->container->getParameter($paramName)) || null === $callbackUrl) { $callbackUrl = $this->container->get('router')->getContext()->getBaseUrl(); } $credentials = new Credentials($this->container->getParameter('apinnecke_oauth.resource_owners.' . $lowerResourceOwnerName . '.client_id'), $this->container->getParameter('apinnecke_oauth.resource_owners.' . $lowerResourceOwnerName . '.client_secret'), $callbackUrl); return $this->serviceCache[$resourceOwnerName] = $this->factory->createService($resourceOwnerName, $credentials, $this->storage); }
public function sf_param($node) { if ($this->container->hasParameter($node)) { return $this->container->getParameter($node); } return $node; }
public static function getParameter(ContainerInterface $container, $key, $default = null) { if (!$container->hasParameter('rg_user_voice.' . $key)) { return $default; } return $container->getParameter('rg_user_voice.' . $key); }
/** * @param string $name * @param bool $debug * @return string */ private function getClassname($name, $debug) { if ($this->container->hasParameter($name . '_database_classname')) { return $this->container->getParameter($name . '_database_classname'); } return $debug ? 'DebugPDO' : 'PropelPDO'; }
/** * @param string $parameter * * @return mixed */ public function getParameter($parameter) { if ($this->container->hasParameter($parameter)) { return $this->container->getParameter($parameter); } throw new RuntimeException('Parameter "%s" doesn\'t exist in container for "%s".', null, null, $parameter, $this->getName()); }
/** * @param ContainerInterface $container * @param RouterInterface $router * @param Reader $reader * @param DocCommentExtractor $commentExtractor * @param ControllerNameParser $controllerNameParser * @param array $handlers * @param array $annotationsProviders * @param TransformerHelper $transformerHelper * @param Normalizer $normailzer * @param ResourceCollection $resourceCollection * @param EntityManager $entityManager * @param FormRegistryInterface $registry */ public function __construct(ContainerInterface $container, RouterInterface $router, Reader $reader, DocCommentExtractor $commentExtractor, ControllerNameParser $controllerNameParser, array $handlers, array $annotationsProviders, TransformerHelper $transformerHelper, Normalizer $normailzer, ResourceCollection $resourceCollection, EntityManager $entityManager, FormRegistryInterface $registry) { $this->container = $container; $this->router = $router; $this->commentExtractor = $commentExtractor; $this->reader = $reader; $this->handlers = $handlers; $this->transformerHelper = $transformerHelper; $this->resourceCollection = $resourceCollection; $this->normailzer = $normailzer; $this->classMetadataFactory = $this->container->get('api.mapping.class_metadata_factory'); $nelmioDocStandard = $this->container->hasParameter('nelmio.extractor.standard.api.version'); if ($nelmioDocStandard) { $this->nelmioDocStandardVersion = $this->container->getParameter('nelmio.extractor.standard.api.version'); } $this->transformerHelper->setClassMetadataFactory($this->classMetadataFactory); $this->annotationsProviders = $annotationsProviders; $this->setVersionApiDoc(); if (in_array(strtolower($this->versionApi), $this->nelmioDocStandardVersion)) { $annotationsProviders = []; } parent::__construct($container, $router, $reader, $commentExtractor, $controllerNameParser, $handlers, $annotationsProviders); $this->registry = $registry; $this->controllerNameParser = $controllerNameParser; $this->entityManager = $entityManager; }
/** * * {{dump( cjw_config_get_parameter( 'mailer_transport' ) ) }} * * Gets a parameter. * * @param string $name The parameter name * * @return mixed The parameter value * * @throws InvalidArgumentException if the parameter is not defined * * @api */ public function configGetParameter($paramName) { if ($this->container->hasParameter($paramName)) { return $this->container->getParameter($paramName); } else { return null; } }
/** * Retrieves a Mautic parameter * * @param $id * @param mixed $default * * @return bool|mixed */ public function getParameter($id, $default = false) { if ($id == 'db_table_prefix' && defined('MAUTIC_TABLE_PREFIX')) { //use the constant in case in the installer return MAUTIC_TABLE_PREFIX; } return $this->container->hasParameter('mautic.' . $id) ? $this->container->getParameter('mautic.' . $id) : $default; }
/** * LocaleExtension constructor * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) { $this->container = $container; if (!$container->hasParameter(self::INDEX_PARAMETER_CLASS_LOCALE)) { throw new \Exception('Parameter not configured!'); } $this->repository = $container->getParameter(self::INDEX_PARAMETER_CLASS_LOCALE); }
/** * Returns the service instance given in param. * * @param string $name The parameter name * * @return string * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function getParameterFunction($name) { if ($this->container->hasParameter($name)) { return $this->container->getParameter($name); } else { throw new \InvalidArgumentException("The parameter given in param isn't register !"); } }
/** * Register commands into the application * * @return void */ protected function registerCommands() { if ($this->container->hasParameter('app.command.ids')) { foreach ($this->container->getParameter('app.command.ids') as $id) { $this->add($this->container->get($id)); } } }
public function __construct(ContainerInterface $container) { if (!$container->hasParameter('maxmind_geoip_data_file_path')) { throw new \InvalidArgumentException("It seems, the MaxmindGeoIP-Bundle is not installed. The parameter 'maxmind_geoip_data_file_path' is not defined."); } $filePath = $container->getParameter('maxmind_geoip_data_file_path'); $this->geoip = new GeoIp($filePath); }
public function __construct(Container $container) { $this->container = $container; if ($container->hasParameter('stacksight.token')) { $token = $container->getParameter('stacksight.token'); if (!defined('STACKSIGHT_TOKEN') && $token) { define('STACKSIGHT_TOKEN', $token); } } else { return; // We can notice that need set stacksight token } if ($container->hasParameter('stacksight.app_id')) { $app_id = $container->getParameter('stacksight.app_id'); if (!defined('STACKSIGHT_APP_ID') && $app_id) { define('STACKSIGHT_APP_ID', $app_id); } } if ($container->hasParameter('stacksight.group')) { $group = $container->getParameter('stacksight.group'); if (!defined('STACKSIGHT_GROUP') && $group) { define('STACKSIGHT_GROUP', $group); } } if ($container->hasParameter('stacksight.logs')) { $include_logs = $container->getParameter('stacksight.logs'); if (!defined('STACKSIGHT_INCLUDE_LOGS') && $include_logs) { define('STACKSIGHT_INCLUDE_LOGS', $include_logs); } } if ($container->hasParameter('stacksight.debug')) { $debug = $container->getParameter('stacksight.debug'); if (!defined('STACKSIGHT_DEBUG') && $debug) { define('STACKSIGHT_DEBUG', (bool) $debug); } } global $ss_client; if (!$ss_client) { require_once 'src/sdk/bootstrap-symfony-2.php'; $stacksight = new \SymfonyBootstrap(); $this->_ss_client = $stacksight->getClient(); } else { $this->_ss_client = $ss_client; } }
/** * @param string $name * @param string $value */ public function setMetaTag($name, $value) { if (empty($name) || empty($value)) { throw new \InvalidArgumentException(__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } $metaTags = $this->container->hasParameter('zikula_view.metatags') ? $this->container->getParameter('zikula_view.metatags') : array(); $metaTags[$name] = \DataUtil::formatForDisplay($value); $this->container->setParameter('zikula_view.metatags', $metaTags); }