8000 Merge branch '2.1' into 2.2 · symfony/symfony@0d7593c · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d7593c

Browse files
committed
Merge branch '2.1' into 2.2
* 2.1: sub-requests are now created with the same class as their parent [FrameworkBundle] removed BC break [FrameworkBundle] changed temp kernel name in cache:clear [DoctrineBridge] Avoids blob values to be logged by doctrine [Security] use current request attributes to generate redirect url? [Validator] fix showing wrong max file size for upload errors [TwigBridge] removed double var initialization (refs #7344) [2.1][TwigBridge] Fixes Issue #7342 in TwigBridge [FrameworkBundle] fixed cahe:clear command's warmup [TwigBridge] now enter/leave scope on Twig_Node_Module [TwigBridge] fixed fixed scope & trans_default_domain node visitor [TwigBridge] fixed non probant tests & added new one [BrowserKit] added ability to ignored malformed set-cookie header [Translation] removed wriong 'use' [Translation] added xliff loader/dumper with resname support [TwigBridge] fixes Conflicts: src/Symfony/Bundle/FrameworkBundle/HttpKernel.php src/Symfony/Component/Security/Http/HttpUtils.php src/Symfony/Component/Translation/Loader/XliffFileLoader.php src/Symfony/Component/Translation/Tests/Loader/XliffFileLoaderTest.php
2 parents edd9a4e + 4ae667d commit 0d7593c

File tree

21 files changed

+456
-102
lines changed

21 files changed

+456
-102
lines changed

src/Symfony/Bridge/Doctrine/Logger/DbalLogger.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
*/
2323
class DbalLogger implements SQLLogger
2424
{
25+
const MAX_STRING_LENGTH = 32;
26+
const BINARY_DATA_VALUE = '(binary value)';
27+
2528
protected $logger;
2629
protected $stopwatch;
2730

@@ -46,6 +49,26 @@ public function startQuery($sql, array $params = null, array $types = null)
4649
$this->stopwatch->start('doctrine', 'doctrine');
4750
}
4851

52+
if (is_array($params)) {
53+
foreach ($params as $index => $param) {
54+
if (!is_string($params[$index])) {
55+
continue;
56+
}
57+
58+
// non utf-8 strings break json encoding
59+
if (null === preg_match('#[^\p{L}\p{N} ]#u', $params[$index])) {
60+
$params[$index] = self::BINARY_DATA_VALUE;
61+
continue;
62+
}
63+
64+
// too long string must be shorten
65+
if (self::MAX_STRING_LENGTH < strlen($params[$index])) {
66+
$params[$index] = substr($params[$index], self::MAX_STRING_LENGTH - 6).' [...]';
67+
continue;
68+
}
69+
}
70+
}
71+
4972
if (null !== $this->logger) {
5073
$this->log($sql, null === $params ? array() : $params);
5174
}

src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
3333
protected function getExtensions()
3434
{
3535
$manager = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
36+
3637
$manager->expects($this->any())
3738
->method('getManager')
3839
->will($this->returnValue($this->em));
3940

41+
$manager->expects($this->any())
42+
->method('getManagerForClass')
43+
->will($this->returnValue($this->em));
44+
4045
return array(
4146
new CoreExtension(),
4247
new DoctrineOrmExtension($manager)

src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Logger;
1313

14+
use Symfony\Bridge\Doctrine\Logger\DbalLogger;
15+
1416
class DbalLoggerTest extends \PHPUnit_Framework_TestCase
1517
{
1618
/**
@@ -59,12 +61,38 @@ public function testLogNonUtf8()
5961
$dbalLogger
6062
->expects($this->once())
6163
->method('log')
62-
->with('SQL', array('utf8' => 'foo', 'nonutf8' => "\x7F\xFF"))
64+
->with('SQL', array('utf8' => 'foo', 'nonutf8' => DbalLogger::BINARY_DATA_VALUE))
6365
;
6466

6567
$dbalLogger->startQuery('SQL', array(
6668
'utf8' => 'foo',
67-
'nonutf8' => "\x7F\xFF"
69+
'nonutf8' => "\x7F\xFF",
70+
));
71+
}
72+
73+
public function testLogLongString()
74+
{
75+
$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');
76+
77+
$dbalLogger = $this
78+
->getMockBuilder('Symfony\\Bridge\\Doctrine\\Logger\\DbalLogger')
79+
->setConstructorArgs(array($logger, null))
80+
->setMethods(array('log'))
81+
->getMock()
82+
;
83+
84+
$shortString = str_repeat('a', DbalLogger::MAX_STRING_LENGTH);
85+
$longString = str_repeat('a', DbalLogger::MAX_STRING_LENGTH + 1);
86+
87+
$dbalLogger
88+
->expects($this->once())
89+
->method('log')
90+
->with('SQL', array('short' => $shortString, 'long' => substr($longString, DbalLogger::MAX_STRING_LENGTH - 6).' [...]'))
91+
;
92+
93+
$dbalLogger->startQuery('SQL', array(
94+
'short' => $shortString,
95+
'long' => $longString,
6896
));
6997
}
7098
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Twig\NodeVisitor;
4+
5+
/**
6+
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
7+
*/
8+
class Scope
9+
{
10+
/**
11+
* @var Scope|null
12+
*/
13+
private $parent;
14+
15+
/**
16+
* @var Scope[]
17+
*/
18+
private $children;
19+
20+
/**
21+
* @var array
22+
*/
23+
private $data;
24+
25+
/**
26+
* @var boolean
27+
*/
28+
private $left;
29+
30+
/**
31+
* @param Scope $parent
32+
*/
33+
public function __construct(Scope $parent = null)
34+
{
35+
$this->parent = $parent;
36+
$this->left = false;
37+
$this->data = array();
38+
}
39+
40+
/**
41+
* Opens a new child scope.
42+
*
43+
* @return Scope
44+
*/
45+
public function enter()
46+
{
47+
$child = new self($this);
48+
$this->children[] = $child;
49+
50+
return $child;
51+
}
52+
53+
/**
54+
* Closes current scope and returns parent one.
55+
*
56+
* @return Scope|null
57+
*/
58+
public function leave()
59+
{
60+
$this->left = true;
61+
62+
return $this->parent;
63+
}
64+
65+
/**
66+
* Stores data into current scope.
67+
*
68+
* @param string $key
69+
* @param mixed $value
70+
*
71+
* @throws \LogicException
10000
72+
*
73+
* @return Scope Current scope
74+
*/
75+
public function set($key, $value)
76+
{
77+
if ($this->left) {
78+
throw new \LogicException('Left scope is not mutable.');
79+
}
80+
81+
$this->data[$key] = $value;
82+
83+
return $this;
84+
}
85+
86+
/**
87+
* Tests if a data is visible from current scope.
88+
*
89+
* @param string $key
90+
*
91+
* @return boolean
92+
*/
93+
public function has($key)
94+
{
95+
if (array_key_exists($key, $this->data)) {
96+
return true;
97+
}
98+
99+
if (null === $this->parent) {
100+
return false;
101+
}
102+
103+
return $this->parent->has($key);
104+
}
105+
106+
/**
107+
* Returns data visible from current scope.
108+
*
109+
* @param string $key
110+
* @param mixed $default
111+
*
112+
* @return mixed
113+
*/
114+
public function get($key, $default = null)
115+
{
116+
if (array_key_exists($key, $this->data)) {
117+
return $this->data[$key];
118+
}
119+
120+
if (null === $this->parent) {
121+
return $default;
122+
}
123+
124+
return $this->parent->get($key, $default);
125+
}
126+
}

src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,43 @@
2121
*/
2222
class TranslationDefaultDomainNodeVisitor implements \Twig_NodeVisitorInterface
2323
{
24-
private $domain;
24+
/**
25+
* @var Scope
26+
*/
27+
private $scope;
28+
29+
/**
30+
* Constructor.
31+
*/
32+
public function __construct()
33+
{
34+
$this->scope = new Scope();
35+
}
2536

2637
/**
2738
* {@inheritdoc}
2839
*/
2940
public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
3041
{
31-
if ($node instanceof \Twig_Node_Module) {
32-
$this->domain = null;
42+
if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
43+
$this->scope = $this->scope->enter();
3344
}
3445

3546
if ($node instanceof TransDefaultDomainNode) {
3647
if ($node->getNode('expr') instanceof \Twig_Node_Expression_Constant) {
37-
$this->domain = $node->getNode('expr');
48+
$this->scope->set('domain', $node->getNode('expr'));
3849

3950
return $node;
4051
} else {
4152
$var = $env->getParser()->getVarName();
4253
$name = new \Twig_Node_Expression_AssignName($var, $node->getLine());
43-
$this->domain = new \Twig_Node_Expression_Name($var, $node->getLine());
54+
$this->scope->set('domain', new \Twig_Node_Expression_Name($var, $node->getLine()));
4455

4556
return new \Twig_Node_Set(false, new \Twig_Node(array($name)), new \Twig_Node(array($node->getNode('expr'))), $node->getLine());
4657
}
4758
}
4859

49-
if (null === $this->domain) {
60+
if (!$this->scope->has('domain')) {
5061
return $node;
5162
}
5263

@@ -58,11 +69,11 @@ public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
5869
$arguments->setNode($ind - 1, new \Twig_Node_Expression_Array(array(), $node->getLine()));
5970
}
6071

61-
$arguments->setNode($ind, $this->domain);
72+
$arguments->setNode($ind, $this->scope->get('domain'));
6273
}
6374
} elseif ($node instanceof TransNode) {
6475
if (null === $node->getNode('domain')) {
65-
$node->setNode('domain', $this->domain);
76+
$node->setNode('domain', $this->scope->get('domain'));
6677
}
6778
}
6879

@@ -78,6 +89,10 @@ public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
7889
return false;
7990
}
8091

92+
if ($node instanceof \Twig_Node_Block || $node instanceof \Twig_Node_Module) {
93+
$this->scope = $this->scope->leave();
94+
}
95+
8196
return $node;
8297
}
8398

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Twig\Tests\NodeVisitor;
4+
5+
use Symfony\Bridge\Twig\NodeVisitor\Scope;
6+
use Symfony\Bridge\Twig\Tests\TestCase;
7+
8+
class ScopeTest extends TestCase
9+
{
10+
public function testScopeInitiation()
11+
{
12+
$scope = new Scope();
13+
$scope->enter();
14+
$this->assertNull($scope->get('test'));
15+
}
16+
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TranslationDefaultDomainNodeVisitorTest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ class TranslationDefaultDomainNodeVisitorTest extends TestCase
1515
public function testDefaultDomainAssignment(\Twig_Node $node)
1616
{
1717
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
18-
1918
$visitor = new TranslationDefaultDomainNodeVisitor();
2019

2120
// visit trans_default_domain tag
22-
$defaultDomain = TwigNodeProvider::getTransDefaultDomainTag('domain');
21+
$defaultDomain = TwigNodeProvider::getTransDefaultDomainTag(self::$domain);
2322
$visitor->enterNode($defaultDomain, $env);
2423
$visitor->leaveNode($defaultDomain, $env);
2524

@@ -38,12 +37,38 @@ public function testDefaultDomainAssignment(\Twig_Node $node)
3837
$this->assertEquals(array(array(self::$message, self::$domain)), $visitor->getMessages());
3938
}
4039

40+
/** @dataProvider getDefaultDomainAssignmentTestData */
41+
public function testNewModuleWithoutDefaultDomainTag(\Twig_Node $node)
42+
{
43+
$env = new \Twig_Environment(new \Twig_Loader_String(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
44+
$visitor = new TranslationDefaultDomainNodeVisitor();
45+
46+
// visit trans_default_domain tag
47+
$newModule = TwigNodeProvider::getModule('test');
48+
$visitor->enterNode($newModule, $env);
49+
$visitor->leaveNode($newModule, $env);
50+
51+
// visit tested node
52+
$enteredNode = $visitor->enterNode($node, $env);
53+
$leavedNode = $visitor->leaveNode($node, $env);
54+
$this->assertSame($node, $enteredNode);
55+
$this->assertSame($node, $leavedNode);
56+
57+
// extracting tested node messages
58+
$visitor = new TranslationNodeVisitor();
59+
$visitor->enable();
60+
$visitor->enterNode($node, $env);
61+
$visitor->leaveNode($node, $env);
62+
63+
$this->assertEquals(array(array(self::$message, null)), $visitor->getMessages());
64+
}
65+
4166
public function getDefaultDomainAssignmentTestData()
4267
{
4368
return array(
44-
array(TwigNodeProvider::getTransFilter(self::$message, self::$domain)),
45-
array(TwigNodeProvider::getTransChoiceFilter(self::$message, self::$domain)),
46-
array(TwigNodeProvider::getTransTag(self::$message, self::$domain)),
69+
array(TwigNodeProvider::getTransFilter(self::$message)),
70+
array(TwigNodeProvider::getTransChoiceFilter(self::$message)),
71+
array(TwigNodeProvider::getTransTag(self::$message)),
4772
);
4873
}
4974
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77

88
class TwigNodeProvider
99
{
10+
public static function getModule($content)
11+
{
12+
return new \Twig_Node_Module(
13+
new \Twig_Node_Expression_Constant($content, 0),
14+
null,
15+
new \Twig_Node_Expression_Array(array(), 0),
16+
new \Twig_Node_Expression_Array(array(), 0),
17+
new \Twig_Node_Expression_Array(array(), 0),
18+
null,
19+
null
20+
);
21+
}
22+
1023
public static function getTransFilter($message, $domain = null)
1124
{
1225
$arguments = $domain ? array(

0 commit comments

Comments
 (0)
0