scratch – Blame information for rev
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | /* |
||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
14 | * |
||
15 | * This software consists of voluntary contributions made by many individuals |
||
16 | * and is licensed under the MIT license. For more information, see |
||
17 | * <http://www.doctrine-project.org>. |
||
18 | */ |
||
19 | |||
20 | namespace Doctrine\Common\Cache; |
||
21 | |||
22 | /** |
||
23 | * Filesystem cache driver. |
||
24 | * |
||
25 | * @since 2.3 |
||
26 | * @author Fabio B. Silva <fabio.bat.silva@gmail.com> |
||
27 | */ |
||
28 | class FilesystemCache extends FileCache |
||
29 | { |
||
30 | const EXTENSION = '.doctrinecache.data'; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function __construct($directory, $extension = self::EXTENSION, $umask = 0002) |
||
36 | { |
||
37 | parent::__construct($directory, $extension, $umask); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | protected function doFetch($id) |
||
44 | { |
||
45 | $data = ''; |
||
46 | $lifetime = -1; |
||
47 | $filename = $this->getFilename($id); |
||
48 | |||
49 | if ( ! is_file($filename)) { |
||
50 | return false; |
||
51 | } |
||
52 | |||
53 | $resource = fopen($filename, "r"); |
||
54 | |||
55 | if (false !== ($line = fgets($resource))) { |
||
56 | $lifetime = (int) $line; |
||
57 | } |
||
58 | |||
59 | if ($lifetime !== 0 && $lifetime < time()) { |
||
60 | fclose($resource); |
||
61 | |||
62 | return false; |
||
63 | } |
||
64 | |||
65 | while (false !== ($line = fgets($resource))) { |
||
66 | $data .= $line; |
||
67 | } |
||
68 | |||
69 | fclose($resource); |
||
70 | |||
71 | return unserialize($data); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | protected function doContains($id) |
||
78 | { |
||
79 | $lifetime = -1; |
||
80 | $filename = $this->getFilename($id); |
||
81 | |||
82 | if ( ! is_file($filename)) { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | $resource = fopen($filename, "r"); |
||
87 | |||
88 | if (false !== ($line = fgets($resource))) { |
||
89 | $lifetime = (int) $line; |
||
90 | } |
||
91 | |||
92 | fclose($resource); |
||
93 | |||
94 | return $lifetime === 0 || $lifetime > time(); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | protected function doSave($id, $data, $lifeTime = 0) |
||
101 | { |
||
102 | if ($lifeTime > 0) { |
||
103 | $lifeTime = time() + $lifeTime; |
||
104 | } |
||
105 | |||
106 | $data = serialize($data); |
||
107 | $filename = $this->getFilename($id); |
||
108 | |||
109 | return $this->writeFile($filename, $lifeTime . PHP_EOL . $data); |
||
110 | } |
||
111 | } |