@@ -18,13 +18,13 @@ class Files {
18
18
* @var RootDirCollection Container with all root directories
19
19
*
20
20
*/
21
- private $ _rootDirs ;
21
+ private $ _rootDirCollection ;
22
22
23
23
/**
24
24
* @var ChildDirCollection Container with all child directories
25
25
*
26
26
*/
27
- private $ _childDirs ;
27
+ private $ _childDirCollection ;
28
28
29
29
/**
30
30
* @var FilesQuery Query object for each Files instance
@@ -35,16 +35,16 @@ class Files {
35
35
const DEFAULT_EXTENSION = 'php ' ;
36
36
37
37
function __construct () {
38
- $ this ->_rootDirs = new RootDirCollection ();
39
- $ this ->_childDirs = new ChildDirCollection ();
38
+ $ this ->_rootDirCollection = new RootDirCollection ();
39
+ $ this ->_childDirCollection = new ChildDirCollection ();
40
40
$ this ->_query = new FilesQuery ($ this );
41
41
}
42
42
43
43
/**
44
44
* @return RootDirCollection
45
45
*/
46
- protected function _rootDirs () {
47
- return $ this ->_rootDirs ;
46
+ protected function _rootCollection () {
47
+ return $ this ->_rootDirCollection ;
48
48
}
49
49
50
50
/**
@@ -53,70 +53,95 @@ protected function _rootDirs() {
53
53
* @return RootDir|false
54
54
*/
55
55
public function addRootDir (RootDir $ rootDir , $ index = null ) {
56
- $ rootDir = $ this ->_rootDirs ()->addRootDir ($ rootDir , $ index );
56
+ $ rootDir = $ this ->_rootCollection ()->addRootDir ($ rootDir , $ index );
57
57
return $ this ->isValid () === true ? $ rootDir : false ;
58
58
}
59
59
60
+ /**
61
+ * @param RootDir $rootDir
62
+ * @return bool
63
+ */
64
+ public function removeRootDir (RootDir $ rootDir ) {
65
+ return $ this ->_rootCollection ()->removeDir ($ rootDir );
66
+ }
67
+ /**
68
+ * @param string $id
69
+ * @return bool
70
+ */
71
+ public function removeRootDirById ($ id ) {
72
+ return $ this ->_rootCollection ()->removeDirById ($ id );
73
+ }
74
+ /**
75
+ * @param int $index
76
+ * @return bool
77
+ */
78
+ public function removeRootDirAtIndex ($ index ) {
79
+ return $ this ->_rootCollection ()->removeDirAtIndex ($ index );
80
+ }
81
+ public function removeAllRootDirs () {
82
+ $ this ->_rootCollection ()->removeAllDirs ();
83
+ }
84
+
60
85
/**
61
86
* @return RootDir[]
62
87
*/
63
88
public function rootDirs () {
64
- return $ this ->_rootDirs ()->dirs ();
89
+ return $ this ->_rootCollection ()->dirs ();
65
90
}
66
91
67
92
/**
68
93
* @param RootDir $rootDir RootDir that will be checked
69
94
* @return bool Returns true if RootDir is part of this files instance
70
95
*/
71
96
public function containsRootDir (RootDir $ rootDir ) {
72
- return $ this ->_rootDirs ()->isInCollection ($ rootDir );
97
+ return $ this ->_rootCollection ()->isInCollection ($ rootDir );
73
98
}
74
99
75
100
/**
76
101
* @return int Total root directories
77
102
*/
78
103
public function totalRootDirs () {
79
- return $ this ->_rootDirs ()->totalDirs ();
104
+ return $ this ->_rootCollection ()->totalDirs ();
80
105
}
81
106
82
107
/**
83
108
* @param string|RootDir $rootDir
84
109
* @return RootDir|null
85
110
*/
86
111
public function getRootDir ($ rootDir ) {
87
- return $ this ->_rootDirs ()->getDir ($ rootDir );
112
+ return $ this ->_rootCollection ()->getDir ($ rootDir );
88
113
}
89
114
90
115
/**
91
116
* @param string $id
92
117
* @return null|RootDir
93
118
*/
94
119
public function getRootDirById ($ id ) {
95
- return $ this ->_rootDirs ()->getDirById ($ id );
120
+ return $ this ->_rootCollection ()->getDirById ($ id );
96
121
}
97
122
98
123
/**
99
124
* @param int $index
100
125
* @return RootDir|false
101
126
*/
102
127
public function getRootDirByIndex ($ index ) {
103
- return $ this ->_rootDirs ()->getDirByIndex ($ index );
128
+ return $ this ->_rootCollection ()->getDirByIndex ($ index );
104
129
}
105
130
106
131
/**
107
132
* @return string[]
108
133
*/
109
134
public function getRootPaths () {
110
- return $ this ->_rootDirs ()->getPaths ();
135
+ return $ this ->_rootCollection ()->getPaths ();
111
136
}
112
137
113
138
114
139
115
140
/**
116
141
* @return ChildDirCollection
117
142
*/
118
- protected function _childDirs () {
119
- return $ this ->_childDirs ;
143
+ protected function _childCollection () {
144
+ return $ this ->_childDirCollection ;
120
145
}
121
146
122
147
/**
@@ -125,61 +150,86 @@ protected function _childDirs() {
125
150
* @return ChildDir|false
126
151
*/
127
152
public function addChildDir (ChildDir $ childDir , $ index = null ) {
128
- $ childDir = $ this ->_childDirs ()->addChildDir ($ childDir , $ index );
153
+ $ childDir = $ this ->_childCollection ()->addChildDir ($ childDir , $ index );
129
154
return $ this ->isValid () === true ? $ childDir : false ;
130
155
}
131
156
157
+ /**
158
+ * @param ChildDir $childDir
159
+ * @return bool
160
+ */
161
+ public function removeChildDir (ChildDir $ childDir ) {
162
+ return $ this ->_childCollection ()->removeDir ($ childDir );
163
+ }
164
+ /**
165
+ * @param string $id
166
+ * @return bool
167
+ */
168
+ public function removeChildDirById ($ id ) {
169
+ return $ this ->_childCollection ()->removeDirById ($ id );
170
+ }
171
+ /**
172
+ * @param int $index
173
+ * @return bool
174
+ */
175
+ public function removeChildDirAtIndex ($ index ) {
176
+ return $ this ->_childCollection ()->removeDirAtIndex ($ index );
177
+ }
178
+ public function removeAllChildDirs () {
179
+ $ this ->_childCollection ()->removeAllDirs ();
180
+ }
181
+
132
182
/**
133
183
* @return ChildDir[]
134
184
*/
135
185
public function childDirs () {
136
- return $ this ->_childDirs ()->dirs ();
186
+ return $ this ->_childCollection ()->dirs ();
137
187
}
138
188
139
189
/**
140
190
* @param ChildDir $childDir Dir that will be checked
141
191
* @return bool Returns true if dir is part of this files instance
142
192
*/
143
193
public function containsChildDir (ChildDir $ childDir ) {
144
- return $ this ->_childDirs ()->isInCollection ($ childDir );
194
+ return $ this ->_childCollection ()->isInCollection ($ childDir );
145
195
}
146
196
147
197
/**
148
198
* @return int Total child directories
149
199
*/
150
200
public function totalChildDirs () {
151
- return $ this ->_childDirs ()->totalDirs ();
201
+ return $ this ->_childCollection ()->totalDirs ();
152
202
}
153
203
154
204
/**
155
205
* @param string|ChildDir $childDir
156
206
* @return null|ChildDir
157
207
*/
158
208
public function getChildDir ($ childDir ) {
159
- return $ this ->_childDirs ()->getDir ($ childDir );
209
+ return $ this ->_childCollection ()->getDir ($ childDir );
160
210
}
161
211
162
212
/**
163
213
* @param string $id
164
214
* @return null|ChildDir
165
215
*/
166
216
public function getChildDirById ($ id ) {
167
- return $ this ->_childDirs ()->getDirById ($ id );
217
+ return $ this ->_childCollection ()->getDirById ($ id );
168
218
}
169
219
170
220
/**
171
221
* @param int $index
172
222
* @return ChildDir|false
173
223
*/
174
224
public function getChildDirByIndex ($ index ) {
175
- return $ this ->_childDirs ()->getDirByIndex ($ index );
225
+ return $ this ->_childCollection ()->getDirByIndex ($ index );
176
226
}
177
227
178
228
/**
179
229
* @return string[]
180
230
*/
181
231
public function getChildPaths () {
182
- return $ this ->_childDirs ()->getPaths ();
232
+ return $ this ->_childCollection ()->getPaths ();
183
233
}
184
234
185
235
/**
@@ -192,7 +242,7 @@ protected function isValid() {
192
242
if ($ rootDir ->isRequired ()) {
193
243
$ rootDirPath = $ rootDir ->dir ();
194
244
if (!is_dir ($ rootDirPath )) {
195
- throw new FilesException (sprintf ('Root directory "%s" does not exist but is required. Please create this directory or turn this requirement off. ' , $ rootDirPath ));
245
+ throw new FilesException (sprintf ('Absolute root directory "%s" does not exist but is required. Please create this directory or turn this requirement off. ' , $ rootDirPath ));
196
246
}
197
247
foreach ($ this ->childDirs () as $ childDir ) {
198
248
if ($ childDir ->isRequired ()) {
@@ -221,7 +271,7 @@ public function getFullPath($rootDir, $childDir) {
221
271
$ childDirId = $ childObj !== null ? $ childObj ->id () : '- ' ;
222
272
throw new FilesException (sprintf ('Cannot build a full path because either the root directory, the child directory or both are not defined. Root directory id "%s". Child directory id "%s" ' , $ rootDirId , $ childDirId ));
223
273
}
224
- return $ rootDirObj -> dir () . ' / ' . $ childObj ->dir ( );
274
+ return $ childObj ->fullAbsolutePath ( $ rootDirObj );
225
275
}
226
276
227
277
/**
0 commit comments