Skip to content

Commit

Permalink
Merge branch '4.2' into 4.3
Browse files Browse the repository at this point in the history
* 4.2:
  [Routing] Fixed unexpected 404 NoConfigurationException
  [DI] Removes number of elements information in debug mode
  [Contracts] Simplify implementation declarations
  Update PR template for 4.3
  [Intl] Add FallbackTrait for data generation
  [Console] Commands with an alias should not be recognized as ambiguous
  clarify the possible class/interface of the cache
  • Loading branch information
nicolas-grekas committed May 9, 2019
2 parents 6852c84 + c083e20 commit 7a53e8d
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 126 deletions.
15 changes: 8 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
| Q | A
| ------------- | ---
| Branch? | master for features / 3.4 up to 4.2 for bug fixes <!-- see below -->
| Branch? | master for features / 3.4, 4.2 or 4.3 for bug fixes <!-- see below -->
| Bug fix? | yes/no
| New feature? | yes/no <!-- don't forget to update src/**/CHANGELOG.md files -->
| New feature? | yes/no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | yes/no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Deprecations? | yes/no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
- Bug fixes must be submitted against the lowest branch where they apply
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.
Additionally (see https://symfony.com/roadmap):
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
-->
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$options['show_hidden'] = $input->getOption('show-hidden');
$options['raw_text'] = $input->getOption('raw');
$options['output'] = $io;
$options['is_debug'] = $this->getApplication()->getKernel()->isDebug();

try {
$helper->describe($io, $object, $options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
Expand Down Expand Up @@ -347,21 +348,21 @@ protected function describeContainerDefinition(Definition $definition, array $op
if ($argument instanceof Reference) {
$argumentsInformation[] = sprintf('Service(%s)', (string) $argument);
} elseif ($argument instanceof IteratorArgument) {
$argumentsInformation[] = sprintf('Iterator (%d element(s))', \count($argument->getValues()));
foreach (array_map(function (Reference $value) {return (string) $value; }, $argument->getValues()) as $service) {
$argumentsInformation[] = sprintf('- %s', $service);
if ($argument instanceof TaggedIteratorArgument) {
$argumentsInformation[] = sprintf('Tagged Iterator for "%s"%s', $argument->getTag(), $options['is_debug'] ? '' : sprintf(' (%d element(s))', \count($argument->getValues())));
} else {
$argumentsInformation[] = sprintf('Iterator (%d element(s))', \count($argument->getValues()));
}

foreach ($argument->getValues() as $ref) {
$argumentsInformation[] = sprintf('- Service(%s)', $ref);
}
} elseif ($argument instanceof ServiceLocatorArgument) {
$argumentsInformation[] = sprintf('Service locator (%d element(s))', \count($argument->getValues()));
} elseif ($argument instanceof Definition) {
$argumentsInformation[] = 'Inlined Service';
} else {
$argumentsInformation[] = \is_array($argument) ? sprintf('Array (%d element(s))', \count($argument)) : $argument;
if (\is_array($argument)) {
foreach (array_keys($argument) as $service) {
$argumentsInformation[] = sprintf('- %s', $service);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<tag name="kernel.cache_warmer" />
</service>

<service id="serializer.mapping.cache.symfony" class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
<service id="serializer.mapping.cache.symfony" class="Psr\Cache\CacheItemPoolInterface">
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="create" />
<argument>%serializer.mapping.cache.file%</argument>
<argument type="service" id="cache.serializer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ abstract protected function getFormat();

private function assertDescription($expectedDescription, $describedObject, array $options = [])
{
$options['is_debug'] = false;
$options['raw_output'] = true;
$options['raw_text'] = true;
$output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
 %parameter% 
 Inlined Service 
 Array (3 element(s)) 
 - 0 
 - 1 
 - 2 
 Iterator (2 element(s)) 
 - definition_1 
 - .definition_2
 - Service(definition_1) 
 - Service(.definition_2)
---------------- -----------------------------

2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"provide": {
"psr/cache-implementation": "1.0",
"psr/simple-cache-implementation": "1.0",
"symfony/cache-contracts-implementation": "1.0"
"symfony/cache-implementation": "1.0"
},
"require": {
"php": "^7.1.3",
Expand Down
9 changes: 9 additions & 0 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,15 @@ public function find($name)
$this->init();

$aliases = [];

foreach ($this->commands as $command) {
foreach ($command->getAliases() as $alias) {
if (!$this->has($alias)) {
$this->commands[$alias] = $command;
}
}
}

$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
$commands = preg_grep('{^'.$expr.'}', $allCommands);
Expand Down
32 changes: 27 additions & 5 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static function setUpBeforeClass()
require_once self::$fixturesPath.'/FooSubnamespaced1Command.php';
require_once self::$fixturesPath.'/FooSubnamespaced2Command.php';
require_once self::$fixturesPath.'/FooWithoutAliasCommand.php';
require_once self::$fixturesPath.'/TestTiti.php';
require_once self::$fixturesPath.'/TestToto.php';
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering.php';
require_once self::$fixturesPath.'/TestAmbiguousCommandRegistering2.php';
}

protected function normalizeLineBreaks($text)
Expand Down Expand Up @@ -165,6 +165,28 @@ public function testRegister()
$this->assertEquals('foo', $command->getName(), '->register() registers a new command');
}

public function testRegisterAmbiguous()
{
$code = function (InputInterface $input, OutputInterface $output) {
$output->writeln('It works!');
};

$application = new Application();
$application->setAutoExit(false);
$application
->register('test-foo')
->setAliases(['test'])
->setCode($code);

$application
->register('test-bar')
->setCode($code);

$tester = new ApplicationTester($application);
$tester->run(['test']);
$this->assertContains('It works!', $tester->getDisplay(true));
}

public function testAdd()
{
$application = new Application();
Expand Down Expand Up @@ -304,9 +326,9 @@ public function testFindAmbiguousNamespace()
public function testFindNonAmbiguous()
{
$application = new Application();
$application->add(new \TestTiti());
$application->add(new \TestToto());
$this->assertEquals('test-toto', $application->find('test')->getName());
$application->add(new \TestAmbiguousCommandRegistering());
$application->add(new \TestAmbiguousCommandRegistering2());
$this->assertEquals('test-ambiguous', $application->find('test')->getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestToto extends Command
class TestAmbiguousCommandRegistering extends Command
{
protected function configure()
{
$this
->setName('test-toto')
->setDescription('The test-toto command')
->setName('test-ambiguous')
->setDescription('The test-ambiguous command')
->setAliases(['test'])
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-toto');
$output->write('test-ambiguous');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class TestTiti extends Command
class TestAmbiguousCommandRegistering2 extends Command
{
protected function configure()
{
$this
->setName('test-titi')
->setDescription('The test:titi command')
->setName('test-ambiguous2')
->setDescription('The test-ambiguous2 command')
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$output->write('test-titi');
$output->write('test-ambiguous2');
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"provide": {
"psr/container-implementation": "1.0",
"symfony/service-contracts-implementation": "1.0"
"symfony/service-implementation": "1.0"
},
"autoload": {
"psr-4": { "Symfony\\Component\\DependencyInjection\\": "" },
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"provide": {
"psr/http-client-implementation": "1.0",
"symfony/http-client-contracts-implementation": "1.1"
"symfony/http-client-implementation": "1.1"
},
"require": {
"php": "^7.1.3",
Expand Down
67 changes: 67 additions & 0 deletions src/Symfony/Component/Intl/Data/Generator/FallbackTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Intl\Data\Generator;

use Symfony\Component\Intl\Data\Bundle\Reader\BundleEntryReaderInterface;
use Symfony\Component\Intl\Locale;

/**
* @author Roland Franssen <franssen.roland@gmail.com>
*
* @internal
*/
trait FallbackTrait
{
private $fallbackCache = [];
private $generatingFallback = false;

/**
* @param string $tempDir
* @param string $displayLocale
*
* @return array|null
*
* @see AbstractDataGenerator::generateDataForLocale()
*/
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);

/**
* @param string $tempDir
*
* @return array|null
*
* @see AbstractDataGenerator::generateDataForRoot()
*/
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);

private function generateFallbackData(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): array
{
if (null === $fallback = Locale::getFallback($displayLocale)) {
return [];
}

if (isset($this->fallbackCache[$fallback])) {
return $this->fallbackCache[$fallback];
}

$prevGeneratingFallback = $this->generatingFallback;
$this->generatingFallback = true;

try {
$data = 'root' === $fallback ? $this->generateDataForRoot($reader, $tempDir) : $this->generateDataForLocale($reader, $tempDir, $fallback);
} finally {
$this->generatingFallback = $prevGeneratingFallback;
}

return $this->fallbackCache[$fallback] = $data ?: [];
}
}

0 comments on commit 7a53e8d

Please sign in to comment.