8000 Revert "merged branch everzet/config-additions-from-rw (PR #4619)" · lchenay/symfony@0d4b02e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0d4b02e

Browse files
committed
Revert "merged branch everzet/config-additions-from-rw (PR symfony#4619)"
This reverts commit 041286e, reversing changes made to 4c8ea31.
1 parent 0f9be2f commit 0d4b02e

File tree

5 files changed

+23
-359
lines changed

5 files changed

+23
-359
lines changed

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

Lines changed: 17 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
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-
$iterator = new \RecursiveIteratorIterator(
48-
new \RecursiveDirectoryIterator($this->resource, \FilesystemIterator::SKIP_DOTS),
49-
\RecursiveIteratorIterator::SELF_FIRST
50-
);
51-
52-
$childs = array();
53-
foreach ($iterator as $file) {
54-
// if regex filtering is enabled only return matching files
55-
if ($file->isFile() && !$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 ($file->isDir() && '/..' === substr($file, -3)) {
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-
$iterator = new \DirectoryIterator($this->resource);
83-
84-
$resources = array();
85-
foreach ($iterator as $file) {
86-
// if regex filtering is enabled only return matching files
87-
if ($file->isFile() && !$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 ($file->isDir() && '/..' === substr($file, -3)) {
94-
continue;
95-
}
96-
97-
// if file is dot - continue
98-
if ($file->isDot()) {
99-
continue;
100-
}
101-
102-
if ($file->isFile()) {
103-
$resources[] = new FileResource($file->getRealPath());
104-
} elseif ($file->isDir()) {
105-
$resources[] = new DirectoryResource($file->getRealPath());
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 (!$file instanceof \SplFileInfo) {
152-
$file = new \SplFileInfo($file);
153-
}
154-
155-
if (0 !== strpos($file->getRealPath(), realpath($this->resource))) {
156-
return false;
157-
}
158-
159-
if ($this->pattern) {
160-
return (bool) preg_match($this->pattern, $file->getBasename());
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-
$newestMTime = filemtime($this->resource);
179-
180-
foreach ($this->getFilteredChilds() as $file) {
181-
clearstatcache(true, (string) $file);
182-
$newestMTime = max($file->getMTime(), $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 10000
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+
$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+
}
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 ($file->isDir() && '/..' === substr($file, -3)) {
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+
$newestMTime = max($file->getMTime(), $newestMTime);
88+
}
89+
90+
return $newestMTime < $timestamp;
22291
}
22392

22493
public function serialize()

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

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
* @author Fabien Potencier <fabien@symfony.com>
2020
*/
21-
class FileResource implements ResourceInterface
21+
class FileResource implements ResourceInterface, \Serializable
2222
{
2323
private $resource;
2424

@@ -29,7 +29,7 @@ class FileResource implements ResourceInterface
2929
*/
3030
public function __construct($resource)
3131
{
32-
$this->resource = file_exists($resource) ? realpath($resource) : $resource;
32+
$this->resource = realpath($resource);
3333
}
3434

3535
/**
@@ -52,22 +52,6 @@ public function getResource()
5252
return $this->resource;
5353
}
5454

55-
/**
56-
* Returns resource mtime.
57-
*
58-
* @return integer
59-
*/
60-
public function getModificationTime()
61-
{
62-
if (!$this->exists()) {
63-
return -1;
64-
}
65-
66-
clearstatcache(true, $this->resource);
67-
68-
return filemtime($this->resource);
69-
}
70-
7155
/**
7256
* Returns true if the resource has not been updated since the given timestamp.
7357
*
@@ -77,31 +61,11 @@ public function getModificationTime()
7761
*/
7862
public function isFresh($timestamp)
7963
{
80-
if (!$this->exists()) {
64+
if (!file_exists($this->resource)) {
8165
return false;
8266
}
8367

84-
return $this->getModificationTime() <= $timestamp;
85-
}
86-
87-
/**
88-
* Returns true if the resource exists in the filesystem.
89-
*
90-
* @return Boolean
91-
*/
92-
public function exists()
93-
{
94-
return is_file($this->resource);
95-
}
96-
97-
/**
98-
* Returns unique resource ID.
99-
*
100-
* @return string
101-
*/
102-
public function getId()
103-
{
104-
return md5('f'.$this->resource);
68+
return filemtime($this->resource) < $timestamp;
10569
}
10670

10771
public function serialize()

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

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Fabien Potencier <fabien@symfony.com>
1818
*/
19-
interface ResourceInterface extends \Serializable
19+
interface ResourceInterface
2020
{
2121
/**
2222
* Returns a string representation of the Resource.
@@ -34,31 +34,10 @@ function __toString();
3434
*/
3535
function isFresh($timestamp);
3636

37-
/**
38-
* Returns resource mtime.
39-
*
40-
* @return integer
41-
*/
42-
function getModificationTime();
43-
44-
/**
45-
* Returns true if the resource exists in the filesystem.
46-
*
47-
* @return Boolean
48-
*/
49-
function exists();
50-
5137
/**
5238
* Returns the resource tied to this Resource.
5339
*
5440
* @return mixed The resource
5541
*/
5642
function getResource();
57-
58-
/**
59-
* Returns unique resource ID.
60-
*
61-
* @return string
62-
*/
63-
function getId();
6443
}

0 commit comments

Comments
 (0)
0