You are here

public function TokenParser::__construct in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php \Doctrine\Common\Annotations\TokenParser::__construct()

Parameters

string $contents:

File

vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php, line 54

Class

TokenParser
Parses a file for namespaces/use/class declarations.

Namespace

Doctrine\Common\Annotations

Code

public function __construct($contents) {
  $this->tokens = token_get_all($contents);

  // The PHP parser sets internal compiler globals for certain things. Annoyingly, the last docblock comment it
  // saw gets stored in doc_comment. When it comes to compile the next thing to be include()d this stored
  // doc_comment becomes owned by the first thing the compiler sees in the file that it considers might have a
  // docblock. If the first thing in the file is a class without a doc block this would cause calls to
  // getDocBlock() on said class to return our long lost doc_comment. Argh.
  // To workaround, cause the parser to parse an empty docblock. Sure getDocBlock() will return this, but at least
  // it's harmless to us.
  token_get_all("<?php\n/**\n *\n */");
  $this->numTokens = count($this->tokens);
}