merged 2.0
This commit is contained in:
commit
b1148e334f
@ -14,9 +14,9 @@ namespace Symfony\Component\Config\Definition;
|
|||||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This node represents a variable value in the config tree.
|
* This node represents a value of variable type in the config tree.
|
||||||
*
|
*
|
||||||
* This node is intended for arbitrary variables.
|
* This node is intended for values of arbitrary type.
|
||||||
* Any PHP type is accepted as a value.
|
* Any PHP type is accepted as a value.
|
||||||
*
|
*
|
||||||
* @author Jeremy Mikola <jmikola@gmail.com>
|
* @author Jeremy Mikola <jmikola@gmail.com>
|
||||||
|
@ -139,7 +139,7 @@ class ParameterBag implements ParameterBagInterface
|
|||||||
foreach ($this->parameters as $key => $value) {
|
foreach ($this->parameters as $key => $value) {
|
||||||
try {
|
try {
|
||||||
$value = $this->resolveValue($value);
|
$value = $this->resolveValue($value);
|
||||||
$parameters[$key] = is_string($value) ? str_replace('%%', '%', $value) : $value;
|
$parameters[$key] = $this->unescapeValue($value);
|
||||||
} catch (ParameterNotFoundException $e) {
|
} catch (ParameterNotFoundException $e) {
|
||||||
$e->setSourceKey($key);
|
$e->setSourceKey($key);
|
||||||
|
|
||||||
@ -235,4 +235,22 @@ class ParameterBag implements ParameterBagInterface
|
|||||||
{
|
{
|
||||||
return $this->resolved;
|
return $this->resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function unescapeValue($value)
|
||||||
|
{
|
||||||
|
if (is_string($value)) {
|
||||||
|
return str_replace('%%', '%', $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($value)) {
|
||||||
|
$result = array();
|
||||||
|
foreach ($value as $k => $v) {
|
||||||
|
$result[$k] = $this->unescapeValue($v);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ class MoneyType extends AbstractType
|
|||||||
|
|
||||||
// the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
|
// the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)
|
||||||
|
|
||||||
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches);
|
preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123(?:[,.]0+)?[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches);
|
||||||
|
|
||||||
if (!empty($matches[1])) {
|
if (!empty($matches[1])) {
|
||||||
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
|
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';
|
||||||
|
@ -154,6 +154,7 @@ class Esi
|
|||||||
|
|
||||||
// we don't use a proper XML parser here as we can have ESI tags in a plain text response
|
// we don't use a proper XML parser here as we can have ESI tags in a plain text response
|
||||||
$content = $response->getContent();
|
$content = $response->getContent();
|
||||||
|
$content = str_replace(array('<?', '<%'), array('<?php echo "<?"; ?>', '<?php echo "<%"; ?>'), $content);
|
||||||
$content = preg_replace_callback('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', array($this, 'handleEsiIncludeTag'), $content);
|
$content = preg_replace_callback('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#', array($this, 'handleEsiIncludeTag'), $content);
|
||||||
$content = preg_replace('#<esi\:comment[^>]*(?:/|</esi\:comment)>#', '', $content);
|
$content = preg_replace('#<esi\:comment[^>]*(?:/|</esi\:comment)>#', '', $content);
|
||||||
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#', '', $content);
|
$content = preg_replace('#<esi\:remove>.*?</esi\:remove>#', '', $content);
|
||||||
|
@ -45,6 +45,33 @@ class EntityChoiceListTest extends DoctrineOrmTestCase
|
|||||||
$this->em = null;
|
$this->em = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
|
* @expectedMessage Entity "Symfony\Tests\Bridge\Doctrine\Fixtures\SingleIdentEntity" passed to the choice field must have a "__toString()" method defined (or you can also override the "property" option).
|
||||||
|
*/
|
||||||
|
public function testEntitesMustHaveAToStringMethod()
|
||||||
|
{
|
||||||
|
$entity1 = new SingleIdentEntity(1, 'Foo');
|
||||||
|
$entity2 = new SingleIdentEntity(2, 'Bar');
|
||||||
|
|
||||||
|
// Persist for managed state
|
||||||
|
$this->em->persist($entity1);
|
||||||
|
$this->em->persist($entity2);
|
||||||
|
|
||||||
|
$choiceList = new EntityChoiceList(
|
||||||
|
$this->em,
|
||||||
|
self::SINGLE_IDENT_CLASS,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
array(
|
||||||
|
$entity1,
|
||||||
|
$entity2,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$choiceList->getEntities();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Symfony\Component\Form\Exception\FormException
|
* @expectedException Symfony\Component\Form\Exception\FormException
|
||||||
*/
|
*/
|
||||||
|
@ -94,6 +94,7 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays');
|
$this->assertEquals(array('bar' => array('bar' => array('bar' => 'bar'))), $bag->resolveValue(array('%foo%' => array('%foo%' => array('%foo%' => '%foo%')))), '->resolveValue() replaces placeholders in nested arrays');
|
||||||
$this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it');
|
$this->assertEquals('I\'m a %%foo%%', $bag->resolveValue('I\'m a %%foo%%'), '->resolveValue() supports % escaping by doubling it');
|
||||||
$this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it');
|
$this->assertEquals('I\'m a bar %%foo bar', $bag->resolveValue('I\'m a %foo% %%foo %foo%'), '->resolveValue() supports % escaping by doubling it');
|
||||||
|
$this->assertEquals(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar'))), $bag->resolveValue(array('foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')))), '->resolveValue() supports % escaping by doubling it');
|
||||||
|
|
||||||
$bag = new ParameterBag(array('foo' => true));
|
$bag = new ParameterBag(array('foo' => true));
|
||||||
$this->assertTrue($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
|
$this->assertTrue($bag->resolveValue('%foo%'), '->resolveValue() replaces arguments that are just a placeholder by their value without casting them to strings');
|
||||||
@ -165,6 +166,22 @@ class ParameterBagTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve
|
||||||
|
*/
|
||||||
|
public function testResolveUnespacesValue()
|
||||||
|
{
|
||||||
|
$bag = new ParameterBag(array(
|
||||||
|
'foo' => array('bar' => array('ding' => 'I\'m a bar %%foo %%bar')),
|
||||||
|
'bar' => 'I\'m a %%foo%%',
|
||||||
|
));
|
||||||
|
|
||||||
|
$bag->resolve();
|
||||||
|
|
||||||
|
$this->assertEquals('I\'m a %foo%', $bag->get('bar'), '->resolveValue() supports % escaping by doubling it');
|
||||||
|
$this->assertEquals(array('bar' => array('ding' => 'I\'m a bar %foo %bar')), $bag->get('foo'), '->resolveValue() supports % escaping by doubling it');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve
|
* @covers Symfony\Component\DependencyInjection\ParameterBag\ParameterBag::resolve
|
||||||
* @dataProvider stringsWithSpacesProvider
|
* @dataProvider stringsWithSpacesProvider
|
||||||
|
@ -24,4 +24,13 @@ class MoneyTypeTest extends LocalizedTestCase
|
|||||||
|
|
||||||
$this->assertSame('{{ widget }} €', $view->get('money_pattern'));
|
$this->assertSame('{{ widget }} €', $view->get('money_pattern'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testMoneyPatternWorksForYen()
|
||||||
|
{
|
||||||
|
\Locale::setDefault('en_US');
|
||||||
|
|
||||||
|
$form = $this->factory->create('money', null, array('currency' => 'JPY'));
|
||||||
|
$view = $form->createView();
|
||||||
|
$this->assertTrue((Boolean) strstr($view->get('money_pattern'), '¥'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,17 @@ class EsiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('foo <?php echo $this->esi->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
|
$this->assertEquals('foo <?php echo $this->esi->handle($this, \'...\', \'\', false) ?>'."\n", $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testProcessEscapesPhpTags()
|
||||||
|
{
|
||||||
|
$esi = new Esi();
|
||||||
|
|
||||||
|
$request = Request::create('/');
|
||||||
|
$response = new Response('foo <?php die("foo"); ?><%= "lala" %>');
|
||||||
|
$esi->process($request, $response);
|
||||||
|
|
||||||
|
$this->assertEquals('foo <?php echo "<?"; ?>php die("foo"); ?><?php echo "<%"; ?>= "lala" %>', $response->getContent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException RuntimeException
|
* @expectedException RuntimeException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user