10000 Merge branch '2.3' into 2.7 · symfony/symfony@8d7b19f · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d7b19f

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Fixed correct class name in thrown exception Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memory manager will not release small buckets to OS automatically Removed a duplicated test in CardSchemeValidatorTest Fix perf and mem issue when using token_get_all [SecurityBundle] fix SecureRandom service constructor args Normalize params only when used.
2 parents 0f6a32d + 7d72f93 commit 8d7b19f

File tree

11 files changed

+69
-47
lines changed

11 files changed

+69
-47
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,8 @@ public function startQuery($sql, array $params = null, array $types = null)
4949
$this->stopwatch->start('doctrine', 'doctrine');
5050
}
5151

52-
if (is_array($params)) {
53-
$params = $this->normalizeParams($params);
54-
}
55-
5652
if (null !== $this->logger) {
57-
$this->log($sql, null === $params ? array() : $params);
53+
$this->log($sql, null === $params ? array() : $this->normalizeParams($params));
5854
}
5955
}
6056

src/Symfony/Bundle/FrameworkBundle/Resources/config/security.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
</parameters>
1010

1111
<services>
12-
<!-- Pseudo-Random Number Generator -->
13-
<service id="security.secure_random" class="%security.secure_random.class%">
14-
<tag name="monolog.logger" channel="security" />
15-
<argument>%kernel.cache_dir%/secure_random.seed</argument>
16-
<argument type="service" id="logger" on-invalid="ignore" />
17-
</service>
12+
<!-- Pseudorandom Number Generator -->
13+
<service id="security.secure_random" class="Symfony\Component\Security\Core\Util\SecureRandom" />
1814
</services>
1915
</container>

src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function extract($resource, MessageCatalogue $catalog)
6060
$files = $this->extractFiles($resource);
6161
foreach ($files as $file) {
6262
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
63+
64+
if (PHP_VERSION_ID >= 70000) {
65+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
66+
gc_mem_caches();
67+
}
6368
}
6469
}
6570

