Chris@0
|
1 <?php
|
Chris@0
|
2 /*
|
Chris@0
|
3 * This file is part of the PHP_TokenStream package.
|
Chris@0
|
4 *
|
Chris@0
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
6 *
|
Chris@0
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
8 * file that was distributed with this source code.
|
Chris@0
|
9 */
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * A caching factory for token stream objects.
|
Chris@0
|
13 *
|
Chris@0
|
14 * @author Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
15 * @copyright Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@0
|
16 * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
|
Chris@0
|
17 * @link http://github.com/sebastianbergmann/php-token-stream/tree
|
Chris@0
|
18 * @since Class available since Release 1.0.0
|
Chris@0
|
19 */
|
Chris@0
|
20 class PHP_Token_Stream_CachingFactory
|
Chris@0
|
21 {
|
Chris@0
|
22 /**
|
Chris@0
|
23 * @var array
|
Chris@0
|
24 */
|
Chris@0
|
25 protected static $cache = array();
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * @param string $filename
|
Chris@0
|
29 * @return PHP_Token_Stream
|
Chris@0
|
30 */
|
Chris@0
|
31 public static function get($filename)
|
Chris@0
|
32 {
|
Chris@0
|
33 if (!isset(self::$cache[$filename])) {
|
Chris@0
|
34 self::$cache[$filename] = new PHP_Token_Stream($filename);
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 return self::$cache[$filename];
|
Chris@0
|
38 }
|
Chris@0
|
39
|
Chris@0
|
40 /**
|
Chris@0
|
41 * @param string $filename
|
Chris@0
|
42 */
|
Chris@0
|
43 public static function clear($filename = null)
|
Chris@0
|
44 {
|
Chris@0
|
45 if (is_string($filename)) {
|
Chris@0
|
46 unset(self::$cache[$filename]);
|
Chris@0
|
47 } else {
|
Chris@0
|
48 self::$cache = array();
|
Chris@0
|
49 }
|
Chris@0
|
50 }
|
Chris@0
|
51 }
|