1616 * 
1717 * @author Fabien Potencier <fabien@symfony.com> 
1818 */ 
19- class  DirectoryResource implements  ResourceInterface
19+ class  DirectoryResource implements  ResourceInterface, \Serializable 
2020{
2121 private  $ resource
2222 private  $ pattern
@@ -33,82 +33,6 @@ public function __construct($resource, $pattern = null)
3333 $ this pattern  = $ pattern
3434 }
3535
36-  /** 
37-  * Returns the list of filtered file and directory childs of directory resource. 
38-  * 
39-  * @return array An array of files 
40-  */ 
41-  public  function  getFilteredChilds ()
42-  {
43-  if  (!$ this exists ()) {
44-  return  array ();
45-  }
46- 
47-  $ iteratornew  \RecursiveIteratorIterator (
48-  new  \RecursiveDirectoryIterator ($ this resource , \FilesystemIterator::SKIP_DOTS ),
49-  \RecursiveIteratorIterator::SELF_FIRST 
50-  );
51- 
52-  $ childsarray ();
53-  foreach  ($ iteratoras  $ file
54-  // if regex filtering is enabled only return matching files 
55-  if  ($ fileisFile () && !$ this hasFile ($ file
56-  continue ;
57-  }
58- 
59-  // always monitor directories for changes, except the .. entries 
60-  // (otherwise deleted files wouldn't get detected) 
61-  if  ($ fileisDir () && '/.. '  === substr ($ file3 )) {
62-  continue ;
63-  }
64- 
65-  $ childs$ file
66-  }
67- 
68-  return  $ childs
69-  }
70- 
71-  /** 
72-  * Returns child resources that matches directory filters. 
73-  * 
74-  * @return array 
75-  */ 
76-  public  function  getFilteredResources ()
77-  {
78-  if  (!$ this exists ()) {
79-  return  array ();
80-  }
81- 
82-  $ iteratornew  \DirectoryIterator ($ this resource );
83- 
84-  $ resourcesarray ();
85-  foreach  ($ iteratoras  $ file
86-  // if regex filtering is enabled only return matching files 
87-  if  ($ fileisFile () && !$ this hasFile ($ file
88-  continue ;
89-  }
90- 
91-  // always monitor directories for changes, except the .. entries 
92-  // (otherwise deleted files wouldn't get detected) 
93-  if  ($ fileisDir () && '/.. '  === substr ($ file3 )) {
94-  continue ;
95-  }
96- 
97-  // if file is dot - continue 
98-  if  ($ fileisDot ()) {
99-  continue ;
100-  }
101- 
102-  if  ($ fileisFile ()) {
103-  $ resourcesnew  FileResource ($ filegetRealPath ());
104-  } elseif  ($ fileisDir ()) {
105-  $ resourcesnew  DirectoryResource ($ filegetRealPath ());
106-  }
107-  }
108- 
109-  return  $ resources
110-  }
111- 
11236 /** 
11337 * Returns a string representation of the Resource. 
11438 * 
@@ -129,62 +53,11 @@ public function getResource()
12953 return  $ this resource ;
13054 }
13155
132-  /** 
133-  * Returns check pattern. 
134-  * 
135-  * @return mixed 
136-  */ 
13756 public  function  getPattern ()
13857 {
13958 return  $ this pattern ;
14059 }
14160
142-  /** 
143-  * Checks that passed file exists in resource and matches resource filters. 
144-  * 
145-  * @param SplFileInfo|string $file 
146-  * 
147-  * @return Boolean 
148-  */ 
149-  public  function  hasFile ($ file
150-  {
151-  if  (!$ fileinstanceof  \SplFileInfo) {
152-  $ filenew  \SplFileInfo ($ file
153-  }
154- 
155-  if  (0  !== strpos ($ filegetRealPath (), realpath ($ this resource ))) {
156-  return  false ;
157-  }
158- 
159-  if  ($ this pattern ) {
160-  return  (bool ) preg_match ($ this pattern , $ filegetBasename ());
161-  }
162- 
163-  return  true ;
164-  }
165- 
166-  /** 
167-  * Returns resource mtime. 
168-  * 
169-  * @return integer 
170-  */ 
171-  public  function  getModificationTime ()
172-  {
173-  if  (!$ this exists ()) {
174-  return  -1 ;
175-  }
176- 
177-  clearstatcache (true , $ this resource );
178-  $ newestMTimefilemtime ($ this resource );
179- 
180-  foreach  ($ this getFilteredChilds () as  $ file
181-  clearstatcache (true , (string ) $ file
182-  $ newestMTimemax ($ filegetMTime (), $ newestMTime
183-  }
184- 
185-  return  $ newestMTime
186-  }
187- 
18861 /** 
18962 * Returns true if the resource has not been updated since the given timestamp. 
19063 * 
@@ -194,31 +67,27 @@ public function getModificationTime()
19467 */ 
19568 public  function  isFresh ($ timestamp
19669 {
197-  if  (!$ this exists ( )) {
70+  if  (!is_dir ( $ this resource )) {
19871 return  false ;
19972 }
20073
201-  return  $ this getModificationTime () < $ timestamp
202-  }
74+  $ newestMTimefilemtime ($ this resource );
75+  foreach  (new  \RecursiveIteratorIterator (new  \RecursiveDirectoryIterator ($ this resource ), \RecursiveIteratorIterator::SELF_FIRST ) as  $ file
76+  // if regex filtering is enabled only check matching files 
77+  if  ($ this pattern  && $ fileisFile () && !preg_match ($ this pattern , $ filegetBasename ())) {
78+  continue ;
79+  }
20380
204-  /** 
205-  * Returns true if the resource exists in the filesystem. 
206-  * 
207-  * @return Boolean 
208-  */ 
209-  public  function  exists ()
210-  {
211-  return  is_dir ($ this resource );
212-  }
81+  // always monitor directories for changes, except the .. entries 
82+  // (otherwise deleted files wouldn't get detected) 
83+  if  ($ fileisDir () && '/.. '  === substr ($ file3 )) {
84+  continue ;
85+  }
21386
214-  /** 
215-  * Returns unique resource ID. 
216-  * 
217-  * @return string 
218-  */ 
219-  public  function  getId ()
220-  {
221-  return  md5 ('d ' .$ this resource .$ this pattern );
87+  $ newestMTimemax ($ filegetMTime (), $ newestMTime
88+  }
89+ 
90+  return  $ newestMTime$ timestamp
22291 }
22392
22493 public  function  serialize ()
0 commit comments