@@ -80,7 +85,7 @@ public function setPrefix($prefix)
8085
*/
8186
protected function normalizeToken($token)
8287
{
83-
if (is_array($token)) {
88+
if (isset($token[1]) && 'b"' !== $token) {
8489
return $token[1];
8590
}
8691

@@ -94,7 +99,7 @@ private function seekToNextRelevantToken(\Iterator $tokenIterator)
9499
{
95100
for (; $tokenIterator->valid(); $tokenIterator->next()) {
96101
$t = $tokenIterator->current();
97-
if (!is_array($t) || ($t[0] !== T_WHITESPACE)) {
102+
if (T_WHITESPACE !== $t[0]) {
98103
break;
99104
}
100105
}
@@ -111,7 +116,7 @@ private function getMessage(\Iterator $tokenIterator)
111116

112117
for (; $tokenIterator->valid(); $tokenIterator->next()) {
113118
$t = $tokenIterator->current();
114-
if (!is_array($t)) {
119+
if (!isset($t[1])) {
115120
break;
116121
}
117122

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.9",
20-
"symfony/security": "~2.7",
20+
"symfony/security": "~2.7.9|~2.8",
2121
"symfony/security-acl": "~2.7",
2222
"symfony/http-kernel": "~2.2"
2323
},

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ public static function fixNamespaceDeclarations($source)
149149
$inNamespace = false;
150150
$tokens = token_get_all($source);
151151

152-
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
153-
if (is_string($token)) {
152+
for ($i = 0; isset($tokens[$i]); ++$i) {
153+
$token = $tokens[$i];
154+
if (!isset($token[1]) || 'b"' === $token) {
154155
$rawChunk .= $token;
155156
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
156157
// strip comments
@@ -162,21 +163,21 @@ public static function fixNamespaceDeclarations($source)
162163
$rawChunk .= $token[1];
163164

164165
// namespace name and whitespaces
165-
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
166-
$rawChunk .= $t[1];
166+
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
167+
$rawChunk .= $tokens[$i][1];
167168
}
168-
if ('{' === $t) {
169+
if ('{' === $tokens[$i]) {
169170
$inNamespace = false;
170-
prev($tokens);
171+
--$i;
171172
} else {
172173
$rawChunk = rtrim($rawChunk)."\n{";
173174
$inNamespace = true;
174175
}
175176
} elseif (T_START_HEREDOC === $token[0]) {
176177
$output .= self::compressCode($rawChunk).$token[1];
177178
do {
178-
$token = next($tokens);
179-
$output .= is_string($token) ? $token : $token[1];
179+
$token = $tokens[++$i];
180+
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
180181
} while ($token[0] !== T_END_HEREDOC);
181182
$output .= "\n";
182183
$rawChunk = '';
@@ -192,7 +193,15 @@ public static function fixNamespaceDeclarations($source)
192193
$rawChunk .= "}\n";
193194
}
194195

195-
return $output.self::compressCode($rawChunk);
196+
$output .= self::compressCode($rawChunk);
197+
198+
if (PHP_VERSION_ID >= 70000) {
199+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
200+
unset($tokens, $rawChunk);
201+
gc_mem_caches();
202+
}
203+
204+
return $output;
196205
}
197206

198207
/**

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public static function createMap($dir)
7272

7373
$classes = self::findClasses($path);
7474

75+
if (PHP_VERSION_ID >= 70000) {
76+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
77+
gc_mem_caches();
78+
}
79+
7580
foreach ($classes as $class) {
7681
$map[$class] = $path;
7782
}
@@ -95,10 +100,10 @@ private static function findClasses($path)
95100
$classes = array();
96101

97102
$namespace = '';
98-
for ($i = 0, $max = count($tokens); $i < $max; ++$i) {
103+
for ($i = 0; isset($tokens[$i]); ++$i) {
99104
$token = $tokens[$i];
100105

101-
if (is_string($token)) {
106+
if (!isset($token[1])) {
102107
continue;
103108
}
104109

@@ -108,9 +113,9 @@ private static function findClasses($path)
108113
case T_NAMESPACE:
109114
$namespace = '';
110115
// If there is a namespace, extract it
111-
while (($t = $tokens[++$i]) && is_array($t)) {
112-
if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
113-
$namespace .= $t[1];
116+
while (isset($tokens[++$i][1])) {
117+
if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
118+
$namespace .= $tokens[$i][1];
114119
}
115120
}
116121
$namespace .= '\\';
@@ -121,7 +126,7 @@ private static function findClasses($path)
121126
// Skip usage of ::class constant
122127
$isClassConstant = false;
123128
for ($j = $i - 1; $j > 0; --$j) {
124-
if (is_string($tokens[$j])) {
129+
if (!isset($tokens[$j][1])) {
125130
break;
126131
}
127132

@@ -138,10 +143,11 @@ private static function findClasses($path)
138143
}
139144

140145
// Find the classname
141-
while (($t = $tokens[++$i]) && is_array($t)) {
146+
while (isset($tokens[++$i][1])) {
147+
$t = $tokens[$i];
142148
if (T_STRING === $t[0]) {
143149
$class .= $t[1];
144-
} elseif ($class !== '' && T_WHITESPACE == $t[0]) {
150+
} elseif ('' !== $class && T_WHITESPACE === $t[0]) {
145151
break;
146152
}
147153
}

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,15 @@ public static function stripComments($source)
711711
$output = '';
712712
$tokens = token_get_all($source);
713713
$ignoreSpace = false;
714-
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
715-
if (is_string($token)) {
714+
for ($i = 0; isset($tokens[$i]); ++$i) {
715+
$token = $tokens[$i];
716+
if (!isset($token[1]) || 'b"' === $token) {
716717
$rawChunk .= $token;
717718
} elseif (T_START_HEREDOC === $token[0]) {
718719
$output .= $rawChunk.$token[1];
719720
do {
720-
$token = next($tokens);
721-
$output .= $token[1];
721+
$token = $tokens[++$i];
722+
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
722723
} while ($token[0] !== T_END_HEREDOC);
723724
$rawChunk = '';
724725
} elseif (T_WHITESPACE === $token[0]) {
@@ -744,6 +745,12 @@ public static function stripComments($source)
744745

745746
$output .= $rawChunk;
746747

748+
if (PHP_VERSION_ID >= 70000) {
749+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
750+
unset($tokens, $rawChunk);
751+
gc_mem_caches();
752+
}
753+
747754
return $output;
748755
}
749756

src/Symfony/Component/HttpKernel/Tests/KernelTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function testStripComments()
246246
$heredoc = <<<HD
247247
248248
249-
Heredoc should not be modified
249+
Heredoc should not be modified {$a[1+$b]}
250250
251251
252252
HD;
@@ -282,7 +282,7 @@ public function doStuff()
282282
$heredoc = <<<HD
283283
284284
285-
Heredoc should not be modified
285+
Heredoc should not be modified {$a[1+$b]}
286286
287287
288288
HD;

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function load($class, $type = null)
110110

111111
$class = new \ReflectionClass($class);
112112
if ($class->isAbstract()) {
113-
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class));
113+
throw new \InvalidArgumentException(sprintf('Annotations from class "%s" cannot be read as it is abstract.', $class->getName()));
114114
}
115115

116116
$globals = $this->getGlobals($class);

src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function load($file, $type = null)
6464
$collection->addResource(new FileResource($path));
6565
$collection->addCollection($this->loader->load($class, $type));
6666
}
67+
if (PHP_VERSION_ID >= 70000) {
68+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
69+
gc_mem_caches();
70+
}
6771

6872
return $collection;
6973
}
@@ -88,10 +92,10 @@ protected function findClass($file)
8892
$class = false;
8993
$namespace = false;
9094
$tokens = token_get_all(file_get_contents($file));
91-
for ($i = 0, $count = count($tokens); $i < $count; ++$i) {
95+
for ($i = 0; isset($tokens[$i]); ++$i) {
9296
$token = $tokens[$i];
9397

94-
if (!is_array($token)) {
98+
if (!isset($token[1])) {
9599
continue;
96100
}
97101

@@ -100,11 +104,11 @@ protected function findClass($file)
100104
}
101105

102106
if (true === $namespace && T_STRING === $token[0]) {
103-
$namespace = '';
104-
do {
105-
$namespace .= $token[1];
106-
$token = $tokens[++$i];
107-
} while ($i < $count && is_array($token) && in_array($token[0], array(T_NS_SEPARATOR, T_STRING)));
107+
$namespace = $token[1];
108+
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_NS_SEPARATOR, T_STRING))) {
109+
$namespace .= $tokens[$i][1];
110+
}
111+
$token = $tokens[$i];
108112
}
109113

110114
if (T_CLASS === $token[0]) {

src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public function getValidNumbers()
9999
array('MAESTRO', '5020507657408074712'),
100100
array('MAESTRO', '5612559223580173965'),
101101
array('MAESTRO', '6759744069209'),
102-
array('MAESTRO', '6759744069209'),
103102
array('MAESTRO', '6594371785970435599'),
104103
array('MASTERCARD', '5555555555554444'),
105104
array('MASTERCARD', '5105105105105100'),

0 commit comments

Comments
 (0)
0