Merge branch '2.1'

* 2.1:
  [Console] Fix style escaping parsing
  [Console] Make style formatter matching less greedy to avoid having to escape when not needed
  [Bundle] [FrameworkBundle] fixed indentation in esi.xml services file.
  [Component] [Security] fixed PSR-2 coding violation in ClassUtilsTest class.
  [Form] Fixed EntityChoiceList when loading objects with negative integer IDs
  [TwigBundle] There is no CSS visibility of display, should be visible instead
  [Form] corrected source node for a Danish translation
  [DependencyInjection] fixed a bug where the strict flag on references were lost (closes #6607)
  [HttpFoundation] Check if required shell functions for `FileBinaryMimeTypeGuesser` are not disabled
  [CssSelector] added css selector with empty string
  [HttpFoundation] Docblock for Request::isXmlHttpRequest() now points to Wikipedia
  [DependencyInjection] refactored code to avoid logic duplication
  [Form] Deleted references in FormBuilder::getFormConfig() to improve performance
  [HttpFoundation] Update docblock for non-working method

Conflicts:
	src/Symfony/Bundle/TwigBundle/Resources/views/Exception/trace.html.twig
	src/Symfony/Bundle/TwigBundle/Resources/views/Exception/traces.html.twig
This commit is contained in:
Fabien Potencier 2013-01-08 19:17:41 +01:00
commit aba96c7cae
19 changed files with 184 additions and 50 deletions

View File

@ -329,7 +329,7 @@ class EntityChoiceList extends ObjectChoiceList
protected function createIndex($entity)
{
if ($this->idAsIndex) {
return current($this->getIdentifierValues($entity));
return $this->fixIndex(current($this->getIdentifierValues($entity)));
}
return parent::createIndex($entity);
@ -355,6 +355,23 @@ class EntityChoiceList extends ObjectChoiceList
return parent::createValue($entity);
}
/**
* {@inheritdoc}
*/
protected function fixIndex($index)
{
$index = parent::fixIndex($index);
// If the ID is a single-field integer identifier, it is used as
// index. Replace any leading minus by underscore to make it a valid
// form name.
if ($this->idAsIndex && $index < 0) {
$index = strtr($index, '-', '_');
}
return $index;
}
/**
* Loads the list with entities.
*/

View File

@ -312,4 +312,47 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
$this->assertSame(array(0 => $entity1, 1 => $entity2), $choiceList->getChoices());
}
public function testMinusReplacedByUnderscoreInNegativeIntIds()
{
$entity1 = new SingleIdentEntity(-1, 'Foo');
$entity2 = new SingleIdentEntity(1, 'Bar');
// Persist for managed state
$this->em->persist($entity1);
$this->em->persist($entity2);
$this->em->flush();
$choiceList = new EntityChoiceList(
$this->em,
self::SINGLE_IDENT_CLASS,
'name'
);
$this->assertSame(array('_1' => $entity1, 1 => $entity2), $choiceList->getChoices());
$this->assertSame(array('_1', 1), $choiceList->getIndicesForChoices(array($entity1, $entity2)));
$this->assertSame(array('_1', 1), $choiceList->getIndicesForValues(array('-1', '1')));
}
public function testMinusReplacedByUnderscoreIfNotLoaded()
{
$entity1 = new SingleIdentEntity(-1, 'Foo');
$entity2 = new SingleIdentEntity(1, 'Bar');
// Persist for managed state
$this->em->persist($entity1);
$this->em->persist($entity2);
$this->em->flush();
$choiceList = new EntityChoiceList(
$this->em,
self::SINGLE_IDENT_CLASS,
'name'
);
// no getChoices()!
$this->assertSame(array('_1', 1), $choiceList->getIndicesForChoices(array($entity1, $entity2)));
$this->assertSame(array('_1', 1), $choiceList->getIndicesForValues(array('-1', '1')));
}
}

View File

@ -13,8 +13,8 @@
<service id="esi" class="%esi.class%" />
<service id="esi_listener" class="%esi_listener.class%">
<tag name="kernel.event_subscriber" />
<argument type="service" id="esi" on-invalid="ignore" />
<tag name="kernel.event_subscriber" />
<argument type="service" id="esi" on-invalid="ignore" />
</service>
</services>
</container>

View File

