File tree Expand file tree Collapse file tree 1 file changed +34
-2
lines changed
src/Annotator/ClassAnnotatorTask Expand file tree Collapse file tree 1 file changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,25 @@ class ServiceAwareClassAnnotatorTask extends AbstractClassAnnotatorTask implemen
20
20
*/
21
21
public function shouldRun (string $ path , string $ content ): bool
22
22
{
23
- if (!preg_match ('#\buse ServiceAwareTrait\b# ' , $ content )) {
23
+ if (preg_match ('#\buse ServiceAwareTrait\b# ' , $ content )) {
24
+ return true ;
25
+ }
26
+
27
+ $ className = $ this ->getClassName ($ path , $ content );
28
+ if (!$ className ) {
24
29
return false ;
25
30
}
26
31
27
- return true ;
32
+ try {
33
+ $ object = new $ className ();
34
+ if (method_exists ($ object , 'loadService ' )) {
35
+ return true ;
36
+ }
37
+ } catch (\Throwable $ exception ) {
38
+ // Do nothing
39
+ }
40
+
41
+ return false ;
28
42
}
29
43
30
44
/**
@@ -81,4 +95,22 @@ protected function _getServiceAnnotations(array $usedServices): array
81
95
82
96
return $ annotations ;
83
97
}
98
+
99
+ /**
100
+ * @param string $path Path to PHP class file
101
+ * @param string $content Content of PHP class file
102
+ *
103
+ * @return string|null
104
+ */
105
+ protected function getClassName (string $ path , string $ content ): ?string
106
+ {
107
+ preg_match ('#^namespace (.+)\b#m ' , $ content , $ matches );
108
+ if (!$ matches ) {
109
+ return null ;
110
+ }
111
+
112
+ $ className = pathinfo ($ path , PATHINFO_FILENAME );
113
+
114
+ return $ matches [1 ] . '\\' . $ className ;
115
+ }
84
116
}
You can’t perform that action at this time.
0 commit comments