コード例 #1
0
 /**
  * Constructor.
  *
  * Creates a token substream from a file.
  *
  * @param string $fileName File name
  * @throws \TokenReflection\Exception\StreamException If the file does not exist or is not readable.
  */
 public function __construct($fileName)
 {
     parent::__construct();
     $this->fileName = Broker::getRealPath($fileName);
     if (false === $this->fileName) {
         throw new Exception\StreamException($this, 'File does not exist.', Exception\StreamException::DOES_NOT_EXIST);
     }
     $contents = @file_get_contents($this->fileName);
     if (false === $contents) {
         throw new Exception\StreamException($this, 'File is not readable.', Exception\StreamException::NOT_READABLE);
     }
     $this->processSource($contents);
 }
コード例 #2
0
 /**
  * Returns an array of tokens for a particular file.
  *
  * @param string $fileName File name
  * @return \TokenReflection\Stream
  * @throws \RuntimeException If the token stream could not be returned.
  */
 public function getFileTokens($fileName)
 {
     try {
         if (!$this->isFileProcessed($fileName)) {
             throw new InvalidArgumentException('File was not processed');
         }
         $realName = Broker::getRealPath($fileName);
         if (!isset($this->fileCache[$realName])) {
             throw new InvalidArgumentException('File is not in the cache');
         }
         $data = @file_get_contents($this->fileCache[$realName]);
         if (false === $data) {
             throw new RuntimeException('Cached file is not readable');
         }
         $file = @unserialize($data);
         if (false === $file) {
             throw new RuntimeException('Stream could not be loaded from cache');
         }
         return $file;
     } catch (\Exception $e) {
         throw new RuntimeException(sprintf('Could not return token stream for file %s', $fileName), 0, $e);
     }
 }
コード例 #3
0
ファイル: Memory.php プロジェクト: BozzaCoon/SPHERE-Framework
 /**
  * Returns an array of tokens for a particular file.
  *
  * @param string $fileName File name
  *
  * @return \TokenReflection\Stream\StreamBase
  * @throws \TokenReflection\Exception\BrokerException If the requested file was not processed.
  */
 public function getFileTokens($fileName)
 {
     $realName = Broker::getRealPath($fileName);
     if (!isset($this->tokenStreams[$realName])) {
         throw new Exception\BrokerException($this->getBroker(), sprintf('File "%s" was not processed yet.', $fileName), Exception\BrokerException::DOES_NOT_EXIST);
     }
     return true === $this->tokenStreams[$realName] ? new FileStream($realName) : $this->tokenStreams[$realName];
 }