예제 #1
0
  protected function processGenericInformation(DocBlox_TokenIterator $tokens)
  {
    $this->setName($tokens->current()->getContent());
    $this->default    = $this->findDefault($tokens);

    parent::processGenericInformation($tokens);
  }
예제 #2
0
  protected function processGenericInformation(DocBlox_TokenIterator $tokens)
  {
    $this->setName($tokens->gotoNextByType(T_STRING, 5, array('='))->getContent());
    $this->setValue($this->findDefault($tokens));

    parent::processGenericInformation($tokens);
  }
예제 #3
0
파일: File.php 프로젝트: namesco/Docblox
  public function __construct($file, $validate)
  {
    parent::__construct();

    if (!is_string($file) || (!is_readable($file)))
    {
      throw new DocBlox_Reflection_Exception('The given file should be a string, should exist on the filesystem and should be readable');
    }

    if ($validate)
    {
      exec('php -l '.escapeshellarg($file), $output, $result);
      if ($result != 0)
      {
        throw new DocBlox_Reflection_Exception('The given file could not be interpreted as it contains errors: '.implode(PHP_EOL, $output));
      }
    }

    $this->filename = $file;
    $this->name = $this->filename;
    $contents = file_get_contents($file);

    // detect encoding and transform to UTF-8
    $info = new finfo();
    $mime = $info->file($file, FILEINFO_MIME);
    $mime_info = explode('=', $mime);
    if (strtolower($mime_info[1]) != 'utf-8')
    {
        $contents = iconv($mime_info[1], 'UTF-8', $contents);
    }

    $this->contents = $contents;
    $this->setHash(filemtime($file));
  }
예제 #4
0
 /**
  * Retrieves the generic information.
  *
  * Finds out what the name and value is of this constant on top of the information found using the
  * DocBlox_Reflection_DocBlockedAbstract parent method.
  *
  * @param DocBlox_Reflection_TokenIterator $tokens
  *
  * @see DocBlox_Reflection_DocBlockedAbstract::processGenericInformation
  *
  * @return void
  */
 protected function processGenericInformation(DocBlox_Reflection_TokenIterator $tokens)
 {
     if ($tokens->current()->content == 'define') {
         // find the first encapsed string and strip the opening and closing
         // apostrophe
         $name_token = $tokens->gotoNextByType(T_CONSTANT_ENCAPSED_STRING, 5, array(','));
         if (!$name_token) {
             $this->log('Unable to process constant in file ' . $tokens->getFilename() . ' at line ' . $tokens->current()->getLineNumber(), DocBlox_Core_Log::CRIT);
             return;
         }
         $this->setName(substr($name_token->content, 1, -1));
         // skip to after the comma
         while ($tokens->current()->content != ',') {
             if ($tokens->next() === false) {
                 break;
             }
         }
         // get everything until the closing brace and use that for value, take child parenthesis under consideration
         $value = '';
         $level = 0;
         while (!($tokens->current()->content == ')' && $level == -1)) {
             if ($tokens->next() === false) {
                 break;
             }
             switch ($tokens->current()->content) {
                 case '(':
                     $level++;
                     break;
                 case ')':
                     $level--;
                     break;
             }
             $value .= $tokens->current()->content;
         }
         $this->setValue(trim(substr($value, 0, -1)));
     } else {
         // Added T_NAMESPACE in case anyone uses a constant name NAMESPACE in PHP
         // 5.2.x and tries to parse the code in 5.3.x
         $this->setName($tokens->gotoNextByType(array(T_STRING, T_NAMESPACE), 10, array('='))->content);
         $this->setValue($this->findDefault($tokens));
     }
     parent::processGenericInformation($tokens);
 }
예제 #5
0
 /**
  * Opens the file and retrieves its contents.
  *
  * During construction the given file is checked whether it is readable and
  * if the $validate argument is true a PHP Lint action is executed to
  * check whether the there are no parse errors.
  *
  * By default the Lint check is disable because of the performance hit
  * introduced by this action.
  *
  * If the validation checks out the file's contents are read; converted to
  * UTF-8 and the has is created from those contents.
  *
  * @param string  $file     Name of the file.
  * @param boolean $validate Whether to check the file using PHP Lint.
  *
  * @throws DocBlox_Reflection_Exception when the filename is incorrect or
  *   the file can not be opened
  *
  * @return void
  */
 public function __construct($file, $validate = false)
 {
     parent::__construct();
     if (!is_string($file) || !is_readable($file)) {
         throw new DocBlox_Reflection_Exception('The given file should be a string, should exist on the ' . 'filesystem and should be readable');
     }
     if ($validate) {
         exec('php -l ' . escapeshellarg($file), $output, $result);
         if ($result != 0) {
             throw new DocBlox_Reflection_Exception('The given file could not be interpreted as it contains ' . 'errors: ' . implode(PHP_EOL, $output));
         }
     }
     $this->setFilename($file);
     $this->name = $this->filename;
     $this->contents = $this->convertToUtf8($file, file_get_contents($file));
     // filemtime($file) is sometimes between 0.00001 and 0.00005 seconds
     // faster but md5 is more accurate
     // real world tests with larger code bases should determine how much
     // it really matters
     $this->setHash(md5($this->contents));
 }