8000 [Config] moved DirectoryResource childs retrieving to the special get… · symfony/symfony@6b39688 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b39688

Browse files
committed
[Config] moved DirectoryResource childs retrieving to the special getFilteredChilds method
1 parent 45df2e6 commit 6b39688

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

src/Symfony/Component/Config/Resource/DirectoryResource.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,46 @@ 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+
* @param Boolean $recursive search for files recursive
40+
*
41+
* @return array An array of files
42+
*/
43+
public function getFilteredChilds($recursive = true)
44+
{
45+
$iterator = $recursive
46+
? new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->resource), \RecursiveIteratorIterator::SELF_FIRST)
47+
: new \DirectoryIterator($this->resource);
48+
49+
$childs = array();
50+
foreach ($iterator as $file) {
51+
// if regex filtering is enabled only return matching files
52+
if (isset($this->filterRegexList) && $file->isFile()) {
53+
$regexMatched = false;
54+
foreach ($this->filterRegexList as $regex) {
55+
if (preg_match($regex, (string) $file)) {
56+
$regexMatched = true;
57+
}
58+
}
59+
if (!$regexMatched) {
60+
continue;
61+
}
62+
}
63+
64+
// always monitor directories for changes, except the .. entries
65+
// (otherwise deleted files wouldn't get detected)
66+
if ($file->isDir() && '/..' === substr($file, -3)) {
67+
continue;
68+
}
69+
70+
$childs[] = $file;
71+
}
72+
73+
return $childs;
74+
}
75+
3676
/**
3777
* Returns a string representation of the Resource.
3878
*
@@ -66,24 +106,9 @@ public function getPattern()
66106
public function getModificationTime()
67107
{
68108
clearstatcache(true, $this->resource);
69-
70-
if (!is_dir($this->resource)) {
71-
return false;
72-
}
73-
74109
$newestMTime = filemtime($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 && $file->isFile() && !preg_match($this->pattern, $file->getBasename())) {
78-
continue;
79-
}
80-
81-
// always monitor directories for changes, except the .. entries
82-
// (otherwise deleted files wouldn't get detected)
83-
if ($file->isDir() && '/..' === substr($file, -3)) {
84-
continue;
85-
}
86110

111+
foreach ($this->getFilteredChilds() as $file) {
87112
clearstatcache(true, (string) $file);
88113
$newestMTime = max($file->getMTime(), $newestMTime);
89114
}

src/Symfony/Component/Config/Tests/Resource/DirectoryResourceTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public function testIsFreshModifySubdirectory()
161161

162162
/**
163163
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
164+
* @covers Symfony\Component\Config\Resource\DirectoryResource::getFilteredChilds
164165
*/
165166
public function testFilterRegexListNoMatch()
166167
{

0 commit comments

Comments
 (0)
0