Overview

Namespaces

  • TokenReflection
    • Broker
      • Backend
    • Dummy
    • Exception
    • Invalid
    • Php
    • Stream

Classes

  • FileStream
  • StreamBase
  • StringStream
  • Overview
  • Namespace
  • Class
  • Tree
  • Download
 1: <?php
 2: /**
 3:  * PHP Token Reflection
 4:  *
 5:  * Version 1.3.1
 6:  *
 7:  * LICENSE
 8:  *
 9:  * This source file is subject to the new BSD license that is bundled
10:  * with this library in the file LICENSE.
11:  *
12:  * @author Ondřej Nešpor
13:  * @author Jaroslav Hanslík
14:  */
15: 
16: namespace TokenReflection\Stream;
17: 
18: use TokenReflection\Broker as Broker, TokenReflection\Exception;
19: 
20: /**
21:  * Token stream iterator created from a file.
22:  */
23: class FileStream extends StreamBase
24: {
25:     /**
26:      * Constructor.
27:      *
28:      * Creates a token substream from a file.
29:      *
30:      * @param string $fileName File name
31:      * @throws \TokenReflection\Exception\StreamException If the file does not exist or is not readable.
32:      */
33:     public function __construct($fileName)
34:     {
35:         parent::__construct();
36: 
37:         $this->fileName = Broker::getRealPath($fileName);
38: 
39:         if (false === $this->fileName) {
40:             throw new Exception\StreamException($this, 'File does not exist.', Exception\StreamException::DOES_NOT_EXIST);
41:         }
42: 
43:         $contents = @file_get_contents($this->fileName);
44:         if (false === $contents) {
45:             throw new Exception\StreamException($this, 'File is not readable.', Exception\StreamException::NOT_READABLE);
46:         }
47: 
48:         $this->processSource($contents);
49:     }
50: }
PHP Token Reflection API documentation generated by ApiGen 2.8.0