Source for file RobotLoader.php
Documentation is available at RobotLoader.php
6: * @copyright Copyright (c) 2004, 2010 David Grudl
7: * @license http://nettephp.com/license Nette license
8: * @link http://nettephp.com
10: * @package Nette\Loaders
16: * Nette auto loader is responsible for loading classes and interfaces.
18: * @copyright Copyright (c) 2004, 2010 David Grudl
19: * @package Nette\Loaders
26: /** @var string comma separated wildcards */
29: /** @var string comma separated wildcards */
36: private $list =
array();
42: private $rebuilded =
FALSE;
57: throw new Exception("PHP extension Tokenizer is not loaded.");
64: * Register autoloader.
71: if (isset($cache[$key])) {
72: $this->list =
$cache[$key];
87: * Handles autoloading of classes or interfaces.
95: if (isset($this->list[$type])) {
96: if ($this->list[$type] !==
FALSE) {
102: $this->list[$type] =
FALSE;
109: if ($this->rebuilded) {
116: if ($this->list[$type] !==
FALSE) {
126: * Rebuilds class list cache.
132: $this->rebuilded =
TRUE;
140: public function _rebuildCallback()
144: foreach ($this->list as $pair) {
145: if ($pair) $this->files[$pair[0]] =
$pair[1];
148: $this->scanDirectory($dir);
150: $this->files =
NULL;
157: * @return array of class => filename
162: foreach ($this->list as $class =>
$pair) {
163: if ($pair) $res[$class] =
$pair[0];
171: * Add directory (or directories) to list.
172: * @param string|array
174: * @throws DirectoryNotFoundException if path is not found
178: foreach ((array)
$path as $val) {
180: if ($real ===
FALSE) {
190: * Add class and file name to the list.
196: private function addClass($class, $file, $time)
199: if (!empty($this->list[$class]) &&
$this->list[$class][0] !==
$file) {
201: throw new InvalidStateException("Ambiguous class '$class' resolution; defined in $file and in " .
$this->list[$class][0] .
".");
203: $this->list[$class] =
array($file, $time);
209: * Scan a directory for PHP files, subdirectories and 'netterobots.txt' file.
213: private function scanDirectory($dir)
216: if (!isset($this->files[$dir]) ||
$this->files[$dir] !==
filemtime($dir)) {
217: $this->scanScript($dir);
223: if (!$iterator) return;
225: $disallow =
array();
227: foreach (file($dir .
'/netterobots.txt') as $s) {
229: $disallow[trim($m[1], '/')] =
TRUE;
232: if (isset($disallow[''])) return;
235: while (FALSE !==
($entry =
$iterator->read())) {
236: if ($entry ==
'.' ||
$entry ==
'..' ||
isset($disallow[$entry])) continue;
238: $path =
$dir .
DIRECTORY_SEPARATOR .
$entry;
240: // process subdirectories
242: // check ignore mask
244: $this->scanDirectory($path);
250: if (!isset($this->files[$path]) ||
$this->files[$path] !==
filemtime($path)) {
251: $this->scanScript($path);
266: private function scanScript($file)
281: $this->addClass($name, $file, $time);
289: switch ($token[0]) {
295: case T_NS_SEPARATOR:
305: $expected =
$token[0];
309: case T_DOLLAR_OPEN_CURLY_BRACES:
315: switch ($expected) {
319: $this->addClass($namespace .
$name, $file, $time);
324: $namespace =
$name .
'\\';
330: if ($token ===
'{') {
332: } elseif ($token ===
'}') {
341: * Converts comma separated wildcards to regular expression.
345: private static function wildcards2re($wildcards)
351: $wildcard =
strtr($wildcard, array('*' =>
'.*', '?' =>
'.'));
352: $mask[] =
$wildcard;
359: /********************* backend ****************d*g**/