本文整理匯總了PHP中Symfony\Component\DependencyInjection\ContainerInterface::hasParameter方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContainerInterface::hasParameter方法的具體用法?PHP ContainerInterface::hasParameter怎麽用?PHP ContainerInterface::hasParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\DependencyInjection\ContainerInterface
的用法示例。
在下文中一共展示了ContainerInterface::hasParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: initializeCluster
/**
* 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();
}
示例2: getParameter
/**
* @param string $parameter
*
* @return mixed
*/
public static function getParameter($parameter)
{
if (self::$container->hasParameter($parameter)) {
return self::$container->getParameter($parameter);
}
return false;
}
示例3: testKnowsDependency
/**
* @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'));
}
開發者ID:bartfeenstra,項目名稱:dependency-retriever-symfony-bridge,代碼行數:11,代碼來源:ContainerParameterRetrieverTest.php
示例4: testParameter
/**
* @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));
}
示例5: buildMenu
/**
* @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));
}
示例6: __invoke
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;
}
示例7: onKernelRequest
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']);
}
}
}
示例8: __construct
/**
*
* @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();
}
示例9: load
/**
* {@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();
}
示例10: getRoles
/**
* {@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;
}
示例11: buildCache
/**
* @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;
}
示例12: isEnabled
/**
* @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);
}
示例13: configureMigrations
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());
}
示例14: __construct
/**
* @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]);
}
示例15: __get
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));
}