Example #1
0
 /**
  * Create token collection directly from code.
  *
  * @param string $code PHP code
  *
  * @return Tokens
  */
 public static function fromCode($code)
 {
     $codeHash = self::calculateCodeHash($code);
     if (self::hasCache($codeHash)) {
         $tokens = self::getCache($codeHash);
         // generate the code to recalculate the hash
         $tokens->generateCode();
         if ($codeHash === $tokens->codeHash) {
             $tokens->clearEmptyTokens();
             $tokens->clearChanged();
             return $tokens;
         }
     }
     $tokens = new self();
     $tokens->setCode($code);
     $tokens->clearChanged();
     return $tokens;
 }