You are here

public function PHP_Token_Stream::getIncludes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/php-token-stream/src/Token/Stream.php \PHP_Token_Stream::getIncludes()

Gets the names of all files that have been included using include(), include_once(), require() or require_once().

Parameter $categorize set to TRUE causing this function to return a multi-dimensional array with categories in the keys of the first dimension and constants and their values in the second dimension.

Parameter $category allow to filter following specific inclusion type

@since Method available since Release 1.1.0

Parameters

bool $categorize OPTIONAL:

string $category OPTIONAL Either 'require_once', 'require',: 'include_once', 'include'.

Return value

array

File

vendor/phpunit/php-token-stream/src/Token/Stream.php, line 296

Class

PHP_Token_Stream
A stream of PHP tokens.

Code

public function getIncludes($categorize = false, $category = null) {
  if ($this->includes === null) {
    $this->includes = array(
      'require_once' => array(),
      'require' => array(),
      'include_once' => array(),
      'include' => array(),
    );
    foreach ($this->tokens as $token) {
      switch (get_class($token)) {
        case 'PHP_Token_REQUIRE_ONCE':
        case 'PHP_Token_REQUIRE':
        case 'PHP_Token_INCLUDE_ONCE':
        case 'PHP_Token_INCLUDE':
          $this->includes[$token
            ->getType()][] = $token
            ->getName();
          break;
      }
    }
  }
  if (isset($this->includes[$category])) {
    $includes = $this->includes[$category];
  }
  elseif ($categorize === false) {
    $includes = array_merge($this->includes['require_once'], $this->includes['require'], $this->includes['include_once'], $this->includes['include']);
  }
  else {
    $includes = $this->includes;
  }
  return $includes;
}