Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Commit

Permalink
Merge branch '3.0'
Browse files Browse the repository at this point in the history
* 3.0: (36 commits)
  Fixed form types in profiler
  [Process] Use stream based storage to avoid memory issues
  Fix upgrade guides concerning erroneous removal of assets helper
  [Process] Remove a misleading comment
  Fix markdown typo
  ChooseBaseUrl should return an index
  [Form] ChoiceType: Fix a notice when 'choices' normalizer is replaced
  Improve the phpdoc of SplFileInfo methods
  [Process] Use stream based storage to avoid memory issues
  [FrameworkBundle] Don't log twice with the error handler
  synchronize 2.8 and 3.0 upgrade files
  Remove useless is_object condition
  [Process] Fix typo, no arguments needed anymore
  [Serializer] Introduce constants for context keys
  Fixed the documentation of VoterInterface::supportsAttribute
  Fixed Bootstrap form theme form "reset" buttons
  Fixed the form profiler when using long form types
  [PropertyInfo] PhpDocExtractor: Fix a notice when the property doesn't exist
  Remove useless duplicated tests
  [FrameworkBundle] Optimize framework extension tests
  ...
  • Loading branch information
fabpot committed Jan 20, 2016
2 parents 239e983 + eb74b54 commit 696bc20
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
27 changes: 18 additions & 9 deletions ClassCollectionLoader.php
Expand Up @@ -146,8 +146,9 @@ public static function fixNamespaceDeclarations($source)
$inNamespace = false;
$tokens = token_get_all($source);

for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
if (is_string($token)) {
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];
if (!isset($token[1]) || 'b"' === $token) {
$rawChunk .= $token;
} elseif (in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
// strip comments
Expand All @@ -159,21 +160,21 @@ public static function fixNamespaceDeclarations($source)
$rawChunk .= $token[1];

// namespace name and whitespaces
while (($t = next($tokens)) && is_array($t) && in_array($t[0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $t[1];
while (isset($tokens[++$i][1]) && in_array($tokens[$i][0], array(T_WHITESPACE, T_NS_SEPARATOR, T_STRING))) {
$rawChunk .= $tokens[$i][1];
}
if ('{' === $t) {
if ('{' === $tokens[$i]) {
$inNamespace = false;
prev($tokens);
--$i;
} else {
$rawChunk = rtrim($rawChunk)."\n{";
$inNamespace = true;
}
} elseif (T_START_HEREDOC === $token[0]) {
$output .= self::compressCode($rawChunk).$token[1];
do {
$token = next($tokens);
$output .= is_string($token) ? $token : $token[1];
$token = $tokens[++$i];
$output .= isset($token[1]) && 'b"' !== $token ? $token[1] : $token;
} while ($token[0] !== T_END_HEREDOC);
$output .= "\n";
$rawChunk = '';
Expand All @@ -189,7 +190,15 @@ public static function fixNamespaceDeclarations($source)
$rawChunk .= "}\n";
}

return $output.self::compressCode($rawChunk);
$output .= self::compressCode($rawChunk);

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
unset($tokens, $rawChunk);
gc_mem_caches();
}

return $output;
}

/**
Expand Down
22 changes: 14 additions & 8 deletions ClassMapGenerator.php
Expand Up @@ -64,6 +64,11 @@ public static function createMap($dir)

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

if (PHP_VERSION_ID >= 70000) {
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
gc_mem_caches();
}

foreach ($classes as $class) {
$map[$class] = $path;
}
Expand All @@ -87,10 +92,10 @@ private static function findClasses($path)
$classes = array();

$namespace = '';
for ($i = 0, $max = count($tokens); $i < $max; ++$i) {
for ($i = 0; isset($tokens[$i]); ++$i) {
$token = $tokens[$i];

if (is_string($token)) {
if (!isset($token[1])) {
continue;
}

Expand All @@ -100,9 +105,9 @@ private static function findClasses($path)
case T_NAMESPACE:
$namespace = '';
// If there is a namespace, extract it
while (($t = $tokens[++$i]) && is_array($t)) {
if (in_array($t[0], array(T_STRING, T_NS_SEPARATOR))) {
$namespace .= $t[1];
while (isset($tokens[++$i][1])) {
if (in_array($tokens[$i][0], array(T_STRING, T_NS_SEPARATOR))) {
$namespace .= $tokens[$i][1];
}
}
$namespace .= '\\';
Expand All @@ -113,7 +118,7 @@ private static function findClasses($path)
// Skip usage of ::class constant
$isClassConstant = false;
for ($j = $i - 1; $j > 0; --$j) {
if (is_string($tokens[$j])) {
if (!isset($tokens[$j][1])) {
break;
}

Expand All @@ -130,10 +135,11 @@ private static function findClasses($path)
}

// Find the classname
while (($t = $tokens[++$i]) && is_array($t)) {
while (isset($tokens[++$i][1])) {
$t = $tokens[$i];
if (T_STRING === $t[0]) {
$class .= $t[1];
} elseif ($class !== '' && T_WHITESPACE == $t[0]) {
} elseif ('' !== $class && T_WHITESPACE === $t[0]) {
break;
}
}
Expand Down

0 comments on commit 696bc20

Please sign in to comment.