[HttpKernel] fix public Kernel::stripComments()
This commit is contained in:
parent
7200703089
commit
aab60e33a9
@ -730,17 +730,26 @@ abstract class Kernel implements KernelInterface, TerminableInterface
|
|||||||
return $source;
|
return $source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rawChunk = '';
|
||||||
$output = '';
|
$output = '';
|
||||||
foreach (token_get_all($source) as $token) {
|
$tokens = token_get_all($source);
|
||||||
|
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
|
||||||
if (is_string($token)) {
|
if (is_string($token)) {
|
||||||
$output .= $token;
|
$rawChunk .= $token;
|
||||||
|
} elseif (T_START_HEREDOC === $token[0]) {
|
||||||
|
$output .= preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $rawChunk) . $token[1];
|
||||||
|
do {
|
||||||
|
$token = next($tokens);
|
||||||
|
$output .= $token[1];
|
||||||
|
} while ($token[0] !== T_END_HEREDOC);
|
||||||
|
$rawChunk = '';
|
||||||
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
|
||||||
$output .= $token[1];
|
$rawChunk .= $token[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace multiple new lines with a single newline
|
// replace multiple new lines with a single newline
|
||||||
$output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
|
$output .= preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $rawChunk);
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
@ -223,9 +223,28 @@ class KernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$source = <<<EOF
|
$source = <<<'EOF'
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$string = 'string should not be modified';
|
||||||
|
|
||||||
|
|
||||||
|
$heredoc = <<<HD
|
||||||
|
|
||||||
|
|
||||||
|
Heredoc should not be modified
|
||||||
|
|
||||||
|
|
||||||
|
HD;
|
||||||
|
|
||||||
|
$nowdoc = <<<'ND'
|
||||||
|
|
||||||
|
|
||||||
|
Nowdoc should not be modified
|
||||||
|
|
||||||
|
|
||||||
|
ND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* some class comments to strip
|
* some class comments to strip
|
||||||
*/
|
*/
|
||||||
@ -240,8 +259,25 @@ class TestClass
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF;
|
EOF;
|
||||||
$expected = <<<EOF
|
$expected = <<<'EOF'
|
||||||
<?php
|
<?php
|
||||||
|
$string = 'string should not be modified';
|
||||||
|
$heredoc =
|
||||||
|
<<<HD
|
||||||
|
|
||||||
|
|
||||||
|
Heredoc should not be modified
|
||||||
|
|
||||||
|
|
||||||
|
HD;
|
||||||
|
$nowdoc =
|
||||||
|
<<<'ND'
|
||||||
|
|
||||||
|
|
||||||
|
Nowdoc should not be modified
|
||||||
|
|
||||||
|
|
||||||
|
ND;
|
||||||
class TestClass
|
class TestClass
|
||||||
{
|
{
|
||||||
public function doStuff()
|
public function doStuff()
|
||||||
|
Reference in New Issue
Block a user