3
3
namespace Doctrine \Persistence \Mapping \Driver ;
4
4
5
5
use Doctrine \Common \Annotations \Reader ;
6
- use Doctrine \Persistence \Mapping \MappingException ;
7
- use FilesystemIterator ;
8
- use RecursiveDirectoryIterator ;
9
- use RecursiveIteratorIterator ;
10
- use RecursiveRegexIterator ;
11
6
use ReflectionClass ;
12
- use RegexIterator ;
13
7
14
- use function array_merge ;
15
- use function array_unique ;
16
- use function assert ;
17
8
use function get_class ;
18
- use function get_declared_classes ;
19
- use function in_array ;
20
- use function is_dir ;
21
- use function preg_match ;
22
- use function preg_quote ;
23
- use function realpath ;
24
- use function str_replace ;
25
- use function strpos ;
26
9
27
10
/**
28
11
* The AnnotationDriver reads the mapping metadata from docblock annotations.
12
+ *
13
+ * @deprecated extend ColocatedMappingDriver directly instead.
29
14
*/
30
- abstract class AnnotationDriver implements MappingDriver
15
+ abstract class AnnotationDriver extends ColocatedMappingDriver implements MappingDriver
31
16
{
32
17
/**
33
18
* The annotation reader.
@@ -36,35 +21,6 @@ abstract class AnnotationDriver implements MappingDriver
36
21
*/
37
22
protected $ reader ;
38
23
39
- /**
40
- * The paths where to look for mapping files.
41
- *
42
- * @var string[]
43
- */
44
- protected $ paths = [];
45
-
46
- /**
47
- * The paths excluded from path where to look for mapping files.
48
- *
49
- * @var string[]
50
- */
51
- protected $ excludePaths = [];
52
-
53
- /**
54
- * The file extension of mapping documents.
55
- *
56
- * @var string
57
- */
58
- protected $ fileExtension = '.php ' ;
59
-
60
- /**
61
- * Cache for AnnotationDriver#getAllClassNames().
62
- *
63
- * @var string[]|null
64
- * @psalm-var list<class-string>|null
65
- */
66
- protected $ classNames ;
67
-
68
24
/**
69
25
* Name of the entity annotations as keys.
70
26
*
@@ -82,55 +38,8 @@ abstract class AnnotationDriver implements MappingDriver
82
38
public function __construct ($ reader , $ paths = null )
83
39
{
84
40
$ this ->reader = $ reader ;
85
- if (! $ paths ) {
86
- return ;
87
- }
88
41
89
- $ this ->addPaths ((array ) $ paths );
90
- }
91
-
92
- /**
93
- * Appends lookup paths to metadata driver.
94
- *
95
- * @param string[] $paths
96
- *
97
- * @return void
98
- */
99
- public function addPaths (array $ paths )
100
- {
101
- $ this ->paths = array_unique (array_merge ($ this ->paths , $ paths ));
102
- }
103
-
104
- /**
105
- * Retrieves the defined metadata lookup paths.
106
- *
107
- * @return string[]
108
- */
109
- public function getPaths ()
110
- {
111
- return $ this ->paths ;
112
- }
113
-
114
- /**
115
- * Append exclude lookup paths to metadata driver.
116
- *
117
- * @param string[] $paths
118
- *
119
- * @return void
120
- */
121
- public function addExcludePaths (array $ paths )
122
- {
123
- $ this ->excludePaths = array_unique (array_merge ($ this ->excludePaths , $ paths ));
124
- }
125
-
126
- /**
127
- * Retrieve the defined metadata lookup exclude paths.
128
- *
129
- * @return string[]
130
- */
131
- public function getExcludePaths ()
132
- {
133
- return $ this ->excludePaths ;
42
+ parent ::__construct (...(array ) $ paths );
134
43
}
135
44
136
45
/**
@@ -144,34 +53,6 @@ public function getReader()
144
53
}
145
54
146
55
/**
147
- * Gets the file extension used to look for mapping files under.
148
- *
149
- * @return string
150
- */
151
- public function getFileExtension ()
152
- {
153
- return $ this ->fileExtension ;
154
- }
155
-
156
- /**
157
- * Sets the file extension used to look for mapping files under.
158
- *
159
- * @param string $fileExtension The file extension to set.
160
- *
161
- * @return void
162
- */
163
- public function setFileExtension ($ fileExtension )
164
- {
165
- $ this ->fileExtension = $ fileExtension ;
166
- }
167
-
168
- /**
169
- * Returns whether the class with the specified name is transient. Only non-transient
170
- * classes, that is entities and mapped superclasses, should have their metadata loaded.
171
- *
172
- * A class is non-transient if it is annotated with an annotation
173
- * from the {@see AnnotationDriver::entityAnnotationClasses}.
174
- *
175
56
* {@inheritDoc}
176
57
*/
177
58
public function isTransient ($ className )
@@ -186,75 +67,4 @@ public function isTransient($className)
186
67
187
68
return true ;
188
69
}
189
-
190
- /**
191
- * {@inheritDoc}
192
- */
193
- public function getAllClassNames ()
194
- {
195
- if ($ this ->classNames !== null ) {
196
- return $ this ->classNames ;
197
- }
198
-
199
- if (! $ this ->paths ) {
200
- throw MappingException::pathRequired ();
201
- }
202
-
203
- $ classes = [];
204
- $ includedFiles = [];
205
-
206
- foreach ($ this ->paths as $ path ) {
207
- if (! is_dir ($ path )) {
208
- throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath ($ path );
209
- }
210
-
211
- $ iterator = new RegexIterator (
212
- new RecursiveIteratorIterator (
213
- new RecursiveDirectoryIterator ($ path , FilesystemIterator::SKIP_DOTS ),
214
- RecursiveIteratorIterator::LEAVES_ONLY
215
- ),
216
- '/^.+ ' . preg_quote ($ this ->fileExtension ) . '$/i ' ,
217
- RecursiveRegexIterator::GET_MATCH
218
- );
219
-
220
- foreach ($ iterator as $ file ) {
221
- $ sourceFile = $ file [0 ];
222
-
223
- if (preg_match ('(^phar:)i ' , $ sourceFile ) === 0 ) {
224
- $ sourceFile = realpath ($ sourceFile );
225
- }
226
-
227
- foreach ($ this ->excludePaths as $ excludePath ) {
228
- $ realExcludePath = realpath ($ excludePath );
229
- assert ($ realExcludePath !== false );
230
- $ exclude = str_replace ('\\' , '/ ' , $ realExcludePath );
231
- $ current = str_replace ('\\' , '/ ' , $ sourceFile );
232
-
233
- if (strpos ($ current , $ exclude ) !== false ) {
234
- continue 2 ;
235
- }
236
- }
237
-
238
- require_once $ sourceFile ;
239
-
240
- $ includedFiles [] = $ sourceFile ;
241
- }
242
- }
243
-
244
- $ declared = get_declared_classes ();
245
-
246
- foreach ($ declared as $ className ) {
247
- $ rc = new ReflectionClass ($ className );
248
- $ sourceFile = $ rc ->getFileName ();
249
- if (! in_array ($ sourceFile , $ includedFiles ) || $ this ->isTransient ($ className )) {
250
- continue ;
251
- }
252
-
253
- $ classes [] = $ className ;
254
- }
255
-
256
- $ this ->classNames = $ classes ;
257
-
258
- return $ classes ;
259
- }
260
70
}
0 commit comments