comparison vendor/phpunit/php-token-stream/src/Token/Stream/CachingFactory.php @ 0:4c8ae668cc8c

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