1 | <?php |
||
2 | /** |
||
3 | * @package Mailcode |
||
4 | * @subpackage ClassCache |
||
5 | */ |
||
6 | |||
7 | declare(strict_types=1); |
||
8 | |||
9 | namespace Mailcode; |
||
10 | |||
11 | use AppUtils\ClassHelper\Repository\ClassRepositoryManager; |
||
12 | use AppUtils\FileHelper\FolderInfo; |
||
13 | use AppUtils\FileHelper_Exception; |
||
14 | |||
15 | /** |
||
16 | * Utility that handles the dynamic class loading and cache. |
||
17 | * |
||
18 | * @package Mailcode |
||
19 | * @subpackage ClassCache |
||
20 | */ |
||
21 | class ClassCache |
||
22 | { |
||
23 | /** |
||
24 | * @param string|FolderInfo $folder |
||
25 | * @param bool $recursive |
||
26 | * @param string|null $instanceOf |
||
27 | * @return class-string[] |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
28 | * @throws FileHelper_Exception |
||
29 | */ |
||
30 | public static function findClassesInFolder($folder, bool $recursive=false, ?string $instanceOf=null) : array |
||
31 | { |
||
32 | return self::createCache() |
||
33 | ->findClassesInFolder( |
||
34 | FolderInfo::factory($folder), |
||
35 | $recursive, |
||
36 | $instanceOf |
||
37 | ) |
||
38 | ->getClasses(); |
||
39 | } |
||
40 | |||
41 | private static ?ClassRepositoryManager $cache = null; |
||
42 | |||
43 | private static function createCache() : ClassRepositoryManager |
||
44 | { |
||
45 | if(!isset(self::$cache)) { |
||
46 | self::$cache = ClassRepositoryManager::create(Mailcode::getCacheFolder()); |
||
47 | } |
||
48 | |||
49 | return self::$cache; |
||
0 ignored issues
–
show
|
|||
50 | } |
||
51 | } |
||
52 |