@@ -89,6 +89,88 @@ public static function excludeStarterKit($var) {
89
89
90
90
}
91
91
92
+ /**
93
+ * Extract the classes in the given file.
94
+ *
95
+ * This method taken from Symfony ClassLoader component.
96
+ *
97
+ * @see \Symfony\Component\ClassLoader\ClassMapGenerator::findClasses()
98
+ * @license http://symfony.com/doc/current/contributing/code/license.html MIT license
99
+ *
100
+ * @param string $path The file to check
101
+ *
102
+ * @return array The found classes
103
+ */
104
+ private static function findClasses ($ path ) {
105
+
106
+ $ contents = file_get_contents ($ path );
107
+ $ tokens = token_get_all ($ contents );
108
+
109
+ $ classes = array ();
110
+
111
+ $ namespace = '' ;
112
+ for ($ i = 0 ; isset ($ tokens [$ i ]); ++$ i ) {
113
+ $ token = $ tokens [$ i ];
114
+
115
+ if (!isset ($ token [1 ])) {
116
+ continue ;
117
+ }
118
+
119
+ $ class = '' ;
120
+
121
+ switch ($ token [0 ]) {
122
+ case T_NAMESPACE :
123
+ $ namespace = '' ;
124
+ // If there is a namespace, extract it
125
+ while (isset ($ tokens [++$ i ][1 ])) {
126
+ if (in_array ($ tokens [$ i ][0 ], array (T_STRING , T_NS_SEPARATOR ))) {
127
+ $ namespace .= $ tokens [$ i ][1 ];
128
+ }
129
+ }
130
+ $ namespace .= '\\' ;
131
+ break ;
132
+ case T_CLASS :
133
+ case T_INTERFACE :
134
+ case T_TRAIT :
135
+ // Skip usage of ::class constant
136
+ $ isClassConstant = false ;
137
+ for ($ j = $ i - 1 ; $ j > 0 ; --$ j ) {
138
+ if (!isset ($ tokens [$ j ][1 ])) {
139
+ break ;
140
+ }
141
+
142
+ if (T_DOUBLE_COLON === $ tokens [$ j ][0 ]) {
143
+ $ isClassConstant = true ;
144
+ break ;
145
+ } elseif (!in_array ($ tokens [$ j ][0 ], array (T_WHITESPACE , T_DOC_COMMENT , T_COMMENT ))) {
146
+ break ;
147
+ }
148
+ }
149
+
150
+ if ($ isClassConstant ) {
151
+ break ;
152
+ }
153
+
154
+ // Find the classname
155
+ while (isset ($ tokens [++$ i ][1 ])) {
156
+ $ t = $ tokens [$ i ];
157
+ if (T_STRING === $ t [0 ]) {
158
+ $ class .= $ t [1 ];
159
+ } elseif ('' !== $ class && T_WHITESPACE === $ t [0 ]) {
160
+ break ;
161
+ }
162
+ }
163
+
164
+ $ classes [] = ltrim ($ namespace .$ class , '\\' );
165
+ break ;
166
+ default :
167
+ break ;
168
+ }
169
+ }
170
+
171
+ return $ classes ;
172
+ }
173
+
92
174
/**
93
175
* Parse the component types to figure out what needs to be moved and added to the component JSON files
94
176
* @param {String} file path to move
@@ -597,8 +679,8 @@ protected static function scanForListener($pathPackage,$remove = false) {
597
679
foreach ($ finder as $ file ) {
598
680
599
681
// create the name
600
- $ dirs = explode ( DIRECTORY_SEPARATOR , $ file ->getPath ());
601
- $ listenerName = "\\" .$ dirs [ count ( $ dirs )- 2 ]. "\\" . $ dirs [ count ( $ dirs )- 1 ]. "\\" . str_replace ( " .php " , "" , $ file -> getFilename ()) ;
682
+ $ classes = self :: findClasses ( $ file ->getPathname ());
683
+ $ listenerName = "\\" .$ classes [ 0 ] ;
602
684
603
685
// check to see what we should do with the listener info
604
686
if (!$ remove && !in_array ($ listenerName ,$ listenerList ["listeners " ])) {
@@ -639,9 +721,9 @@ protected static function scanForPatternEngineRule($pathPackage,$remove = false)
639
721
// iterate over the returned objects
640
722
foreach ($ finder as $ file ) {
641
723
642
- /// create the name
643
- $ dirs = explode ( DIRECTORY_SEPARATOR , $ file ->getPath ());
644
- $ patternEngineName = "\\" .$ dirs [ count ( $ dirs )- 3 ]. "\\" . $ dirs [ count ( $ dirs )- 2 ]. "\\" . $ dirs [ count ( $ dirs )- 1 ]. "\\" . str_replace ( " .php " , "" , $ file -> getFilename ()) ;
724
+ // create the name
725
+ $ classes = self :: findClasses ( $ file ->getPathname ());
726
+ $ patternEngineName = "\\" .$ classes [ 0 ] ;
645
727
646
728
// check what we should do with the pattern engine info
647
729
if (!$ remove && !in_array ($ patternEngineName , $ patternEngineList ["patternengines " ])) {
0 commit comments