private static function ClassCollectionLoader::stripComments

Removes comments from a PHP source string.

We don't use the PHP php_strip_whitespace() function as we want the content to be readable and well-formatted.

Parameters

string $source A PHP string:

Return value

string The PHP string with the comments removed

1 call to ClassCollectionLoader::stripComments()
ClassCollectionLoader::load in drupal/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php
Loads a list of classes and caches them in one big file.

File

drupal/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ClassCollectionLoader.php, line 213

Class

ClassCollectionLoader
ClassCollectionLoader.

Namespace

Symfony\Component\ClassLoader

Code

private static function stripComments($source) {
  if (!function_exists('token_get_all')) {
    return $source;
  }
  $output = '';
  foreach (token_get_all($source) as $token) {
    if (is_string($token)) {
      $output .= $token;
    }
    elseif (!in_array($token[0], array(
      T_COMMENT,
      T_DOC_COMMENT,
    ))) {
      $output .= $token[1];
    }
  }

  // replace multiple new lines with a single newline
  $output = preg_replace(array(
    '/\\s+$/Sm',
    '/\\n+/S',
  ), "\n", $output);
  return $output;
}