1 | <?php |
||
2 | /** |
||
3 | * This file is part of the O2System Framework package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Steeve Andrian Salim |
||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
10 | */ |
||
11 | |||
12 | // ------------------------------------------------------------------------ |
||
13 | |||
14 | namespace O2System\Spl\Info; |
||
15 | |||
16 | // ------------------------------------------------------------------------ |
||
17 | |||
18 | /** |
||
19 | * Class SplClassInfo |
||
20 | * |
||
21 | * @package O2System\Spl\Info |
||
22 | */ |
||
23 | class SplClassInfo extends \ReflectionClass |
||
24 | { |
||
25 | /** |
||
26 | * Class Name |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $name; |
||
31 | |||
32 | // ------------------------------------------------------------------------ |
||
33 | |||
34 | /** |
||
35 | * SplClassInfo constructor. |
||
36 | * |
||
37 | * @param mixed $className |
||
38 | */ |
||
39 | public function __construct($className) |
||
40 | { |
||
41 | if (is_object($className)) { |
||
42 | $className = get_class($className); |
||
43 | } |
||
44 | |||
45 | if (class_exists($className)) { |
||
46 | parent::__construct($className); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | // ------------------------------------------------------------------------ |
||
51 | |||
52 | /** |
||
53 | * SplClassInfo::getClass |
||
54 | * |
||
55 | * Gets class name. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | public function getClass() |
||
60 | { |
||
61 | return $this->name; |
||
62 | } |
||
63 | |||
64 | // ------------------------------------------------------------------------ |
||
65 | |||
66 | /** |
||
67 | * SplClassInfo::getParameter |
||
68 | * |
||
69 | * Gets class name. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getParameter() |
||
74 | { |
||
75 | $parts = explode('\\', $this->name); |
||
76 | |||
77 | return dash(end($parts)); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
78 | } |
||
79 | |||
80 | // ------------------------------------------------------------------------ |
||
81 | |||
82 | /** |
||
83 | * SplClassInfo::getFileInfo |
||
84 | * |
||
85 | * Gets class file info metadata. |
||
86 | * |
||
87 | * @return \O2System\Spl\Info\SplNamespaceInfo |
||
88 | */ |
||
89 | public function getNamespaceInfo() |
||
90 | { |
||
91 | if (empty($this->name)) { |
||
92 | throw new \RuntimeException('Internal error: SplClassInfo failed to retrieve the reflection object'); |
||
93 | } |
||
94 | |||
95 | return new SplNamespaceInfo($this->name, $this->getFileName()); |
||
96 | } |
||
97 | |||
98 | // ------------------------------------------------------------------------ |
||
99 | |||
100 | /** |
||
101 | * SplClassInfo::getFileInfo |
||
102 | * |
||
103 | * Gets class file info metadata. |
||
104 | * |
||
105 | * @return \O2System\Spl\Info\SplFileInfo |
||
106 | */ |
||
107 | public function getFileInfo() |
||
108 | { |
||
109 | if (empty($this->name)) { |
||
110 | throw new \RuntimeException('Internal error: SplClassInfo failed to retrieve the reflection object'); |
||
111 | } |
||
112 | |||
113 | return new SplFileInfo($this->getFileName()); |
||
114 | } |
||
115 | } |