Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fd12796

Browse files
committed
merged 2.0
2 parents 76ba2bc + e9ddd39 commit fd12796

File tree

11 files changed

+441
-43
lines changed

11 files changed

+441
-43
lines changed

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(ManagerRegistry $registry, DbalLogger $logger = null
4141
public function collect(Request $request, Response $response, \Exception $exception = null)
4242
{
4343
$this->data = array(
44-
'queries' => null !== $this->logger ? $this->logger->queries : array(),
44+
'queries' => null !== $this->logger ? $this->sanitizeQueries($this->logger->queries) : array(),
4545
'connections' => $this->connections,
4646
'managers' => $this->managers,
4747
);
@@ -84,4 +84,49 @@ public function getName()
8484
{
8585
return 'db';
8686
}
87+
88+
private function sanitizeQueries($queries)
89+
{
90+
foreach ($queries as $i => $query) {
91+
foreach ($query['params'] as $j => $param) {
92+
$queries[$i]['params'][$j] = $this->varToString($param);
93+
}
94+
}
95+
96+
return $queries;
97+
}
98+
99+
private function varToString($var)
100+
{
101+
if (is_object($var)) {
102+
return sprintf('Object(%s)', get_class($var));
103+
}
104+
105+
if (is_array($var)) {
106+
$a = array();
107+
foreach ($var as $k => $v) {
108+
$a[] = sprintf('%s => %s', $k, $this->varToString($v));
109+
}
110+
111+
return sprintf("Array(%s)", implode(', ', $a));
112+
}
113+
114+
if (is_resource($var)) {
115+
return sprintf('Resource(%s)', get_resource_type($var));
116+
}
117+
118+
if (null === $var) {
119+
return 'null';
120+
}
121+
122+
if (false === $var) {
123+
return 'false';
124+
}
125+
126+
if (true === $var) {
127+
return 'true';
128+
}
129+
130+
return (string) $var;
131+
}
87132
}

src/Symfony/Bundle/DoctrineBundle/Resources/views/Collector/db.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<code>{{ query.sql }}</code>
3737
</div>
3838
<small>
39-
<strong>Parameters</strong>: {{ query.params|yaml_encode }}<br />
39+
<strong>Parameters</strong>: {{ query.params }}<br />
4040
<strong>Time</strong>: {{ '%0.2f'|format(query.executionMS * 1000) }} ms
4141
</small>
4242
</li>

src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
2828
*/
2929
private $container;
3030

31+
/**
32+
* @return ContainerInterface
33+
*/
3134
protected function getContainer()
3235
{
3336
if (null === $this->container) {

src/Symfony/Component/DependencyInjection/Reference.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Reference
3535
*/
3636
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict = true)
3737
{
38-
$this->id = $id;
38+
$this->id = strtolower($id);
3939
$this->invalidBehavior = $invalidBehavior;
4040
$this->strict = $strict;
4141
}

src/Symfony/Component/HttpKernel/Util/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function rename($origin, $target)
133133
{
134134
// we check that target does not exist
135135
if (is_readable($target)) {
136-
throw new \RuntimeException(sprintf('Cannot rename because the target "%" already exist.', $target));
136+
throw new \RuntimeException(sprintf('Cannot rename because the target "%s" already exist.', $target));
137137
}
138138

139139
rename($origin, $target);

src/Symfony/Component/Locale/Stub/StubNumberFormatter.php

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,20 @@ class StubNumberFormatter
203203
* The maximum values of the integer type in 32 bit platforms.
204204
* @var array
205205
*/
206-
static private $intRange = array(
206+
static private $int32Range = array(
207207
'positive' => 2147483647,
208208
'negative' => -2147483648
209209
);
210210

211+
/**
212+
* The maximum values of the integer type in 64 bit platforms.
213+
* @var array
214+
*/
215+
static private $int64Range = array(
216+
'positive' => 9223372036854775807,
217+
'negative' => -9223372036854775808
218+
);
219+
211220
/**
212221
* @var string
213222
*/
@@ -450,7 +459,6 @@ public function parseCurrency($value, &$currency, &$position = null)
450459
* @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended
451460
* @return Boolean|string The parsed value of false on error
452461
* @see http://www.php.net/manual/en/numberformatter.parse.php
453-
* @throws MethodArgumentValueNotImplementedException When $type equals to TYPE_INT64, behavior not implemented
454462
* @throws MethodArgumentNotImplementedException When $position different than null, behavior not implemented
455463
*/
456464
public function parse($value, $type = self::TYPE_DOUBLE, &$position = null)
@@ -461,11 +469,6 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = null)
461469
return false;
462470
}
463471

464-
// Not implemented, the NumberFormatter behavior is inconsistency
465-
if ($type == self::TYPE_INT64) {
466-
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'type', $type);
467-
}
468-
469472
// We don't calculate the position when parsing the value
470473
if (null !== $position) {
471474
throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
@@ -719,9 +722,10 @@ private function convertValueDataType($value, $type)
719722
{
720723
if ($type == self::TYPE_DOUBLE) {
721724
$value = (float) $value;
722-
}
723-
elseif ($type == self::TYPE_INT32) {
724-
$value = $this->getIntValue($value);
725+
} elseif ($type == self::TYPE_INT32) {
726+
$value = $this->getInt32Value($value);
727+
} elseif ($type == self::TYPE_INT64) {
728+
$value = $this->getInt64Value($value);
725729
}
726730

727731
return $value;
@@ -733,12 +737,35 @@ private function convertValueDataType($value, $type)
733737
* @param mixed $value The value to be converted
734738
* @return int The converted value
735739
*/
736-
private function getIntValue($value)
740+
private function getInt32Value($value)
741+
{
742+
if ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative']) {
743+
return false;
744+
}
745+
746+
return (int) $value;
747+
}
748+
749+
/**
750+
* Convert the value data type to int or returns false if the value is out of the integer value range.
751+
*
752+
* @param mixed $value The value to be converted
753+
* @return int|float The converted value
754+
*/
755+
private function getInt64Value($value)
737756
{
738-
if ($value > self::$intRange['positive'] || $value < self::$intRange['negative']) {
757+
if ($value > self::$int64Range['positive'] || $value < self::$int64Range['negative']) {
739758
return false;
740759
}
741760

761+
if (PHP_INT_SIZE !== 8 && ($value > self::$int32Range['positive'] || $value <= self::$int32Range['negative'])) {
762+
return (float) $value;
763+
}
764+
765+
if (PHP_INT_SIZE === 8 && ($value > self::$int32Range['positive'] || $value < self::$int32Range['negative'])) {
766+
$value = (-2147483648 - ($value % -2147483648)) * ($value / abs($value));
767+
}
768+
742769
return (int) $value;
743770
}
744771

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Tests\Bridge\Doctrine\DataCollector;
13+
14+
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
15+
use Symfony\Component\HttpFoundation\Request;
16+
use Symfony\Component\HttpFoundation\Response;
17+
18+
class DoctrineDataCollectorTest extends \PHPUnit_Framework_TestCase
19+
{
20+
public function testCollectConnections()
21+
{
22+
$c = $this->createCollector(array());
23+
$c->collect(new Request(), new Response());
24+
$this->assertEquals(array('default' => 'doctrine.dbal.default_connection'), $c->getConnections());
25+
}
26+
27+
public function testCollectManagers()
28+
{
29+
$c = $this->createCollector(array());
30+
$c->collect(new Request(), new Response());
31+
$this->assertEquals(array('default' => 'doctrine.orm.default_entity_manager'), $c->getManagers());
32+
}
33+
34+
public function testCollectQueryCount()
35+
{
36+
$c = $this->createCollector(array());
37+
$c->collect(new Request(), new Response());
38+
$this->assertEquals(0, $c->getQueryCount());
39+
40+
$queries = array(
41+
array('sql' => "SELECT * FROM table1", 'params' => array(), 'types' => array(), 'executionMS' => 0)
42+
);
43+
$c = $this->createCollector($queries);
44+
$c->collect(new Request(), new Response());
45+
$this->assertEquals(1, $c->getQueryCount());
46+
}
47+
48+
public function testCollectTime()
49+
{
50+
$c = $this->createCollector(array());
51+
$c->collect(new Request(), new Response());
52+
$this->assertEquals(0, $c->getTime());
53+
54+
$queries = array(
55+
array('sql' => "SELECT * FROM table1", 'params' => array(), 'types' => array(), 'executionMS' => 1)
56+
);
57+
$c = $this->createCollector($queries);
58+
$c->collect(new Request(), new Response());
59+
$this->assertEquals(1, $c->getTime());
60+
61+
$queries = array(
62+
array('sql' => "SELECT * FROM table1", 'params' => array(), 'types' => array(), 'executionMS' => 1),
63+
array('sql' => "SELECT * FROM table2", 'params' => array(), 'types' => array(), 'executionMS' => 2)
64+
);
65+
$c = $this->createCollector($queries);
66+
$c->collect(new Request(), new Response());
67+
$this->assertEquals(3, $c->getTime());
68+
}
69+
70+
/**
71+
* @dataProvider paramProvider
72+
*/
73+
public function testCollectQueries($param, $expected)
74+
{
75+
$queries = array(
76+
array('sql' => "SELECT * FROM table1 WHERE field1 = ?1", 'params' => array($param), 'types' => array(), 'executionMS' => 1)
77+
);
78+
$c = $this->createCollector($queries);
79+
$c->collect(new Request(), new Response());
80+
81+
$collected_queries = $c->getQueries();
82+
$this->assertEquals($expected, $collected_queries[0]['params'][0]);
83+
}
84+
85+
/**
86+
* @dataProvider paramProvider
87+
*/
88+
public function testSerialization($param, $expected)
89+
{
90+
$queries = array(
91+
array('sql' => "SELECT * FROM table1 WHERE field1 = ?1", 'params' => array($param), 'types' => array(), 'executionMS' => 1)
92+
);
93+
$c = $this->createCollector($queries);
94+
$c->collect(new Request(), new Response());
95+
$c = unserialize(serialize($c));
96+
97+
$collected_queries = $c->getQueries();
98+
$this->assertEquals($expected, $collected_queries[0]['params'][0]);
99+
}
100+
101+
public function paramProvider()
102+
{
103+
return array(
104+
array('some value', 'some value'),
105+
array(1, '1'),
106+
array(true, 'true'),
107+
array(null, 'null'),
108+
array(new \stdClass(), 'Object(stdClass)'),
109+
array(fopen(__FILE__, 'r'), 'Resource(stream)'),
110+
array(new \SplFileInfo(__FILE__), 'Object(SplFileInfo)'),
111+
);
112+
}
113+
114+
private function createCollector($queries)
115+
{
116+
$registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry');
117+
$registry
118+
->expects($this->any())
119+
->method('getConnectionNames')
120+
->will($this->returnValue(array('default' => 'doctrine.dbal.default_connection')));
121+
$registry
122+
->expects($this->any())
123+
->method('getManagerNames')
124+
->will($this->returnValue(array('default' => 'doctrine.orm.default_entity_manager')));
125+
126+
$logger = $this->getMock('Symfony\Bridge\Doctrine\Logger\DbalLogger');
127+
$logger->queries = $queries;
128+
129+
return new DoctrineDataCollector($registry, $logger);
130+
}
131+
}

tests/Symfony/Tests/Component/DependencyInjection/ReferenceTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ public function testConstructor()
2323
$ref = new Reference('foo');
2424
$this->assertEquals('foo', (string) $ref, '__construct() sets the id of the reference, which is used for the __toString() method');
2525
}
26+
27+
public function testCaseInsensitive()
28+
{
29+
$ref = new Reference('FooBar');
30+
$this->assertEquals('foobar', (string) $ref, 'the id is lowercased as the container is case insensitive');
31+
}
2632
}

0 commit comments

Comments
 (0)