Merge branch '2.7'
* 2.7: [FrameworkBundle] fixed tests [FrameworkBundle][config cmd] initialize extension. [Console][TableStyle] validate padding type value. Refresh catalogues when resources change [HttpKernel] Mask '_password' request in profiler
This commit is contained in:
commit
1e15f0e096
@ -14,6 +14,8 @@ namespace Symfony\Bundle\FrameworkBundle\Command;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||
|
||||
/**
|
||||
* A console command for dumping available configuration reference.
|
||||
@ -70,6 +72,8 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
|
||||
}
|
||||
}
|
||||
|
||||
$this->initializeExtensions($bundles);
|
||||
|
||||
return $extension;
|
||||
}
|
||||
|
||||
@ -83,4 +87,22 @@ abstract class AbstractConfigCommand extends ContainerDebugCommand
|
||||
throw new \LogicException(sprintf('Configuration class "%s" should implement ConfigurationInterface in order to be dumpable', get_class($configuration)));
|
||||
}
|
||||
}
|
||||
|
||||
private function initializeExtensions($bundles)
|
||||
{
|
||||
// Re-build bundle manually to initialize DI extensions that can be extended by other bundles in their build() method
|
||||
// as this method is not called when the container is loaded from the cache.
|
||||
$parameters = $this->getContainer()->getParameterBag()->all();
|
||||
$container = new ContainerBuilder(new ParameterBag($parameters));
|
||||
foreach ($bundles as $bundle) {
|
||||
if ($extension = $bundle->getContainerExtension()) {
|
||||
$container->registerExtension($extension);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($bundles as $bundle) {
|
||||
$bundle = clone $bundle;
|
||||
$bundle->build($container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"path": "\/hello\/{name}",
|
||||
"pathRegex": "#^\/hello(?:\/(?P<name>[a-z]+))?$#s",
|
||||
"host": "localhost",
|
||||
"hostRegex": "#^localhost$#s",
|
||||
"hostRegex": "#^localhost$#si",
|
||||
"scheme": "http|https",
|
||||
"method": "GET|HEAD",
|
||||
"class": "Symfony\\Component\\Routing\\Route",
|
||||
|
@ -1,7 +1,7 @@
|
||||
- Path: /hello/{name}
|
||||
- Path Regex: #^/hello(?:/(?P<name>[a-z]+))?$#s
|
||||
- Host: localhost
|
||||
- Host Regex: #^localhost$#s
|
||||
- Host Regex: #^localhost$#si
|
||||
- Scheme: http|https
|
||||
- Method: GET|HEAD
|
||||
- Class: Symfony\Component\Routing\Route
|
||||
|
@ -1,7 +1,7 @@
|
||||
<comment>Path</comment> /hello/{name}
|
||||
<comment>Path Regex</comment> #^/hello(?:/(?P<name>[a-z]+))?$#s
|
||||
<comment>Host</comment> localhost
|
||||
<comment>Host Regex</comment> #^localhost$#s
|
||||
<comment>Host Regex</comment> #^localhost$#si
|
||||
<comment>Scheme</comment> http|https
|
||||
<comment>Method</comment> GET|HEAD
|
||||
<comment>Class</comment> Symfony\Component\Routing\Route
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<route class="Symfony\Component\Routing\Route">
|
||||
<path regex="#^/hello(?:/(?P<name>[a-z]+))?$#s">/hello/{name}</path>
|
||||
<host regex="#^localhost$#s">localhost</host>
|
||||
<host regex="#^localhost$#si">localhost</host>
|
||||
<scheme>http</scheme>
|
||||
<scheme>https</scheme>
|
||||
<method>GET</method>
|
||||
|
@ -2,7 +2,7 @@
|
||||
"path": "\/name\/add",
|
||||
"pathRegex": "#^\/name\/add$#s",
|
||||
"host": "localhost",
|
||||
"hostRegex": "#^localhost$#s",
|
||||
"hostRegex": "#^localhost$#si",
|
||||
"scheme": "http|https",
|
||||
"method": "PUT|POST",
|
||||
"class": "Symfony\\Component\\Routing\\Route",
|
||||
|
@ -1,7 +1,7 @@
|
||||
- Path: /name/add
|
||||
- Path Regex: #^/name/add$#s
|
||||
- Host: localhost
|
||||
- Host Regex: #^localhost$#s
|
||||
- Host Regex: #^localhost$#si
|
||||
- Scheme: http|https
|
||||
- Method: PUT|POST
|
||||
- Class: Symfony\Component\Routing\Route
|
||||
|
@ -1,7 +1,7 @@
|
||||
<comment>Path</comment> /name/add
|
||||
<comment>Path Regex</comment> #^/name/add$#s
|
||||
<comment>Host</comment> localhost
|
||||
<comment>Host Regex</comment> #^localhost$#s
|
||||
<comment>Host Regex</comment> #^localhost$#si
|
||||
<comment>Scheme</comment> http|https
|
||||
<comment>Method</comment> PUT|POST
|
||||
<comment>Class</comment> Symfony\Component\Routing\Route
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<route class="Symfony\Component\Routing\Route">
|
||||
<path regex="#^/name/add$#s">/name/add</path>
|
||||
<host regex="#^localhost$#s">localhost</host>
|
||||
<host regex="#^localhost$#si">localhost</host>
|
||||
<scheme>http</scheme>
|
||||
<scheme>https</scheme>
|
||||
<method>PUT</method>
|
||||
|
@ -3,7 +3,7 @@
|
||||
"path": "\/hello\/{name}",
|
||||
"pathRegex": "#^\/hello(?:\/(?P<name>[a-z]+))?$#s",
|
||||
"host": "localhost",
|
||||
"hostRegex": "#^localhost$#s",
|
||||
"hostRegex": "#^localhost$#si",
|
||||
"scheme": "http|https",
|
||||
"method": "GET|HEAD",
|
||||
"class": "Symfony\\Component\\Routing\\Route",
|
||||
@ -23,7 +23,7 @@
|
||||
"path": "\/name\/add",
|
||||
"pathRegex": "#^\/name\/add$#s",
|
||||
"host": "localhost",
|
||||
"hostRegex": "#^localhost$#s",
|
||||
"hostRegex": "#^localhost$#si",
|
||||
"scheme": "http|https",
|
||||
"method": "PUT|POST",
|
||||
"class": "Symfony\\Component\\Routing\\Route",
|
||||
|
@ -4,7 +4,7 @@ route_1
|
||||
- Path: /hello/{name}
|
||||
- Path Regex: #^/hello(?:/(?P<name>[a-z]+))?$#s
|
||||
- Host: localhost
|
||||
- Host Regex: #^localhost$#s
|
||||
- Host Regex: #^localhost$#si
|
||||
- Scheme: http|https
|
||||
- Method: GET|HEAD
|
||||
- Class: Symfony\Component\Routing\Route
|
||||
@ -24,7 +24,7 @@ route_2
|
||||
- Path: /name/add
|
||||
- Path Regex: #^/name/add$#s
|
||||
- Host: localhost
|
||||
- Host Regex: #^localhost$#s
|
||||
- Host Regex: #^localhost$#si
|
||||
- Scheme: http|https
|
||||
- Method: PUT|POST
|
||||
- Class: Symfony\Component\Routing\Route
|
||||
|
@ -2,7 +2,7 @@
|
||||
<routes>
|
||||
<route name="route_1" class="Symfony\Component\Routing\Route">
|
||||
<path regex="#^/hello(?:/(?P<name>[a-z]+))?$#s">/hello/{name}</path>
|
||||
<host regex="#^localhost$#s">localhost</host>
|
||||
<host regex="#^localhost$#si">localhost</host>
|
||||
<scheme>http</scheme>
|
||||
<scheme>https</scheme>
|
||||
<method>GET</method>
|
||||
@ -21,7 +21,7 @@
|
||||
</route>
|
||||
<route name="route_2" class="Symfony\Component\Routing\Route">
|
||||
<path regex="#^/name/add$#s">/name/add</path>
|
||||
<host regex="#^localhost$#s">localhost</host>
|
||||
<host regex="#^localhost$#si">localhost</host>
|
||||
<scheme>http</scheme>
|
||||
<scheme>https</scheme>
|
||||
<method>PUT</method>
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config;
|
||||
|
||||
class CustomConfig
|
||||
{
|
||||
public function addConfiguration($rootNode)
|
||||
{
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('custom')->end()
|
||||
->end()
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
private $customConfig;
|
||||
|
||||
public function __construct($customConfig = null)
|
||||
{
|
||||
$this->customConfig = $customConfig;
|
||||
}
|
||||
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('test');
|
||||
|
||||
if ($this->customConfig) {
|
||||
$this->customConfig->addConfiguration($rootNode);
|
||||
}
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
class TestExtension extends Extension
|
||||
{
|
||||
private $customConfig;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = $this->getConfiguration($configs, $container);
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new Configuration($this->customConfig);
|
||||
}
|
||||
|
||||
public function setCustomConfig($customConfig)
|
||||
{
|
||||
$this->customConfig = $customConfig;
|
||||
}
|
||||
}
|
@ -12,7 +12,18 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
|
||||
|
||||
class TestBundle extends Bundle
|
||||
{
|
||||
public function build(ContainerBuilder $container)
|
||||
{
|
||||
parent::build($container);
|
||||
|
||||
/** @var $extension DependencyInjection\TestExtension */
|
||||
$extension = $container->getExtension('test');
|
||||
|
||||
$extension->setCustomConfig(new CustomConfig());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
<?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\Bundle\FrameworkBundle\Tests\Functional;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @group functional
|
||||
*/
|
||||
class ConfigDumpReferenceCommandTest extends WebTestCase
|
||||
{
|
||||
private $application;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$kernel = static::createKernel(array('test_case' => 'ConfigDump', 'root_config' => 'config.yml'));
|
||||
$this->application = new Application($kernel);
|
||||
$this->application->doRun(new ArrayInput(array()), new NullOutput());
|
||||
}
|
||||
|
||||
public function testDumpBundleName()
|
||||
{
|
||||
$tester = $this->createCommandTester();
|
||||
$ret = $tester->execute(array('name' => 'TestBundle'));
|
||||
|
||||
$this->assertEquals(0, $ret, 'Returns 0 in case of success');
|
||||
$this->assertContains('test:', $tester->getDisplay());
|
||||
$this->assertContains(' custom:', $tester->getDisplay());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return CommandTester
|
||||
*/
|
||||
private function createCommandTester()
|
||||
{
|
||||
$command = $this->application->find('config:dump-reference');
|
||||
|
||||
return new CommandTester($command);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
|
||||
return array(
|
||||
new FrameworkBundle(),
|
||||
new TestBundle(),
|
||||
);
|
@ -0,0 +1,2 @@
|
||||
imports:
|
||||
- { resource: ../config/default.yml }
|
@ -234,6 +234,10 @@ class TableStyle
|
||||
*/
|
||||
public function setPadType($padType)
|
||||
{
|
||||
if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
|
||||
throw new \InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
|
||||
}
|
||||
|
||||
$this->padType = $padType;
|
||||
|
||||
return $this;
|
||||
|
@ -0,0 +1,27 @@
|
||||
<?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\Console\Tests\Helper;
|
||||
|
||||
use Symfony\Component\Console\Helper\TableStyle;
|
||||
|
||||
class TableStyleTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).
|
||||
*/
|
||||
public function testSetPadTypeWithInvalidType()
|
||||
{
|
||||
$style = new TableStyle();
|
||||
$style->setPadType('TEST');
|
||||
}
|
||||
}
|
@ -117,6 +117,10 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
|
||||
$this->data['request_server']['PHP_AUTH_PW'] = '******';
|
||||
}
|
||||
|
||||
if (isset($this->data['request_request']['_password'])) {
|
||||
$this->data['request_request']['_password'] = '******';
|
||||
}
|
||||
|
||||
if (isset($this->controllers[$request])) {
|
||||
$controller = $this->controllers[$request];
|
||||
if (is_array($controller)) {
|
||||
|
@ -167,8 +167,6 @@ class ProcessBuilder
|
||||
/**
|
||||
* Sets the input of the process.
|
||||
*
|
||||
* Deprecation: As of Symfony 2.5, this method only accepts string values.
|
||||
*
|
||||
* @param string|null $input The input as a string
|
||||
*
|
||||
* @return ProcessBuilder
|
||||
|
@ -101,6 +101,41 @@ class TranslatorCacheTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||
}
|
||||
|
||||
public function testRefreshCacheWhenResourcesChange()
|
||||
{
|
||||
// prime the cache
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
$loader
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('fr', array(
|
||||
'foo' => 'foo A',
|
||||
))))
|
||||
;
|
||||
|
||||
$translator = new Translator('fr', new MessageSelector(), $this->tmpDir, true);
|
||||
$translator->setLocale('fr');
|
||||
$translator->addLoader('loader', $loader);
|
||||
$translator->addResource('loader', 'foo', 'fr');
|
||||
|
||||
$this->assertEquals('foo A', $translator->trans('foo'));
|
||||
|
||||
// add a new resource to refresh the cache
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
$loader
|
||||
->method('load')
|
||||
->will($this->returnValue($this->getCatalogue('fr', array(
|
||||
'foo' => 'foo B',
|
||||
))))
|
||||
;
|
||||
|
||||
$translator = new Translator('fr', new MessageSelector(), $this->tmpDir, true);
|
||||
$translator->setLocale('fr');
|
||||
$translator->addLoader('loader', $loader);
|
||||
$translator->addResource('loader', 'bar', 'fr');
|
||||
|
||||
$this->assertEquals('foo B', $translator->trans('foo'));
|
||||
}
|
||||
|
||||
public function testTransWithCachingWithInvalidLocale()
|
||||
{
|
||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||
|
@ -346,8 +346,9 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param bool $forceRefresh
|
||||
*/
|
||||
private function initializeCacheCatalogue($locale)
|
||||
private function initializeCacheCatalogue($locale, $forceRefresh = false)
|
||||
{
|
||||
if (isset($this->catalogues[$locale])) {
|
||||
return;
|
||||
@ -361,7 +362,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
|
||||
|
||||
$this->assertValidLocale($locale);
|
||||
$cache = new ConfigCache($this->cacheDir.'/catalogue.'.$locale.'.php', $this->debug);
|
||||
if (!$cache->isFresh()) {
|
||||
if ($forceRefresh || !$cache->isFresh()) {
|
||||
$this->initializeCatalogue($locale);
|
||||
|
||||
$fallbackContent = '';
|
||||
@ -392,13 +393,15 @@ EOF
|
||||
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
|
||||
\$resourcesHash = '%s';
|
||||
\$catalogue = new MessageCatalogue('%s', %s);
|
||||
|
||||
%s
|
||||
return \$catalogue;
|
||||
return array(\$catalogue, \$resourcesHash);
|
||||
|
||||
EOF
|
||||
,
|
||||
$this->getResourcesHash($locale),
|
||||
$locale,
|
||||
var_export($this->catalogues[$locale]->all(), true),
|
||||
$fallbackContent
|
||||
@ -409,7 +412,30 @@ EOF
|
||||
return;
|
||||
}
|
||||
|
||||
$this->catalogues[$locale] = include $cache;
|
||||
$catalogue = include $cache;
|
||||
|
||||
/**
|
||||
* Old cache returns only the catalogue, without resourcesHash
|
||||
*/
|
||||
$resourcesHash = null;
|
||||
if (is_array($catalogue)) {
|
||||
list($catalogue, $resourcesHash) = $catalogue;
|
||||
}
|
||||
|
||||
if ($this->debug && $resourcesHash !== $this->getResourcesHash($locale)) {
|
||||
return $this->initializeCacheCatalogue($locale, true);
|
||||
}
|
||||
|
||||
$this->catalogues[$locale] = $catalogue;
|
||||
}
|
||||
|
||||
private function getResourcesHash($locale)
|
||||
{
|
||||
if (!isset($this->resources[$locale])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sha1(serialize($this->resources[$locale]));
|
||||
}
|
||||
|
||||
private function doLoadCatalogue($locale)
|
||||
|
Reference in New Issue
Block a user