Rev 1422 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1422 | Rev 1424 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | * @see https://www.php-fig.org/psr/psr-0/ |
40 | * @see https://www.php-fig.org/psr/psr-0/ |
41 | * @see https://www.php-fig.org/psr/psr-4/ |
41 | * @see https://www.php-fig.org/psr/psr-4/ |
42 | */ |
42 | */ |
43 | class ClassLoader |
43 | class ClassLoader |
44 | { |
44 | { |
45 | /** @var \Closure(string):void */ |
- | |
46 | private static $includeFile; |
- | |
47 | - | ||
48 | /** @var ?string */ |
45 | /** @var ?string */ |
49 | private $vendorDir; |
46 | private $vendorDir; |
50 | 47 | ||
51 | // PSR-4 |
48 | // PSR-4 |
52 | /** |
49 | /** |
Line 107... | Line 104... | ||
107 | * @param ?string $vendorDir |
104 | * @param ?string $vendorDir |
108 | */ |
105 | */ |
109 | public function __construct($vendorDir = null) |
106 | public function __construct($vendorDir = null) |
110 | { |
107 | { |
111 | $this->vendorDir = $vendorDir; |
108 | $this->vendorDir = $vendorDir; |
112 | self::initializeIncludeClosure(); |
- | |
113 | } |
109 | } |
114 | 110 | ||
115 | /** |
111 | /** |
116 | * @return string[] |
112 | * @return string[] |
117 | */ |
113 | */ |
Line 427... | Line 423... | ||
427 | * @return true|null True if loaded, null otherwise |
423 | * @return true|null True if loaded, null otherwise |
428 | */ |
424 | */ |
429 | public function loadClass($class) |
425 | public function loadClass($class) |
430 | { |
426 | { |
431 | if ($file = $this->findFile($class)) { |
427 | if ($file = $this->findFile($class)) { |
432 | $includeFile = self::$includeFile; |
- | |
433 | $includeFile($file); |
428 | includeFile($file); |
434 | 429 | ||
435 | return true; |
430 | return true; |
436 | } |
431 | } |
437 | 432 | ||
438 | return null; |
433 | return null; |
Line 558... | Line 553... | ||
558 | return $file; |
553 | return $file; |
559 | } |
554 | } |
560 | 555 | ||
561 | return false; |
556 | return false; |
562 | } |
557 | } |
563 | - | ||
564 | /** |
- | |
565 | * @return void |
- | |
566 | */ |
- | |
567 | private static function initializeIncludeClosure() |
- | |
568 | { |
- | |
569 | if (self::$includeFile !== null) { |
- | |
570 | return; |
- | |
571 | } |
558 | } |
572 | 559 | ||
573 | /** |
560 | /** |
574 | * Scope isolated include. |
561 | * Scope isolated include. |
575 | * |
562 | * |
576 | * Prevents access to $this/self from included files. |
563 | * Prevents access to $this/self from included files. |
577 | * |
564 | * |
578 | * @param string $file |
565 | * @param string $file |
579 | * @return void |
566 | * @return void |
- | 567 | * @private |
|
580 | */ |
568 | */ |
581 | self::$includeFile = \Closure::bind(static function($file) { |
569 | function includeFile($file) |
- | 570 | { |
|
582 | include $file; |
571 | include $file; |
583 | }, null, null); |
- | |
584 | } |
- | |
585 | } |
572 | } |