@@ -18,13 +18,13 @@ class Files {
1818 * @var RootDirCollection Container with all root directories
1919 *
2020 */
21- private $ _rootDirs ;
21+ private $ _rootDirCollection ;
2222
2323 /**
2424 * @var ChildDirCollection Container with all child directories
2525 *
2626 */
27- private $ _childDirs ;
27+ private $ _childDirCollection ;
2828
2929 /**
3030 * @var FilesQuery Query object for each Files instance
@@ -35,16 +35,16 @@ class Files {
3535 const DEFAULT_EXTENSION = 'php ' ;
3636
3737 function __construct () {
38- $ this ->_rootDirs = new RootDirCollection ();
39- $ this ->_childDirs = new ChildDirCollection ();
38+ $ this ->_rootDirCollection = new RootDirCollection ();
39+ $ this ->_childDirCollection = new ChildDirCollection ();
4040 $ this ->_query = new FilesQuery ($ this );
4141 }
4242
4343 /**
4444 * @return RootDirCollection
4545 */
46- protected function _rootDirs () {
47- return $ this ->_rootDirs ;
46+ protected function _rootCollection () {
47+ return $ this ->_rootDirCollection ;
4848 }
4949
5050 /**
@@ -53,70 +53,95 @@ protected function _rootDirs() {
5353 * @return RootDir|false
5454 */
5555 public function addRootDir (RootDir $ rootDir , $ index = null ) {
56- $ rootDir = $ this ->_rootDirs ()->addRootDir ($ rootDir , $ index );
56+ $ rootDir = $ this ->_rootCollection ()->addRootDir ($ rootDir , $ index );
5757 return $ this ->isValid () === true ? $ rootDir : false ;
5858 }
5959
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+
6085 /**
6186 * @return RootDir[]
6287 */
6388 public function rootDirs () {
64- return $ this ->_rootDirs ()->dirs ();
89+ return $ this ->_rootCollection ()->dirs ();
6590 }
6691
6792 /**
6893 * @param RootDir $rootDir RootDir that will be checked
6994 * @return bool Returns true if RootDir is part of this files instance
7095 */
7196 public function containsRootDir (RootDir $ rootDir ) {
72- return $ this ->_rootDirs ()->isInCollection ($ rootDir );
97+ return $ this ->_rootCollection ()->isInCollection ($ rootDir );
7398 }
7499
75100 /**
76101 * @return int Total root directories
77102 */
78103 public function totalRootDirs () {
79- return $ this ->_rootDirs ()->totalDirs ();
104+ return $ this ->_rootCollection ()->totalDirs ();
80105 }
81106
82107 /**
83108 * @param string|RootDir $rootDir
84109 * @return RootDir|null
85110 */
86111 public function getRootDir ($ rootDir ) {
87- return $ this ->_rootDirs ()->getDir ($ rootDir );
112+ return $ this ->_rootCollection ()->getDir ($ rootDir );
88113 }
89114
90115 /**
91116 * @param string $id
92117 * @return null|RootDir
93118 */
94119 public function getRootDirById ($ id ) {
95- return $ this ->_rootDirs ()->getDirById ($ id );
120+ return $ this ->_rootCollection ()->getDirById ($ id );
96121 }
97122
98123 /**
99124 * @param int $index
100125 * @return RootDir|false
101126 */
102127 public function getRootDirByIndex ($ index ) {
103- return $ this ->_rootDirs ()->getDirByIndex ($ index );
128+ return $ this ->_rootCollection ()->getDirByIndex ($ index );
104129 }
105130
106131 /**
107132 * @return string[]
108133 */
109134 public function getRootPaths () {
110- return $ this ->_rootDirs ()->getPaths ();
135+ return $ this ->_rootCollection ()->getPaths ();
111136 }
112137
113138
114139
115140 /**
116141 * @return ChildDirCollection
117142 */
118- protected function _childDirs () {
119- return $ this ->_childDirs ;
143+ protected function _childCollection () {
144+ return $ this ->_childDirCollection ;
120145 }
121146
122147 /**
@@ -125,61 +150,86 @@ protected function _childDirs() {
125150 * @return ChildDir|false
126151 */
127152 public function addChildDir (ChildDir $ childDir , $ index = null ) {
128- $ childDir = $ this ->_childDirs ()->addChildDir ($ childDir , $ index );
153+ $ childDir = $ this ->_childCollection ()->addChildDir ($ childDir , $ index );
129154 return $ this ->isValid () === true ? $ childDir : false ;
130155 }
131156
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+
132182 /**
133183 * @return ChildDir[]
134184 */
135185 public function childDirs () {
136- return $ this ->_childDirs ()->dirs ();
186+ return $ this ->_childCollection ()->dirs ();
137187 }
138188
139189 /**
140190 * @param ChildDir $childDir Dir that will be checked
141191 * @return bool Returns true if dir is part of this files instance
142192 */
143193 public function containsChildDir (ChildDir $ childDir ) {
144- return $ this ->_childDirs ()->isInCollection ($ childDir );
194+ return $ this ->_childCollection ()->isInCollection ($ childDir );
145195 }
146196
147197 /**
148198 * @return int Total child directories
149199 */
150200 public function totalChildDirs () {
151- return $ this ->_childDirs ()->totalDirs ();
201+ return $ this ->_childCollection ()->totalDirs ();
152202 }
153203
154204 /**
155205 * @param string|ChildDir $childDir
156206 * @return null|ChildDir
157207 */
158208 public function getChildDir ($ childDir ) {
159- return $ this ->_childDirs ()->getDir ($ childDir );
209+ return $ this ->_childCollection ()->getDir ($ childDir );
160210 }
161211
162212 /**
163213 * @param string $id
164214 * @return null|ChildDir
165215 */
166216 public function getChildDirById ($ id ) {
167- return $ this ->_childDirs ()->getDirById ($ id );
217+ return $ this ->_childCollection ()->getDirById ($ id );
168218 }
169219
170220 /**
171221 * @param int $index
172222 * @return ChildDir|false
173223 */
174224 public function getChildDirByIndex ($ index ) {
175- return $ this ->_childDirs ()->getDirByIndex ($ index );
225+ return $ this ->_childCollection ()->getDirByIndex ($ index );
176226 }
177227
178228 /**
179229 * @return string[]
180230 */
181231 public function getChildPaths () {
182- return $ this ->_childDirs ()->getPaths ();
232+ return $ this ->_childCollection ()->getPaths ();
183233 }
184234
185235 /**
@@ -192,7 +242,7 @@ protected function isValid() {
192242 if ($ rootDir ->isRequired ()) {
193243 $ rootDirPath = $ rootDir ->dir ();
194244 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 ));
196246 }
197247 foreach ($ this ->childDirs () as $ childDir ) {
198248 if ($ childDir ->isRequired ()) {
@@ -221,7 +271,7 @@ public function getFullPath($rootDir, $childDir) {
221271 $ childDirId = $ childObj !== null ? $ childObj ->id () : '- ' ;
222272 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 ));
223273 }
224- return $ rootDirObj -> dir () . ' / ' . $ childObj ->dir ( );
274+ return $ childObj ->fullAbsolutePath ( $ rootDirObj );
225275 }
226276
227277 /**
0 commit comments