3 * This file is part of the PHP_TokenStream package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * A caching factory for token stream objects.
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
20 class PHP_Token_Stream_CachingFactory
25 protected static $cache = array();
28 * @param string $filename
29 * @return PHP_Token_Stream
31 public static function get($filename)
33 if (!isset(self::$cache[$filename])) {
34 self::$cache[$filename] = new PHP_Token_Stream($filename);
37 return self::$cache[$filename];
41 * @param string $filename
43 public static function clear($filename = null)
45 if (is_string($filename)) {
46 unset(self::$cache[$filename]);
48 self::$cache = array();