1 | <?php |
||
2 | /** |
||
3 | * Units plugin for Craft CMS |
||
4 | * |
||
5 | * A plugin for handling physical quantities and the units of measure in which they're represented. |
||
6 | * |
||
7 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
8 | * @copyright Copyright (c) nystudio107 |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | namespace nystudio107\units\helpers; |
||
12 | |||
13 | use Craft; |
||
14 | use ReflectionClass; |
||
15 | use ReflectionException; |
||
16 | use function dirname; |
||
17 | |||
18 | /** |
||
0 ignored issues
–
show
|
|||
19 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||
20 | * @package Units |
||
0 ignored issues
–
show
|
|||
21 | * @since 1.0.0 |
||
0 ignored issues
–
show
|
|||
22 | */ |
||
0 ignored issues
–
show
|
|||
23 | class ClassHelper |
||
24 | { |
||
25 | // Public Static Methods |
||
26 | // ========================================================================= |
||
27 | |||
28 | /** |
||
29 | * Return an array of classes in the same namespace as $className, in an |
||
30 | * array of shortName => fullyQualifiedName |
||
31 | * |
||
32 | * @param string $className |
||
0 ignored issues
–
show
|
|||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public static function getClassesInNamespace(string $className): array |
||
37 | { |
||
38 | $result = []; |
||
39 | $loader = include Craft::getAlias('@vendor/autoload.php'); |
||
40 | $filePath = $loader->findFile($className); |
||
41 | if ($filePath) { |
||
42 | $dir = realpath(dirname($filePath)); |
||
43 | $classesMap = ClassMapGenerator::createMap($dir); |
||
44 | foreach ($classesMap as $class => $path) { |
||
45 | try { |
||
46 | $reflect = new ReflectionClass($class); |
||
47 | $shortName = $reflect->getShortName(); |
||
48 | $result[$shortName] = $class; |
||
49 | } catch (ReflectionException $e) { |
||
50 | Craft::error($e->getMessage(), __METHOD__); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | ksort($result); |
||
55 | |||
56 | return $result; |
||
57 | } |
||
58 | } |
||
59 |