Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
namespace Kevinrob\GuzzleCache\Storage;
4
 
5
use Kevinrob\GuzzleCache\CacheEntry;
6
use League\Flysystem\Filesystem;
1441 ariadna 7
use League\Flysystem\FilesystemAdapter;
8
use League\Flysystem\FilesystemException;
1 efrain 9
 
10
class FlysystemStorage implements CacheStorageInterface
11
{
12
 
13
    /**
14
     * @var Filesystem
15
     */
16
    protected $filesystem;
17
 
1441 ariadna 18
    public function __construct(FilesystemAdapter $adapter)
1 efrain 19
    {
20
        $this->filesystem = new Filesystem($adapter);
21
    }
22
 
23
    /**
24
     * @inheritdoc
25
     */
26
    public function fetch($key)
27
    {
1441 ariadna 28
        if ($this->filesystem->fileExists($key)) {
1 efrain 29
            // The file exist, read it!
30
            $data = @unserialize(
31
                $this->filesystem->read($key)
32
            );
33
 
34
            if ($data instanceof CacheEntry) {
35
                return $data;
36
            }
37
        }
38
 
39
        return;
40
    }
41
 
42
    /**
43
     * @inheritdoc
44
     */
45
    public function save($key, CacheEntry $data)
46
    {
1441 ariadna 47
      try {
48
        $this->filesystem->write($key, serialize($data));
49
        return true;
50
      } catch (FilesystemException $e) {
51
        return false;
52
      }
1 efrain 53
    }
54
 
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function delete($key)
59
    {
60
        try {
1441 ariadna 61
            $this->filesystem->delete($key);
1 efrain 62
            return true;
1441 ariadna 63
        } catch (FilesystemException $ex) {
64
            return true;
1 efrain 65
        }
66
    }
67
}