@ -12,8 +12,8 @@
in {{ trace.file|format_file(trace.line) }}&nbsp;
{% spaceless %}
<a href="#" onclick="toggle('trace-{{ prefix ~ '-' ~ i }}'); switchIcons('icon-{{ prefix ~ '-' ~ i }}-open', 'icon-{{ prefix ~ '-' ~ i }}-close'); return false;">
<img class="toggle" id="icon-{{ prefix ~ '-' ~ i }}-close" alt="-" src="data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=" style="visibility: {{ 0 == i ? 'display' : 'hidden' }}" />
<img class="toggle" id="icon-{{ prefix ~ '-' ~ i }}-open" alt="+" src="data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7" style="visibility: {{ 0 == i ? 'hidden' : 'display' }}; margin-left: -18px" />
<img class="toggle" id="icon-{{ prefix ~ '-' ~ i }}-close" alt="-" src="data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=" style="visibility: {{ 0 == i ? 'visible' : 'hidden' }}" />
<img class="toggle" id="icon-{{ prefix ~ '-' ~ i }}-open" alt="+" src="data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7" style="visibility: {{ 0 == i ? 'hidden' : 'visible' }}; margin-left: -18px" />
</a>
{% endspaceless %}
<div id="trace-{{ prefix ~ '-' ~ i }}" style="display: {{ 0 == i ? 'block' : 'none' }}" class="trace">

View File

@ -5,8 +5,8 @@
{{ exception.class|abbr_class }}: {{ exception.message|nl2br|format_file_from_text }}&nbsp;
{% spaceless %}
<a href="#" onclick="toggle('traces-{{ position }}', 'traces'); switchIcons('icon-traces-{{ position }}-open', 'icon-traces-{{ position }}-close'); return false;">
<img class="toggle" id="icon-traces-{{ position }}-close" alt="-" src="data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=" style="visibility: {{ 0 == count ? 'display' : 'hidden' }}" />
<img class="toggle" id="icon-traces-{{ position }}-open" alt="+" src="data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7" style="visibility: {{ 0 == count ? 'hidden' : 'display' }}; margin-left: -18px" />
<img class="toggle" id="icon-traces-{{ position }}-close" alt="-" src="data:image/gif;base64,R0lGODlhEgASAMQSANft94TG57Hb8GS44ez1+mC24IvK6ePx+Wa44dXs92+942e54o3L6W2844/M6dnu+P/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABIALAAAAAASABIAQAVCoCQBTBOd6Kk4gJhGBCTPxysJb44K0qD/ER/wlxjmisZkMqBEBW5NHrMZmVKvv9hMVsO+hE0EoNAstEYGxG9heIhCADs=" style="visibility: {{ 0 == count ? 'visible' : 'hidden' }}" />
<img class="toggle" id="icon-traces-{{ position }}-open" alt="+" src="data:image/gif;base64,R0lGODlhEgASAMQTANft99/v+Ga44bHb8ITG52S44dXs9+z1+uPx+YvK6WC24G+944/M6W28443L6dnu+Ge54v/+/l614P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAABMALAAAAAASABIAQAVS4DQBTiOd6LkwgJgeUSzHSDoNaZ4PU6FLgYBA5/vFID/DbylRGiNIZu74I0h1hNsVxbNuUV4d9SsZM2EzWe1qThVzwWFOAFCQFa1RQq6DJB4iIQA7" style="visibility: {{ 0 == count ? 'hidden' : 'visible' }}; margin-left: -18px" />
</a>
{% endspaceless %}
</h2>

View File

@ -23,7 +23,7 @@ class OutputFormatter implements OutputFormatterInterface
/**
* The pattern to phrase the format.
*/
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?:(?!\\\\?<).)*)#is';
const FORMAT_PATTERN = '#(\\\\?)<(/?)([a-z][a-z0-9_=;-]+)?>((?: [^<\\\\]+ | (?!<(?:/?[a-z]|/>)). | .(?<=\\\\<) )*)#isx';
private $decorated;
private $styles = array();

View File

