public static function Kernel::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

2 calls to Kernel::stripComments()
Kernel::dumpContainer in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php
Dumps the service container to PHP code in the cache.
KernelTest::testStripComments in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/KernelTest.php

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Kernel.php, line 755

Class

Kernel
The Kernel is the heart of the Symfony system.

Namespace

Symfony\Component\HttpKernel

Code

public 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;
}