Пример #1
0
  protected function processGenericInformation(DocBlox_TokenIterator $tokens)
  {
    $this->setName($tokens->gotoNextByType(T_STRING, 5, array('='))->getContent());
    $this->setValue($this->findDefault($tokens));

    parent::processGenericInformation($tokens);
  }
Пример #2
0
  protected function processGenericInformation(DocBlox_TokenIterator $tokens)
  {
    $this->setName($tokens->current()->getContent());
    $this->default    = $this->findDefault($tokens);

    parent::processGenericInformation($tokens);
  }
Пример #3
0
  /**
   * Returns the first docblock preceding the active token within 10 tokens.
   *
   * Please note that the iterator cursor does not change due to this method
   *
   * @param  DocBlox_TokenIterator $tokens
   * @return Zend_Reflection_DocBlock|null
   */
  protected function findDocBlock(DocBlox_TokenIterator $tokens)
  {
    $result = null;
    $docblock = $tokens->findPreviousByType(T_DOC_COMMENT, 10, array('{'. '}', ';'));
    try
    {
      $result = $docblock ? new Zend_Reflection_Docblock($docblock->getContent()) : null;
      if ($result)
      {
        // attach line number to class, the Zend_Reflection_DocBlock does not know the number
        $result->line_number = $docblock->getLineNumber();
      }
    }
    catch (Exception $e)
    {
      $this->log($e->getMessage(), Zend_Log::CRIT);
    }

    if (!$result)
    {
      $this->log('No DocBlock was found for '.substr(get_class($this), strrpos(get_class($this), '_')+1).' '.$this->getName().' on line '.$this->getLineNumber(), Zend_Log::ERR);
    }

    return $result;
  }
Пример #4
0
  protected function findName(DocBlox_TokenIterator $tokens)
  {
    $name = $tokens->findNextByType(T_STRING, 5, array('{', ';'));
    $this->setType($name ? 'function' : 'closure');

    return $name ? $name->getContent() : 'Closure';
  }
Пример #5
0
  protected function processGenericInformation(DocBlox_TokenIterator $tokens)
  {
    $this->type = ucwords(strtolower(str_replace('_', ' ', substr($tokens->current()->getName(), 2))));

    if ($token = $tokens->gotoNextByType(T_CONSTANT_ENCAPSED_STRING, 10, array(';')))
    {
      $this->setName(trim($token->getContent(), '\'"'));
    }
    elseif ($token = $tokens->gotoNextByType(T_VARIABLE, 10, array(';')))
    {
      $this->setName(trim($token->getContent(), '\'"'));
    }
  }
Пример #6
0
  /**
   * Generic method which iterates through all tokens between the braces following the current position in the token
   * iterator.
   *
   * Please note: This method will also move the cursor position in the token iterator forward.
   * When a token is encountered this method will invoke the processToken method, which is defined in the
   * DocBlox_Reflection_Abstract class. Literals are ignored.
   *
   * @see    DocBlox_Reflection_Abstract
   * @param  DocBlox_TokenIterator $tokens
   * @return int[]
   */
  public function processTokens(DocBlox_TokenIterator $tokens)
  {
    $level = -1;
    $start = 0;
    $end   = 0;

    // parse class contents
    $this->debug('>> Processing tokens');
    $token = null;
    while ($tokens->valid())
    {
        /** @var DocBlox_Token $token */
      $token = $token === null ? $tokens->current() : $tokens->next();

      // determine where the 'braced' section starts and end.
      // the first open brace encountered is considered the opening brace for the block and processing will
      // be 'breaked' when the closing brace is encountered
      if ($token
          && (!$token->getType()
              || ($token->getType() == T_CURLY_OPEN)
              || ($token->getType() == T_DOLLAR_OPEN_CURLY_BRACES))
          && (($token->getContent() == '{')
              || (($token->getContent() == '}'))))
      {
        switch ($token->getContent())
        {
          case '{':
            // expect the first brace to be an opening brace
            if ($level == -1)
            {
              $level++;
              $start = $tokens->key();
            }
            $level++;
            break;
          case '}':
            if ($level == -1) continue;
            $level--;

            // reached the end; break from the while
            if ($level === 0)
            {
              $end = $tokens->key();
              break 2; // time to say goodbye
            }
            break;
        }
        continue;
      }

      if ($token && $token->getType())
      {
        // if a token is encountered and it is not a literal, invoke the processToken method
        $this->processToken($token, $tokens);
      }
    }

    // return the start and end token index
    return array($start, $end);
  }
Пример #7
0
  public function testGetTokenIdsOfParenthesisPair()
  {
    $this->object->seek(0);
    $this->object->gotoNextByType(T_FUNCTION, 0);
    $result = $this->object->getTokenIdsOfParenthesisPair();

    $this->assertType('array', $result, 'Expected result to be an array');
    $this->assertArrayHasKey(0, $result, 'Expected result to have a start element');
    $this->assertArrayHasKey(1, $result, 'Expected result to have an end element');
    $this->assertEquals(40, $result[0], 'Expected the first brace to be at token id 40');
    $this->assertEquals(41, $result[1], 'Expected the closing brace to be at token id 41');
  }
Пример #8
0
  protected function processNamespace(DocBlox_TokenIterator $tokens)
  {
    // collect all namespace parts
    $namespace = array();
    while($token = $tokens->gotoNextByType(T_STRING, 5, array(';', '{')))
    {
      $namespace[] = $token->getContent();
    }
    $namespace = implode('\\', $namespace);

    $this->active_namespace = $namespace;
  }
Пример #9
0
  public function parseTokenizer(DocBlox_TokenIterator $tokens)
  {
    if (!$tokens->current())
    {
      $this->log('>> No contents found to parse');
      return;
    }

    $this->debug('== Parsing token '.$tokens->current()->getName());
    $this->line_start = $tokens->current()->getLineNumber();

    // retrieve generic information about the class
    $this->processGenericInformation($tokens);

    list($start, $end) = $this->processTokens($tokens);
    $this->token_start = $start;
    $this->token_end   = $end;

    $this->debug('== Determined token index range to be '.$start.' => '.$end);

    $this->debugTimer('>> Processed all tokens');
  }