8000 [Config] Add DirectoryExistenceResource · symfony/symfony@b1a2af6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b1a2af6

Browse files
committed
[Config] Add DirectoryExistenceResource
1 parent 8c5ef68 commit b1a2af6

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Resource;
13+
14+
/**
15+
* Represents the existence of a directory.
16+
* Freshness is only evaluated against resource creation or deletion.
17+
*
18+
* @author Robin Chalas <robin.chalas@gmail.com>
19+
*/
20+
class DirectoryExistenceResource implements SelfCheckingResourceInterface, \Serializable
21+
{
22+
private $resource;
23+
private $exists;
24+
25+
public function __construct($resource)
26+
{
27+
$this->resource = (string) $resource;
28+
$this->exists = is_dir($resource);
29+
}
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function __toString()
35+
{
36+
return $this->resource;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public function getResource()
43+
{
44+
return $this->resource;
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function isFresh($timestamp)
51+
{
52+
return is_dir($this->resource) === $this->exists;
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function serialize()
59+
{
60+
return serialize(array($this->resource, $this->exists));
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function unserialize($serialized)
67+
{
68+
list($this->resource, $this->exists) = unserialize($serialized);
69+
}
70+
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* FileExistenceResource represents a resource stored on the filesystem.
1616
* Freshness is only evaluated against resource creation or deletion.
1717
*
18-
* The resource can be a file or a directory.
19-
*
2018
* @author Charles-Henri Bruyand <charleshenri.bruyand@gmail.com>
2119
*/
2220
class FileExistenceResource implements SelfCheckingResourceInterface, \Serializable
@@ -34,6 +32,10 @@ public function __construct($resource)
3432
{
3533
$this->resource = (string) $resource;
3634
$this->exists = file_exists($resource);
35+
36+
if (is_dir($resource)) {
37+
@trigger_error(sprintf('Passing a directory to %s is deprecated since version 3.3, use %s instead.', __CLASS__, DirectoryExistenceResource::class), E_USER_DEPRECATED);
38+
}
3739
}
3840

3941
/**

0 commit comments

Comments
 (0)
0