37
37
namespace TheSeer \phpDox \Project {
38
38
39
39
use TheSeer \fDOM \fDOMDocument ;
40
+ use TheSeer \fDOM \fDOMElement ;
40
41
41
42
/**
42
43
*
43
44
*/
44
- class Project {
45
+ class Project extends \ TheSeer \ phpDox \Application {
45
46
46
47
/**
47
48
* @var string
@@ -99,6 +100,12 @@ public function addFile(\SplFileInfo $file) {
99
100
return $ isNew ;
100
101
}
101
102
103
+
104
+ public function removeFile (\SplFileInfo $ file ) {
105
+ $ this ->removeFileReferences ($ file ->getPathname ());
106
+ $ this ->source ->removeFile ($ file );
107
+ }
108
+
102
109
/**
103
110
* @param ClassObject $class
104
111
*/
@@ -199,18 +206,24 @@ public function save() {
199
206
}
200
207
$ indexDom = $ this ->index ->export ();
201
208
$ newUnits = $ this ->index ->getAddedUnits ();
209
+ $ reportUnits = $ newUnits ;
202
210
foreach ($ newUnits as $ unit ) {
211
+ $ indexNode = $ indexDom ->queryOne (
212
+ sprintf ('//phpdox:namespace[@name="%s"]/*[@name="%s"] ' ,
213
+ $ unit ->getNamespace (),
214
+ $ unit ->getName ())
215
+ );
203
216
$ name = str_replace ('\\' , '_ ' , $ unit ->getFullName ());
204
217
$ dom = $ unit ->export ();
205
218
$ dom ->formatOutput = TRUE ;
206
219
$ dom ->preserveWhiteSpace = FALSE ;
207
220
$ fname = $ map [$ dom ->documentElement ->localName ] . '/ ' . $ name . '.xml ' ;
221
+ if ($ indexNode ->hasAttribute ('xml ' )) {
222
+ $ reportUnits = array_merge ($ reportUnits , $ this ->findAffectedUnits ($ fname ));
223
+ } else {
224
+ $ indexNode ->setAttribute ('xml ' , $ fname );
225
+ }
208
226
$ dom ->save ($ this ->xmlDir . '/ ' . $ fname );
209
-
210
- $ indexDom ->queryOne (sprintf ('//phpdox:namespace[@name="%s"]/*[@name="%s"] ' ,
211
- $ unit ->getNamespace (),
212
- $ unit ->getName ())
213
- )->setAttribute ('xml ' , $ fname );
214
227
}
215
228
$ indexDom ->formatOutput = TRUE ;
216
229
$ indexDom ->preserveWhiteSpace = FALSE ;
@@ -220,6 +233,52 @@ public function save() {
220
233
$ sourceDom ->formatOutput = TRUE ;
221
234
$ sourceDom ->preserveWhiteSpace = FALSE ;
222
235
$ sourceDom ->save ($ this ->xmlDir . '/source.xml ' );
236
+
237
+ return $ reportUnits ;
238
+ }
239
+
240
+ /**
241
+ * @param $fname
242
+ *
243
+ * @return array
244
+ */
245
+ private function findAffectedUnits ($ fname ) {
246
+ $ affected = array ();
247
+ $ dom = new fDOMDocument ();
248
+ $ dom ->load ($ this ->xmlDir . '/ ' . $ fname );
249
+ $ dom ->registerNamespace ('phpdox ' , 'http://xml.phpdox.de/src# ' );
250
+ $ extends = $ dom ->queryOne ('//phpdox:extends ' );
251
+ if ($ extends instanceof fDOMElement) {
252
+ $ unitNode = $ this ->index ->findUnitNodeByName (
253
+ $ extends ->getAttribute ('namespace ' ), $ extends ->getAttribute ('class ' )
254
+ );
255
+ if ($ unitNode ) {
256
+ $ unitDom = new fDOMDocument ();
257
+ $ unitDom ->load ($ this ->xmlDir . '/ ' . $ unitNode ->getAttribute ('xml ' ));
258
+ $ unitDom ->registerNamespace ('phpdox ' , 'http://xml.phpdox.de/src# ' );
259
+ if ($ unitDom ->documentElement ->nodeName == 'class ' ) {
260
+ $ unit = new ClassObject ();
261
+ } else {
262
+ $ unit = new TraitObject ();
263
+ }
264
+ $ unit ->import ($ unitDom );
265
+ $ affected [$ extends ->getAttribute ('full ' )] = $ unit ;
266
+ }
267
+ }
268
+ $ implements = $ dom ->query ('//phpdox:implements ' );
269
+ foreach ($ implements as $ implement ) {
270
+ $ unitNode = $ this ->index ->findUnitNodeByName (
271
+ $ implement ->getAttribute ('namespace ' ), $ implement ->getAttribute ('class ' )
272
+ );
273
+ if ($ unitNode ) {
274
+ $ unitDom = new fDOMDocument ();
275
+ $ unitDom ->load ($ this ->xmlDir . '/ ' . $ unitNode ->getAttribute ('xml ' ));
276
+ $ unit = new InterfaceObject ();
277
+ $ unit ->import ($ unitDom );
278
+ $ affected [$ implement ->getAttribute ('full ' )] = $ unit ;
279
+ }
280
+ }
281
+ return $ affected ;
223
282
}
224
283
225
284
/**
@@ -248,7 +307,7 @@ private function initCollections() {
248
307
* @param string $path
249
308
*/
250
309
private function removeFileReferences ($ path ) {
251
- foreach ($ this ->index ->getUnitsBySrcFile ($ path ) as $ node ) {
310
+ foreach ($ this ->index ->findUnitNodesBySrcFile ($ path ) as $ node ) {
252
311
/** @var $node \DOMElement */
253
312
$ fname = $ this ->xmlDir . '/ ' . $ node ->getAttribute ('xml ' );
254
313
if (file_exists ($ fname )) {
0 commit comments