Merge branch '3.4'

* 3.4:
  [Console] Add protected static $defaultName to set the default name of a Command
  removed sf2 references
  [Console] Allow commands to provide a default name for compile time registration
  [DI] Case sensitive parameter names
This commit is contained in:
Nicolas Grekas 2017-08-25 12:57:40 +02:00
commit 3a9653df72
59 changed files with 424 additions and 105 deletions

View File

@ -26,6 +26,8 @@ use Twig\Environment;
*/
class DebugCommand extends Command
{
protected static $defaultName = 'debug:twig';
private $twig;
public function __construct(Environment $twig)
@ -38,7 +40,6 @@ class DebugCommand extends Command
protected function configure()
{
$this
->setName('debug:twig')
->setDefinition(array(
new InputArgument('filter', InputArgument::OPTIONAL, 'Show details for all entries matching this filter'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (text or json)', 'text'),

View File

@ -31,6 +31,8 @@ use Twig\Source;
*/
class LintCommand extends Command
{
protected static $defaultName = 'lint:twig';
private $twig;
public function __construct(Environment $twig)
@ -43,7 +45,6 @@ class LintCommand extends Command
protected function configure()
{
$this
->setName('lint:twig')
->setDescription('Lints a template and outputs encountered errors')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
->addArgument('filename', InputArgument::IS_ARRAY)

View File

@ -39,7 +39,8 @@
"symfony/web-link": "~3.4|~4.0"
},
"conflict": {
"symfony/form": "<3.4"
"symfony/form": "<3.4",
"symfony/console": "<3.4"
},
"suggest": {
"symfony/finder": "",

View File

@ -29,15 +29,14 @@ use Symfony\Component\HttpKernel\KernelInterface;
*/
class AboutCommand extends Command
{
protected static $defaultName = 'about';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('about')
->setDescription('Displays information about the current project')
;
$this->setDescription('Displays information about the current project');
}
/**

View File

@ -36,6 +36,8 @@ class AssetsInstallCommand extends Command
const METHOD_ABSOLUTE_SYMLINK = 'absolute symlink';
const METHOD_RELATIVE_SYMLINK = 'relative symlink';
protected static $defaultName = 'assets:install';
private $filesystem;
public function __construct(Filesystem $filesystem)
@ -51,7 +53,6 @@ class AssetsInstallCommand extends Command
protected function configure()
{
$this
->setName('assets:install')
->setDefinition(array(
new InputArgument('target', InputArgument::OPTIONAL, 'The target directory', 'public'),
))

View File

@ -32,6 +32,8 @@ use Symfony\Component\Finder\Finder;
*/
class CacheClearCommand extends Command
{
protected static $defaultName = 'cache:clear';
private $cacheClearer;
private $filesystem;
@ -53,7 +55,6 @@ class CacheClearCommand extends Command
protected function configure()
{
$this
->setName('cache:clear')
->setDefinition(array(
new InputOption('no-warmup', '', InputOption::VALUE_NONE, 'Do not warm up the cache'),
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),

View File

@ -26,6 +26,8 @@ use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
*/
final class CachePoolClearCommand extends Command
{
protected static $defaultName = 'cache:pool:clear';
private $poolClearer;
public function __construct(Psr6CacheClearer $poolClearer)
@ -41,7 +43,6 @@ final class CachePoolClearCommand extends Command
protected function configure()
{
$this
->setName('cache:pool:clear')
->setDefinition(array(
new InputArgument('pools', InputArgument::IS_ARRAY | InputArgument::REQUIRED, 'A list of cache pools or cache pool clearers'),
))

View File

@ -24,6 +24,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
final class CachePoolPruneCommand extends Command
{
protected static $defaultName = 'cache:pool:prune';
private $pools;
/**
@ -42,7 +44,6 @@ final class CachePoolPruneCommand extends Command
protected function configure()
{
$this
->setName('cache:pool:prune')
->setDescription('Prune cache pools')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command deletes all expired items from all pruneable pools.

View File

@ -27,6 +27,8 @@ use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate;
*/
class CacheWarmupCommand extends Command
{
protected static $defaultName = 'cache:warmup';
private $cacheWarmer;
public function __construct(CacheWarmerAggregate $cacheWarmer)
@ -42,7 +44,6 @@ class CacheWarmupCommand extends Command
protected function configure()
{
$this
->setName('cache:warmup')
->setDefinition(array(
new InputOption('no-optional-warmers', '', InputOption::VALUE_NONE, 'Skip optional cache warmers (faster)'),
))

View File

@ -28,13 +28,14 @@ use Symfony\Component\Yaml\Yaml;
*/
class ConfigDebugCommand extends AbstractConfigCommand
{
protected static $defaultName = 'debug:config';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('debug:config')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),

View File

@ -30,13 +30,14 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
class ConfigDumpReferenceCommand extends AbstractConfigCommand
{
protected static $defaultName = 'config:dump-reference';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('config:dump-reference')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),

View File

@ -33,6 +33,8 @@ use Symfony\Component\Config\FileLocator;
*/
class ContainerDebugCommand extends Command
{
protected static $defaultName = 'debug:container';
/**
* @var ContainerBuilder|null
*/
@ -44,7 +46,6 @@ class ContainerDebugCommand extends Command
protected function configure()
{
$this
->setName('debug:container')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'),
new InputOption('show-private', null, InputOption::VALUE_NONE, 'Used to show public *and* private services'),

View File

@ -29,6 +29,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
*/
class EventDispatcherDebugCommand extends Command
{
protected static $defaultName = 'debug:event-dispatcher';
private $dispatcher;
public function __construct(EventDispatcherInterface $dispatcher)
@ -44,7 +45,6 @@ class EventDispatcherDebugCommand extends Command
protected function configure()
{
$this
->setName('debug:event-dispatcher')
->setDefinition(array(
new InputArgument('event', InputArgument::OPTIONAL, 'An event name'),
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),

View File

@ -33,6 +33,7 @@ use Symfony\Component\Routing\Route;
*/
class RouterDebugCommand extends Command
{
protected static $defaultName = 'debug:router';
private $router;
public function __construct(RouterInterface $router)
@ -48,7 +49,6 @@ class RouterDebugCommand extends Command
protected function configure()
{
$this
->setName('debug:router')
->setDefinition(array(
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),

View File

@ -30,6 +30,8 @@ use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
*/
class RouterMatchCommand extends Command
{
protected static $defaultName = 'router:match';
private $router;
public function __construct(RouterInterface $router)
@ -45,7 +47,6 @@ class RouterMatchCommand extends Command
protected function configure()
{
$this
->setName('router:match')
->setDefinition(array(
new InputArgument('path_info', InputArgument::REQUIRED, 'A path info'),
new InputOption('method', null, InputOption::VALUE_REQUIRED, 'Sets the HTTP method'),

View File

@ -41,6 +41,8 @@ class TranslationDebugCommand extends Command
const MESSAGE_UNUSED = 1;
const MESSAGE_EQUALS_FALLBACK = 2;
protected static $defaultName = 'debug:translation';
private $translator;
private $loader;
private $extractor;
@ -60,7 +62,6 @@ class TranslationDebugCommand extends Command
protected function configure()
{
$this
->setName('debug:translation')
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),

View File

@ -34,6 +34,8 @@ use Symfony\Component\Translation\Writer\TranslationWriterInterface;
*/
class TranslationUpdateCommand extends Command
{
protected static $defaultName = 'translation:update';
private $writer;
private $loader;
private $extractor;
@ -61,7 +63,6 @@ class TranslationUpdateCommand extends Command
protected function configure()
{
$this
->setName('translation:update')
->setDefinition(array(
new InputArgument('locale', InputArgument::REQUIRED, 'The locale'),
new InputArgument('bundle', InputArgument::OPTIONAL, 'The bundle name or directory where to load the messages, defaults to app/Resources folder'),

View File

@ -26,13 +26,14 @@ use Symfony\Component\Workflow\Marking;
*/
class WorkflowDumpCommand extends Command
{
protected static $defaultName = 'workflow:dump';
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('workflow:dump')
->setDefinition(array(
new InputArgument('name', InputArgument::REQUIRED, 'A workflow name'),
new InputArgument('marking', InputArgument::IS_ARRAY, 'A marking (a list of places)'),

View File

@ -24,6 +24,8 @@ use Symfony\Component\Translation\Command\XliffLintCommand as BaseLintCommand;
*/
class XliffLintCommand extends BaseLintCommand
{
protected static $defaultName = 'lint:xliff';
public function __construct()
{
$directoryIteratorProvider = function ($directory, $default) {

View File

@ -23,6 +23,8 @@ use Symfony\Component\Yaml\Command\LintCommand as BaseLintCommand;
*/
class YamlLintCommand extends BaseLintCommand
{
protected static $defaultName = 'lint:yaml';
public function __construct()
{
$directoryIteratorProvider = function ($directory, $default) {

View File

@ -27,6 +27,8 @@ use Doctrine\DBAL\Schema\SchemaException;
*/
class InitAclCommand extends Command
{
protected static $defaultName = 'init:acl';
private $connection;
private $schema;
@ -44,7 +46,6 @@ class InitAclCommand extends Command
protected function configure()
{
$this
->setName('init:acl')
->setDescription('Mounts ACL tables in the database')
->setHelp(<<<'EOF'
The <info>%command.name%</info> command mounts ACL tables in the database.

View File

@ -32,6 +32,8 @@ use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface;
*/
class SetAclCommand extends Command
{
protected static $defaultName = 'acl:set';
private $provider;
public function __construct(MutableAclProviderInterface $provider)
@ -47,7 +49,6 @@ class SetAclCommand extends Command
protected function configure()
{
$this
->setName('acl:set')
->setDescription('Sets ACL for objects')
->setHelp(<<<EOF
The <info>%command.name%</info> command sets ACL.

View File

@ -31,6 +31,8 @@ use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
*/
class UserPasswordEncoderCommand extends Command
{
protected static $defaultName = 'security:encode-password';
private $encoderFactory;
private $userClasses;
@ -48,7 +50,6 @@ class UserPasswordEncoderCommand extends Command
protected function configure()
{
$this
->setName('security:encode-password')
->setDescription('Encodes a password.')
->addArgument('password', InputArgument::OPTIONAL, 'The plain password to encode.')
->addArgument('user-class', InputArgument::OPTIONAL, 'The User entity class path associated with the encoder used to encode the password.')

View File

@ -20,7 +20,6 @@ namespace Symfony\Bundle\SecurityBundle\Tests\Functional;
* file that was distributed with this source code.
*/
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\SecurityBundle\Command\InitAclCommand;
use Symfony\Bundle\SecurityBundle\Command\SetAclCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
@ -170,7 +169,6 @@ class SetAclCommandTest extends WebTestCase
$kernel->boot();
$application = new Application($kernel);
$application->add(new InitAclCommand($kernel->getContainer()->get('security.acl.dbal.connection'), $kernel->getContainer()->get('security.acl.dbal.schema')));
$initAclCommand = $application->find('init:acl');
$initAclCommandTester = new CommandTester($initAclCommand);

View File

@ -46,7 +46,8 @@
},
"conflict": {
"symfony/var-dumper": "<3.4",
"symfony/event-dispatcher": "<3.4"
"symfony/event-dispatcher": "<3.4",
"symfony/console": "<3.4"
},
"suggest": {
"symfony/security-acl": "For using the ACL functionality of this bundle"

View File

@ -24,7 +24,7 @@
var noop = function() {};
var profilerStorageKey = 'sf2/profiler/';
var profilerStorageKey = 'symfony/profiler/';
var request = function(url, onSuccess, onError, payload, options) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

View File

@ -24,7 +24,7 @@
var noop = function() {};
var profilerStorageKey = 'sf2/profiler/';
var profilerStorageKey = 'symfony/profiler/';
var request = function(url, onSuccess, onError, payload, options) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

View File

@ -17,6 +17,10 @@ CHANGELOG
* added `CommandLoaderInterface`, `FactoryCommandLoader` and PSR-11
`ContainerCommandLoader` for commands lazy-loading
* added a case-insensitive command name matching fallback
* added static `Command::$defaultName/getDefaultName()`, allowing for
commands to be registered at compile time in the application command loader.
Setting the `$defaultName` property avoids the need for filling the `command`
attribute on the `console.command` tag when using `AddConsoleCommandPass`.
3.3.0
-----

View File

@ -29,6 +29,11 @@ use Symfony\Component\Console\Exception\LogicException;
*/
class Command
{
/**
* @var string|null The default command name
*/
protected static $defaultName;
private $application;
private $name;
private $processTitle;
@ -45,6 +50,17 @@ class Command
private $usages = array();
private $helperSet;
/**
* @return string|null The default command name or null when no default name is set
*/
public static function getDefaultName()
{
$class = get_called_class();
$r = new \ReflectionProperty($class, 'defaultName');
return $class === $r->class ? static::$defaultName : null;
}
/**
* Constructor.
*
@ -56,7 +72,7 @@ class Command
{
$this->definition = new InputDefinition();
if (null !== $name) {
if (null !== $name || null !== $name = static::getDefaultName()) {
$this->setName($name);
}

View File

@ -46,16 +46,21 @@ class AddConsoleCommandPass implements CompilerPassInterface
$definition = $container->getDefinition($id);
$class = $container->getParameterBag()->resolveValue($definition->getClass());
if (!$r = $container->getReflectionClass($class)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}
if (!$r->isSubclassOf(Command::class)) {
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
}
$commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
if (!isset($tags[0]['command'])) {
if (isset($tags[0]['command'])) {
$commandName = $tags[0]['command'];
} else {
if (!$r = $container->getReflectionClass($class)) {
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
}
if (!$r->isSubclassOf(Command::class)) {
throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
}
$commandName = $class::getDefaultName();
}
if (null === $commandName) {
if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
$commandId = $commandId.'_'.$id;
}
@ -69,7 +74,6 @@ class AddConsoleCommandPass implements CompilerPassInterface
}
$serviceIds[$commandId] = false;
$commandName = $tags[0]['command'];
unset($tags[0]);
$lazyCommandMap[$commandName] = $id;
$lazyCommandRefs[$id] = new TypedReference($id, $class);

View File

@ -77,6 +77,38 @@ class AddConsoleCommandPassTest extends TestCase
$this->assertSame(array(array('setName', array('my:command')), array('setAliases', array(array('my:alias')))), $command->getMethodCalls());
}
public function testProcessFallsBackToDefaultName()
{
$container = new ContainerBuilder();
$container
->register('with-default-name', NamedCommand::class)
->setPublic(false)
->addTag('console.command')
;
$pass = new AddConsoleCommandPass();
$pass->process($container);
$commandLoader = $container->getDefinition('console.command_loader');
$commandLocator = $container->getDefinition((string) $commandLoader->getArgument(0));
$this->assertSame(ContainerCommandLoader::class, $commandLoader->getClass());
$this->assertSame(array('default' => 'with-default-name'), $commandLoader->getArgument(1));
$this->assertEquals(array(array('with-default-name' => new ServiceClosureArgument(new TypedReference('with-default-name', NamedCommand::class)))), $commandLocator->getArguments());
$this->assertSame(array('console.command.symfony_component_console_tests_dependencyinjection_namedcommand' => false), $container->getParameter('console.command.ids'));
$container = new ContainerBuilder();
$container
->register('with-default-name', NamedCommand::class)
->setPublic(false)
->addTag('console.command', array('command' => 'new-name'))
;
$pass->process($container);
$this->assertSame(array('new-name' => 'with-default-name'), $container->getDefinition('console.command_loader')->getArgument(1));
}
public function visibilityProvider()
{
return array(
@ -96,7 +128,7 @@ class AddConsoleCommandPassTest extends TestCase
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('Symfony\Component\Console\Tests\DependencyInjection\MyCommand');
$definition->addTag('console.command', array('command' => 'my:command'));
$definition->addTag('console.command');
$definition->setAbstract(true);
$container->setDefinition('my-command', $definition);
@ -114,7 +146,7 @@ class AddConsoleCommandPassTest extends TestCase
$container->addCompilerPass(new AddConsoleCommandPass());
$definition = new Definition('SplObjectStorage');
$definition->addTag('console.command', array('command' => 'my:command'));
$definition->addTag('console.command');
$container->setDefinition('my-command', $definition);
$container->compile();
@ -146,3 +178,8 @@ class AddConsoleCommandPassTest extends TestCase
class MyCommand extends Command
{
}
class NamedCommand extends Command
{
protected static $defaultName = 'default';
}

View File

@ -28,6 +28,7 @@ CHANGELOG
* deprecated service auto-registration while autowiring
* deprecated the ability to check for the initialization of a private service with the `Container::initialized()` method
* deprecated support for top-level anonymous services in XML
* deprecated case insensitivity of parameter names
3.3.0
-----

View File

@ -1039,11 +1039,15 @@ EOF;
$php = array();
$dynamicPhp = array();
$normalizedParams = array();
foreach ($this->container->getParameterBag()->all() as $key => $value) {
if ($key !== $resolvedKey = $this->container->resolveEnvPlaceholders($key)) {
throw new InvalidArgumentException(sprintf('Parameter name cannot use env parameters: %s.', $resolvedKey));
}
if ($key !== $lcKey = strtolower($key)) {
$normalizedParams[] = sprintf(' %s => %s,', $this->export($lcKey), $this->export($key));
}
$export = $this->exportParameters(array($value));
$export = explode('0 => ', substr(rtrim($export, " )\n"), 7, -1), 2);
@ -1063,7 +1067,7 @@ EOF;
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -1081,7 +1085,7 @@ EOF;
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -1151,6 +1155,30 @@ EOF;
{$getDynamicParameter}
}
EOF;
$code .= ' private $normalizedParameterNames = '.($normalizedParams ? sprintf("array(\n%s\n );", implode("\n", $normalizedParams)) : 'array();')."\n";
$code .= <<<'EOF'
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
EOF;
$code .= <<<EOF
/*{$this->docStar}
* Gets the default parameters.
*
@ -1533,10 +1561,10 @@ EOF;
if (preg_match('/^%([^%]+)%$/', $value, $match)) {
// we do this to deal with non string values (Boolean, integer, ...)
// the preg_replace_callback converts them to strings
return $this->dumpParameter(strtolower($match[1]));
return $this->dumpParameter($match[1]);
} else {
$replaceParameters = function ($match) {
return "'.".$this->dumpParameter(strtolower($match[2])).".'";
return "'.".$this->dumpParameter($match[2]).".'";
};
$code = str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', $replaceParameters, $this->export($value)));
@ -1582,8 +1610,6 @@ EOF;
*/
private function dumpParameter($name)
{
$name = strtolower($name);
if ($this->container->isCompiled() && $this->container->hasParameter($name)) {
$value = $this->container->getParameter($name);
$dumpedValue = $this->dumpValue($value, false);

View File

@ -471,11 +471,6 @@ class XmlFileLoader extends FileLoader
$key = array_pop($keys);
} else {
$key = $arg->getAttribute('key');
// parameter keys are case insensitive
if ('parameter' == $name && $lowercase) {
$key = strtolower($key);
}
}
$onInvalid = $arg->getAttribute('on-invalid');
@ -579,7 +574,7 @@ class XmlFileLoader extends FileLoader
foreach ($schemaLocations as $namespace => $location) {
$parts = explode('/', $location);
if (0 === stripos($location, 'phar://')) {
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
$tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
if ($tmpfile) {
copy($location, $tmpfile);
$tmpfiles[] = $tmpfile;

View File

@ -91,7 +91,7 @@ class EnvPlaceholderParameterBag extends ParameterBag
parent::resolve();
foreach ($this->envPlaceholders as $env => $placeholders) {
if (!isset($this->parameters[$name = strtolower("env($env)")])) {
if (!$this->has($name = "env($env)")) {
continue;
}
if (is_numeric($default = $this->parameters[$name])) {

View File

@ -25,6 +25,8 @@ class ParameterBag implements ParameterBagInterface
protected $parameters = array();
protected $resolved = false;
private $normalizedNames = array();
/**
* @param array $parameters An array of parameters
*/
@ -49,7 +51,7 @@ class ParameterBag implements ParameterBagInterface
public function add(array $parameters)
{
foreach ($parameters as $key => $value) {
$this->parameters[strtolower($key)] = $value;
$this->set($key, $value);
}
}
@ -66,7 +68,7 @@ class ParameterBag implements ParameterBagInterface
*/
public function get($name)
{
$name = strtolower($name);
$name = $this->normalizeName($name);
if (!array_key_exists($name, $this->parameters)) {
if (!$name) {
@ -111,7 +113,7 @@ class ParameterBag implements ParameterBagInterface
*/
public function set($name, $value)
{
$this->parameters[strtolower($name)] = $value;
$this->parameters[$this->normalizeName($name)] = $value;
}
/**
@ -119,7 +121,7 @@ class ParameterBag implements ParameterBagInterface
*/
public function has($name)
{
return array_key_exists(strtolower($name), $this->parameters);
return array_key_exists($this->normalizeName($name), $this->parameters);
}
/**
@ -129,7 +131,7 @@ class ParameterBag implements ParameterBagInterface
*/
public function remove($name)
{
unset($this->parameters[strtolower($name)]);
unset($this->parameters[$this->normalizeName($name)]);
}
/**
@ -206,7 +208,7 @@ class ParameterBag implements ParameterBagInterface
// a non-string in a parameter value
if (preg_match('/^%([^%\s]+)%$/', $value, $match)) {
$key = $match[1];
$lcKey = strtolower($key);
$lcKey = strtolower($key); // strtolower() to be removed in 4.0
if (isset($resolving[$lcKey])) {
throw new ParameterCircularReferenceException(array_keys($resolving));
@ -224,7 +226,7 @@ class ParameterBag implements ParameterBagInterface
}
$key = $match[1];
$lcKey = strtolower($key);
$lcKey = strtolower($key); // strtolower() to be removed in 4.0
if (isset($resolving[$lcKey])) {
throw new ParameterCircularReferenceException(array_keys($resolving));
}
@ -288,4 +290,18 @@ class ParameterBag implements ParameterBagInterface
return $value;
}
private function normalizeName($name)
{
if (isset($this->normalizedNames[$normalizedName = strtolower($name)])) {
$normalizedName = $this->normalizedNames[$normalizedName];
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
}

View File

@ -1097,6 +1097,21 @@ class ContainerBuilderTest extends TestCase
$this->assertNotSame($container->get('foo'), $container->get('fOO'), '->get() returns the service for the given id, case sensitively');
$this->assertSame($container->get('fOO')->Foo->foo, $container->get('foo'), '->get() returns the service for the given id, case sensitively');
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since version 3.4.
*/
public function testParameterWithMixedCase()
{
$container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
$container->register('foo', 'stdClass')
->setProperty('foo', '%FOO%');
$container->compile();
$this->assertSame('bar', $container->get('foo')->foo);
}
}
class FooClass

View File

@ -112,10 +112,6 @@ class ContainerTest extends TestCase
$sc->setParameter('foo', 'baz');
$this->assertEquals('baz', $sc->getParameter('foo'), '->setParameter() overrides previously set parameter');
$sc->setParameter('Foo', 'baz1');
$this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
$this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
try {
$sc->getParameter('baba');
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
@ -125,6 +121,20 @@ class ContainerTest extends TestCase
}
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since version 3.4.
*/
public function testGetSetParameterWithMixedCase()
{
$sc = new Container(new ParameterBag(array('foo' => 'bar')));
$sc->setParameter('Foo', 'baz1');
$this->assertEquals('baz1', $sc->getParameter('foo'), '->setParameter() converts the key to lowercase');
$this->assertEquals('baz1', $sc->getParameter('FOO'), '->getParameter() converts the key to lowercase');
}
public function testGetServiceIds()
{
$sc = new Container();

View File

@ -650,4 +650,43 @@ class PhpDumperTest extends TestCase
$container->get('bar');
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "foo" instead of "Foo" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "Foo" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "bar" instead of "BAR" is deprecated since version 3.4.
*/
public function testParameterWithMixedCase()
{
$container = new ContainerBuilder(new ParameterBag(array('Foo' => 'bar', 'BAR' => 'foo')));
$container->compile();
$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Mixed_Case')));
$container = new \Symfony_DI_PhpDumper_Test_Parameter_With_Mixed_Case();
$this->assertSame('bar', $container->getParameter('foo'));
$this->assertSame('bar', $container->getParameter('FOO'));
$this->assertSame('foo', $container->getParameter('bar'));
$this->assertSame('foo', $container->getParameter('BAR'));
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since version 3.4.
*/
public function testParameterWithLowerCase()
{
$container = new ContainerBuilder(new ParameterBag(array('foo' => 'bar')));
$container->compile();
$dumper = new PhpDumper($container);
eval('?>'.$dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Parameter_With_Lower_Case')));
$container = new \Symfony_DI_PhpDumper_Test_Parameter_With_Lower_Case();
$this->assertSame('bar', $container->getParameter('FOO'));
}
}

View File

@ -4,7 +4,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
$container = new ContainerBuilder(new ParameterBag(array(
'FOO' => '%baz%',
'foo' => '%baz%',
'baz' => 'bar',
'bar' => 'foo is %%foo bar',
'escape' => '@escapeme',

View File

@ -78,7 +78,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -96,7 +96,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -142,6 +142,22 @@ class ProjectServiceContainer extends Container
throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -82,7 +82,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -100,7 +100,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -156,6 +156,22 @@ class ProjectServiceContainer extends Container
return $this->dynamicParameters[$name] = $value;
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -80,7 +80,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -98,7 +98,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -152,6 +152,24 @@ class ProjectServiceContainer extends Container
return $this->dynamicParameters[$name] = $value;
}
private $normalizedParameterNames = array(
'env(foo)' => 'env(FOO)',
);
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*
@ -160,7 +178,7 @@ class ProjectServiceContainer extends Container
protected function getDefaultParameters()
{
return array(
'env(foo)' => 'foo',
'env(FOO)' => 'foo',
);
}
}

View File

@ -65,7 +65,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -83,7 +83,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -129,6 +129,22 @@ class ProjectServiceContainer extends Container
throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -383,7 +383,7 @@ class Container%s extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -401,7 +401,7 @@ class Container%s extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -447,6 +447,22 @@ class Container%s extends Container
throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -392,7 +392,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -410,7 +410,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -456,6 +456,22 @@ class ProjectServiceContainer extends Container
throw new InvalidArgumentException(sprintf('The dynamic parameter "%s" must be defined.', $name));
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -86,7 +86,7 @@ class ProjectServiceContainer extends Container
public function getParameter($name)
{
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
throw new InvalidArgumentException(sprintf('The parameter "%s" must be defined.', $name));
@ -104,7 +104,7 @@ class ProjectServiceContainer extends Container
*/
public function hasParameter($name)
{
$name = strtolower($name);
$name = $this->normalizeParameterName($name);
return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters);
}
@ -160,6 +160,22 @@ class ProjectServiceContainer extends Container
return $this->dynamicParameters[$name] = $value;
}
private $normalizedParameterNames = array();
private function normalizeParameterName($name)
{
if (isset($this->normalizedParameterNames[$normalizedName = strtolower($name)]) || isset($this->parameters[$normalizedName]) || array_key_exists($normalizedName, $this->parameters)) {
$normalizedName = isset($this->normalizedParameterNames[$normalizedName]) ? $this->normalizedParameterNames[$normalizedName] : $normalizedName;
if ((string) $name !== $normalizedName) {
@trigger_error(sprintf('Parameter names will be made case sensitive in Symfony 4.0. Using "%s" instead of "%s" is deprecated since version 3.4.', $name, $normalizedName), E_USER_DEPRECATED);
}
} else {
$normalizedName = $this->normalizedParameterNames[$normalizedName] = (string) $name;
}
return $normalizedName;
}
/**
* Gets the default parameters.
*

View File

@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameter>a string</parameter>
<parameter key="FOO">bar</parameter>
<parameter key="foo">bar</parameter>
<parameter key="values" type="collection">
<parameter>0</parameter>
<parameter key="integer">4</parameter>
@ -23,7 +23,7 @@
<parameter>bar</parameter>
</parameter>
</parameter>
<parameter key="MixedCase" type="collection"> <!-- Should be lower cased -->
<parameter key="mixedcase" type="collection"> <!-- Should be lower cased -->
<parameter key="MixedCaseKey">value</parameter> <!-- Should stay mixed case -->
</parameter>
<parameter key="constant" type="constant">PHP_EOL</parameter>

View File

@ -1,5 +1,5 @@
parameters:
FOO: bar
foo: bar
values:
- true
- false
@ -9,5 +9,5 @@ parameters:
bar: foo
escape: '@@escapeme'
foo_bar: '@foo_bar'
MixedCase:
mixedcase:
MixedCaseKey: value

View File

@ -115,18 +115,18 @@ class EnvPlaceholderParameterBagTest extends TestCase
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(INT_VAR)');
$bag->set('env(Int_Var)', 2);
$bag->set('env(INT_VAR)', 2);
$bag->resolve();
$this->assertSame('2', $bag->all()['env(int_var)']);
$this->assertSame('2', $bag->all()['env(INT_VAR)']);
}
public function testResolveEnvAllowsNull()
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(NULL_VAR)');
$bag->set('env(Null_Var)', null);
$bag->set('env(NULL_VAR)', null);
$bag->resolve();
$this->assertNull($bag->all()['env(null_var)']);
$this->assertNull($bag->all()['env(NULL_VAR)']);
}
/**
@ -137,7 +137,7 @@ class EnvPlaceholderParameterBagTest extends TestCase
{
$bag = new EnvPlaceholderParameterBag();
$bag->get('env(ARRAY_VAR)');
$bag->set('env(Array_Var)', array());
$bag->set('env(ARRAY_VAR)', array());
$bag->resolve();
}
@ -148,7 +148,7 @@ class EnvPlaceholderParameterBagTest extends TestCase
$bag->get('env(NULL_VAR)');
$bag->resolve();
$this->assertNull($bag->all()['env(null_var)']);
$this->assertNull($bag->all()['env(NULL_VAR)']);
}
/**

View File

@ -46,8 +46,6 @@ class ParameterBagTest extends TestCase
));
$bag->remove('foo');
$this->assertEquals(array('bar' => 'bar'), $bag->all(), '->remove() removes a parameter');
$bag->remove('BAR');
$this->assertEquals(array(), $bag->all(), '->remove() converts key to lowercase before removing');
}
public function testGetSet()
@ -59,10 +57,6 @@ class ParameterBagTest extends TestCase
$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 Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException if the key does not exist');
@ -109,10 +103,33 @@ class ParameterBagTest extends TestCase
{
$bag = new ParameterBag(array('foo' => 'bar'));
$this->assertTrue($bag->has('foo'), '->has() returns true if a parameter is defined');
$this->assertTrue($bag->has('Foo'), '->has() converts the key to lowercase');
$this->assertFalse($bag->has('bar'), '->has() returns false if a parameter is not defined');
}
/**
* @group legacy
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "BAR" instead of "bar" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "FOO" instead of "foo" is deprecated since version 3.4.
* @expectedDeprecation Parameter names will be made case sensitive in Symfony 4.0. Using "Foo" instead of "foo" is deprecated since version 3.4.
*/
public function testMixedCase()
{
$bag = new ParameterBag(array(
'foo' => 'foo',
'bar' => 'bar',
));
$bag->remove('BAR');
$this->assertEquals(array('foo' => 'foo'), $bag->all(), '->remove() converts key to lowercase before removing');
$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');
$this->assertTrue($bag->has('Foo'), '->has() converts the key to lowercase');
}
public function testResolveValue()
{
$bag = new ParameterBag(array());

View File

@ -39,7 +39,7 @@ class AutoExpireFlashBag implements FlashBagInterface
*
* @param string $storageKey The key used to store flashes in the session
*/
public function __construct($storageKey = '_sf2_flashes')
public function __construct($storageKey = '_symfony_flashes')
{
$this->storageKey = $storageKey;
}

View File

@ -39,7 +39,7 @@ class FlashBag implements FlashBagInterface
*
* @param string $storageKey The key used to store flashes in the session
*/
public function __construct($storageKey = '_sf2_flashes')
public function __construct($storageKey = '_symfony_flashes')
{
$this->storageKey = $storageKey;
}

View File

@ -62,7 +62,7 @@ class AutoExpireFlashBagTest extends TestCase
public function testGetStorageKey()
{
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
$attributeBag = new FlashBag('test');
$this->assertEquals('test', $attributeBag->getStorageKey());
}

View File

@ -57,7 +57,7 @@ class FlashBagTest extends TestCase
public function testGetStorageKey()
{
$this->assertEquals('_sf2_flashes', $this->bag->getStorageKey());
$this->assertEquals('_symfony_flashes', $this->bag->getStorageKey());
$attributeBag = new FlashBag('test');
$this->assertEquals('test', $attributeBag->getStorageKey());
}

View File

@ -26,6 +26,8 @@ use Symfony\Component\Console\Style\SymfonyStyle;
*/
class XliffLintCommand extends Command
{
protected static $defaultName = 'lint:xliff';
private $format;
private $displayCorrectFiles;
private $directoryIteratorProvider;
@ -45,7 +47,6 @@ class XliffLintCommand extends Command
protected function configure()
{
$this
->setName('lint:xliff')
->setDescription('Lints a XLIFF file and outputs encountered errors')
->addArgument('filename', null, 'A file or a directory or STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')

View File

@ -222,7 +222,7 @@ class XliffFileLoader implements LoaderInterface
$newPath = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
$parts = explode('/', $newPath);
if (0 === stripos($newPath, 'phar://')) {
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
$tmpfile = tempnam(sys_get_temp_dir(), 'symfony');
if ($tmpfile) {
copy($newPath, $tmpfile);
$parts = explode('/', str_replace('\\', '/', $tmpfile));

View File

@ -28,6 +28,8 @@ use Symfony\Component\Yaml\Yaml;
*/
class LintCommand extends Command
{
protected static $defaultName = 'lint:yaml';
private $parser;
private $format;
private $displayCorrectFiles;
@ -48,7 +50,6 @@ class LintCommand extends Command
protected function configure()
{
$this
->setName('lint:yaml')
->setDescription('Lints a file and outputs encountered errors')
->addArgument('filename', null, 'A file or a directory or STDIN')
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')

View File

@ -21,6 +21,9 @@
"require-dev": {
"symfony/console": "~3.4|~4.0"
},
"conflict": {
"symfony/console": "<3.4"
},
"suggest": {
"symfony/console": "For validating YAML files using the lint command"
},