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