| 1 | 2 | simandl | <?php |
| 2 | | | |
| 3 | | | namespace Phem\ClassLoading; |
| 4 | | | |
| 5 | | | /** |
| 6 | | | * This file should include all necessary classes inside framework |
| 7 | | | * using lazy include approach if possible. |
| 8 | | | * |
| 9 | | | * All classes must be in separate files |
| 10 | | | * and the physical path to the class files must follow |
| 11 | | | * the Namespace\Class naming convention starting from component root |
| 12 | | | * |
| 13 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
| 14 | | | */ |
| 15 | | | class FrameworkLoader extends Loader |
| 16 | | | { |
| 17 | | | |
| 18 | | | public static function autoload($class) |
| 19 | | | { |
| 20 | | | if (strpos($class, ROOT_NAMESPACE) !== false) |
| 21 | | | { |
| 22 | | | /* |
| 23 | | | * here we cas use include for better efficiency |
| 24 | | | * because this called only once anyway |
| 25 | | | */ |
| 26 | | | $fileName = FRAMEWORK_DIR . DS . str_replace(ROOT_NAMESPACE . DS, "", str_replace('\\', DS, $class)) . '.php'; |
| 27 | | | |
| 28 | | | if (file_exists($fileName)) |
| 29 | | | { |
| 30 | | | include $fileName; |
| 31 | | | return true; |
| 32 | | | } |
| 33 | | | } |
| 34 | | | } |
| 35 | | | |
| 36 | | | public function commit() |
| 37 | | | { |
| 38 | | | spl_autoload_register(array(__CLASS__,'autoload')); |
| 39 | | | } |
| 40 | | | |
| 41 | | | } |