@ -73,6 +73,26 @@ class FormatterStyleTest extends \PHPUnit_Framework_TestCase
);
}
public function testStyleMatchingNotGreedy()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"(\033[32m>=2.0,<2.3\033[0m)",
$formatter->format('(<info>>=2.0,<2.3</info>)')
);
}
public function testStyleEscaping()
{
$formatter = new OutputFormatter(true);
$this->assertEquals(
"(\033[32mz>=2.0,<a2.3\033[0m)",
$formatter->format('(<info>'.$formatter->escape('z>=2.0,<a2.3').'</info>)')
);
}
public function testDeepNestedStyles()
{
$formatter = new OutputFormatter(true);

View File

@ -34,6 +34,7 @@ class TokenizerTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals('foo[class=foo bar ]', $this->tokensToString($this->tokenizer->tokenize('foo[class="foo bar"]')), '->tokenize() lexes an input string and returns an array of tokens');
$this->assertEquals("foo[class=foo Abar ]", $this->tokensToString($this->tokenizer->tokenize('foo[class="foo \\65 bar"]')), '->tokenize() lexes an input string and returns an array of tokens');
$this->assertEquals("img[alt= ]", $this->tokensToString($this->tokenizer->tokenize('img[alt=""]')), '->tokenize() lexes an input string and returns an array of tokens');
}
/**

View File

@ -129,7 +129,7 @@ class Tokenizer
}
$result = substr($s, $start, $next - $start);
if ('\\' === $result[strlen($result) - 1]) {
if (strlen($result) > 0 && '\\' === $result[strlen($result) - 1]) {
// next quote character is escaped
$pos = $next + 1;
continue;

View File

@ -89,7 +89,7 @@ class ResolveInvalidReferencesPass implements CompilerPassInterface
// resolve invalid behavior
if ($exists && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
$arguments[$k] = new Reference($id);
$arguments[$k] = new Reference($id, ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $argument->isStrict());
} elseif (!$exists && ContainerInterface::NULL_ON_INVALID_REFERENCE === $invalidBehavior) {
$arguments[$k] = null;
} elseif (!$exists && ContainerInterface::IGNORE_ON_INVALID_REFERENCE === $invalidBehavior) {

View File

@ -229,24 +229,7 @@ class PhpDumper extends Dumper
throw new ServiceCircularReferenceException($id, array($id));
}
$arguments = array();
foreach ($sDefinition->getArguments() as $argument) {
$arguments[] = $this->dumpValue($argument);
}
if (null !== $sDefinition->getFactoryMethod()) {
if (null !== $sDefinition->getFactoryClass()) {
$code .= sprintf(" \$%s = call_user_func(array(%s, '%s')%s);\n", $name, $this->dumpValue($sDefinition->getFactoryClass()), $sDefinition->getFactoryMethod(), count($arguments) > 0 ? ', '.implode(', ', $arguments) : '');
} elseif (null !== $sDefinition->getFactoryService()) {
$code .= sprintf(" \$%s = %s->%s(%s);\n", $name, $this->getServiceCall($sDefinition->getFactoryService()), $sDefinition->getFactoryMethod(), implode(', ', $arguments));
} else {
throw new RuntimeException('Factory service or factory class must be defined in service definition for '.$id);
}
} elseif (false !== strpos($class, '$')) {
$code .= sprintf(" \$class = %s;\n \$%s = new \$class(%s);\n", $class, $name, implode(', ', $arguments));
} else {
$code .= sprintf(" \$%s = new \\%s(%s);\n", $name, substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
}
$code .= $this->addNewInstance($id, $sDefinition, '$'.$name, ' = ');
if (!$this->hasReference($id, $sDefinition->getMethodCalls(), true) && !$this->hasReference($id, $sDefinition->getProperties(), true)) {
$code .= $this->addServiceMethodCalls(null, $sDefinition, $name);
@ -297,11 +280,6 @@ class PhpDumper extends Dumper
throw new InvalidArgumentException(sprintf('"%s" is not a valid class name for the "%s" service.', $class, $id));
}
$arguments = array();
foreach ($definition->getArguments() as $value) {
$arguments[] = $this->dumpValue($value);
}
$simple = $this->isSimpleInstance($id, $definition);
$instantiation = '';
@ -320,19 +298,7 @@ class PhpDumper extends Dumper
$instantiation .= ' = ';
}
if (null !== $definition->getFactoryMethod()) {
if (null !== $definition->getFactoryClass()) {
$code = sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');
} elseif (null !== $definition->getFactoryService()) {
$code = sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments));
} else {
throw new RuntimeException('Factory method requires a factory service or factory class in service definition for '.$id);
}
} elseif (false !== strpos($class, '$')) {
$code = sprintf(" \$class = %s;\n\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
} else {
$code = sprintf(" $return{$instantiation}new \\%s(%s);\n", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
}
$code = $this->addNewInstance($id, $definition, $return, $instantiation);
if (!$simple) {
$code .= "\n";
@ -611,6 +577,34 @@ EOF;
return $publicServices.$aliasServices.$privateServices;
}
private function addNewInstance($id, Definition $definition, $return, $instantiation)
{
$class = $this->dumpValue($definition->getClass());
$arguments = array();
foreach ($definition->getArguments() as $value) {
$arguments[] = $this->dumpValue($value);
}
if (null !== $definition->getFactoryMethod()) {
if (null !== $definition->getFactoryClass()) {
return sprintf(" $return{$instantiation}call_user_func(array(%s, '%s')%s);\n", $this->dumpValue($definition->getFactoryClass()), $definition->getFactoryMethod(), $arguments ? ', '.implode(', ', $arguments) : '');
}
if (null !== $definition->getFactoryService()) {
return sprintf(" $return{$instantiation}%s->%s(%s);\n", $this->getServiceCall($definition->getFactoryService()), $definition->getFactoryMethod(), implode(', ', $arguments));
}
throw new RuntimeException('Factory method requires a factory service or factory class in service definition for '.$id);
}
if (false !== strpos($class, '$')) {
return sprintf(" \$class = %s;\n\n $return{$instantiation}new \$class(%s);\n", $class, implode(', ', $arguments));
}
return sprintf(" $return{$instantiation}new \\%s(%s);\n", substr(str_replace('\\\\', '\\', $class), 1, -1), implode(', ', $arguments));
}
/**
* Adds the class headers.
*

View File

@ -61,6 +61,20 @@ class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $def->getProperties());
}
public function testStrictFlagIsPreserved()
{
$container = new ContainerBuilder();
$container->register('bar');
$def = $container
->register('foo')
->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
;
$this->process($container);
$this->assertFalse($def->getArgument(0)->isStrict());
}
protected function process(ContainerBuilder $container)
{
$pass = new ResolveInvalidReferencesPass();

View File

@ -204,6 +204,21 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
return count($this->children);
}
/**
* {@inheritdoc}
*/
public function getFormConfig()
{
$config = parent::getFormConfig();
$config->factory = null;
$config->parent = null;
$config->children = array();
$config->unresolvedChildren = array();
return $config;
}
/**
* {@inheritdoc}
*/

