Source for file RobotLoader.php
Documentation is available at RobotLoader.php
6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
8: * This source file is subject to the "Nette license" that is bundled
9: * with this package in the file license.txt.
11: * For more information please see https://nette.org
13: * @copyright Copyright (c) 2004, 2009 David Grudl
14: * @license https://nette.org/license Nette license
15: * @link https://nette.org
17: * @package Nette\Loaders
23: require_once dirname(__FILE__) .
'/../Loaders/AutoLoader.php';
25: require_once dirname(__FILE__) .
'/../Framework.php';
30: * Nette auto loader is responsible for loading classes and interfaces.
32: * @author David Grudl
33: * @copyright Copyright (c) 2004, 2009 David Grudl
34: * @package Nette\Loaders
41: /** @var string comma separated wildcards */
44: /** @var string comma separated wildcards */
51: private $list =
NULL;
54: private $rebuilded =
FALSE;
65: * Handles autoloading of classes or interfaces.
71: if ($this->list ===
NULL) {
72: $this->list =
array(); // prevents cycling
75: $data =
$cache['data'];
78: if ($data['opt'] ===
$opt) {
79: $this->list =
$data['list'];
82: $cache['data'] =
array(
83: 'list' =>
$this->list,
94: if (isset($this->list[$type])) {
95: if ($this->list[$type] !==
FALSE) {
106: if (!$this->rebuilded) {
110: if (isset($this->list[$type])) {
114: $this->list[$type] =
FALSE;
118: $cache['data'] =
array(
119: 'list' =>
$this->list,
129: * Rebuilds class list cache.
136: $this->list =
array();
137: $this->rebuilded =
TRUE;
140: $this->scanDirectory($dir);
147: * Add directory (or directories) to list.
148: * @param string|array
150: * @throws InvalidArgumentException if path is not found
154: foreach ((array)
$path as $val) {
156: if ($real ===
FALSE) {
157: throw new InvalidArgumentException("Directory '$val' not found.");
166: * Add class and file name to the list.
174: if (isset($this->list[$class]) &&
$this->list[$class] !==
$file) {
175: // throwing exception is not possible, Nette\Debug converts errors to exceptions
176: die("Ambiguous class '$class' resolution; defined in $file and in " .
$this->list[$class] .
".");
178: $this->list[$class] =
$file;
184: * Scan a directory for PHP files, subdirectories and 'netterobots.txt' file.
188: private function scanDirectory($dir)
193: if (!$iterator) return;
195: $disallow =
array();
197: foreach (file($dir .
'/netterobots.txt') as $s) {
199: $disallow[trim($m[1], '/')] =
TRUE;
202: if (isset($disallow[''])) return;
205: while (FALSE !==
($entry =
$iterator->read())) {
206: if ($entry ==
'.' ||
$entry ==
'..' ||
isset($disallow[$entry])) continue;
208: $path =
$dir .
'/' .
$entry;
211: // process subdirectories
213: // check ignore mask
215: $this->scanDirectory($path);
221: $this->scanScript($path);
235: private function scanScript($file)
257: switch ($token[0]) {
261: $expected =
$token[0];
270: case T_NS_SEPARATOR:
280: if ($expected ===
T_NAMESPACE) {
281: $namespace =
$name .
'\\';
282: } elseif ($level ===
0) {
289: if ($token[0] ===
T_CURLY_OPEN ||
$token[0] ===
T_DOLLAR_OPEN_CURLY_BRACES) {
292: } elseif ($token ===
'{') {
294: } elseif ($token ===
'}') {
303: * Converts comma separated wildcards to regular expression.
307: private static function wildcards2re($wildcards)
313: $wildcard =
strtr($wildcard, array('*' =>
'.*', '?' =>
'.?'));
314: $mask[] =
$wildcard;
321: /********************* backend ****************d*g**/