Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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 Doctrine\Common\Cache\Psr6;
13
 
14
use Doctrine\Common\Cache\Cache;
15
use Doctrine\Common\Cache\CacheProvider;
16
use Psr\Cache\CacheItemPoolInterface;
17
use Symfony\Component\Cache\Adapter\DoctrineAdapter as SymfonyDoctrineAdapter;
18
use Symfony\Contracts\Service\ResetInterface;
19
 
20
use function rawurlencode;
21
 
22
/**
23
 * This class was copied from the Symfony Framework, see the original copyright
24
 * notice above. The code is distributed subject to the license terms in
25
 * https://github.com/symfony/symfony/blob/ff0cf61278982539c49e467db9ab13cbd342f76d/LICENSE
26
 */
27
final class DoctrineProvider extends CacheProvider
28
{
29
    /** @var CacheItemPoolInterface */
30
    private $pool;
31
 
32
    public static function wrap(CacheItemPoolInterface $pool): Cache
33
    {
34
        if ($pool instanceof CacheAdapter) {
35
            return $pool->getCache();
36
        }
37
 
38
        if ($pool instanceof SymfonyDoctrineAdapter) {
39
            $getCache = function () {
40
                // phpcs:ignore Squiz.Scope.StaticThisUsage.Found
41
                return $this->provider;
42
            };
43
 
44
            return $getCache->bindTo($pool, SymfonyDoctrineAdapter::class)();
45
        }
46
 
47
        return new self($pool);
48
    }
49
 
50
    private function __construct(CacheItemPoolInterface $pool)
51
    {
52
        $this->pool = $pool;
53
    }
54
 
55
    /** @internal */
56
    public function getPool(): CacheItemPoolInterface
57
    {
58
        return $this->pool;
59
    }
60
 
61
    public function reset(): void
62
    {
63
        if ($this->pool instanceof ResetInterface) {
64
            $this->pool->reset();
65
        }
66
 
67
        $this->setNamespace($this->getNamespace());
68
    }
69
 
70
    /**
71
     * {@inheritdoc}
72
     */
73
    protected function doFetch($id)
74
    {
75
        $item = $this->pool->getItem(rawurlencode($id));
76
 
77
        return $item->isHit() ? $item->get() : false;
78
    }
79
 
80
    /**
81
     * {@inheritdoc}
82
     *
83
     * @return bool
84
     */
85
    protected function doContains($id)
86
    {
87
        return $this->pool->hasItem(rawurlencode($id));
88
    }
89
 
90
    /**
91
     * {@inheritdoc}
92
     *
93
     * @return bool
94
     */
95
    protected function doSave($id, $data, $lifeTime = 0)
96
    {
97
        $item = $this->pool->getItem(rawurlencode($id));
98
 
99
        if (0 < $lifeTime) {
100
            $item->expiresAfter($lifeTime);
101
        }
102
 
103
        return $this->pool->save($item->set($data));
104
    }
105
 
106
    /**
107
     * {@inheritdoc}
108
     *
109
     * @return bool
110
     */
111
    protected function doDelete($id)
112
    {
113
        return $this->pool->deleteItem(rawurlencode($id));
114
    }
115
 
116
    /**
117
     * {@inheritdoc}
118
     *
119
     * @return bool
120
     */
121
    protected function doFlush()
122
    {
123
        return $this->pool->clear();
124
    }
125
 
126
    /**
127
     * {@inheritdoc}
128
     *
129
     * @return array|null
130
     */
131
    protected function doGetStats()
132
    {
133
        return null;
134
    }
135
}