View File

@ -11,7 +11,7 @@
<target>Den oploadede fil var for stor. Opload venligst en mindre fil.</target>
</trans-unit>
<trans-unit id="30">
<source>The CSRF token is invalid.</source>
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
<target>CSRF nøglen er ugyldig.</target>
</trans-unit>
</body>

View File

@ -239,6 +239,30 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
$this->builder->create('bar', 'text');
}
public function testGetFormConfigErasesReferences()
{
$builder = new FormBuilder('name', null, $this->dispatcher, $this->factory);
$builder->setParent(new FormBuilder('parent', null, $this->dispatcher, $this->factory));
$builder->add(new FormBuilder('child', null, $this->dispatcher, $this->factory));
$config = $builder->getFormConfig();
$reflClass = new \ReflectionClass($config);
$factory = $reflClass->getProperty('factory');
$parent = $reflClass->getProperty('parent');
$children = $reflClass->getProperty('children');
$unresolvedChildren = $reflClass->getProperty('unresolvedChildren');
$factory->setAccessible(true);
$parent->setAccessible(true);
$children->setAccessible(true);
$unresolvedChildren->setAccessible(true);
$this->assertNull($factory->getValue($config));
$this->assertNull($parent->getValue($config));
$this->assertEmpty($children->getValue($config));
$this->assertEmpty($unresolvedChildren->getValue($config));
}
private function getFormBuilder($name = 'name')
{
$mock = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')

View File

@ -45,7 +45,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
*/
public static function isSupported()
{
return !defined('PHP_WINDOWS_VERSION_BUILD');
return !defined('PHP_WINDOWS_VERSION_BUILD') && function_exists('passthru') && function_exists('escapeshellarg');
}
/**

View File

@ -1404,7 +1404,8 @@ class Request
* Returns true if the request is a XMLHttpRequest.
*
* It works if your JavaScript library set an X-Requested-With HTTP header.
* It is known to work with Prototype, Mootools, jQuery.
* It is known to work with common JavaScript frameworks:
* @link http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
*
* @return Boolean true if the request is an XMLHttpRequest, false otherwise
*

View File

@ -177,6 +177,11 @@ class FlashBag implements FlashBagInterface, \IteratorAggregate, \Countable
/**
* Returns the number of flashes.
*
* This method does not work.
*
* @deprecated in 2.2, removed in 2.3
* @see https://github.com/symfony/symfony/issues/6408
*
* @return int The number of flashes
*/
public function count()

View File

@ -15,7 +15,7 @@ namespace Symfony\Component\Security\Tests\Core\Util
class ClassUtilsTest extends \PHPUnit_Framework_TestCase
{
static public function dataGetClass()
public static function dataGetClass()
{
return array(
array('stdClass', 'stdClass'),