@@ 28-140 (lines=113) @@ | ||
25 | * Class Driver |
|
26 | * @package phpFastCache\Drivers |
|
27 | */ |
|
28 | class Driver implements ExtendedCacheItemPoolInterface |
|
29 | { |
|
30 | use DriverBaseTrait; |
|
31 | ||
32 | /** |
|
33 | * Driver constructor. |
|
34 | * @param array $config |
|
35 | * @throws phpFastCacheDriverException |
|
36 | */ |
|
37 | public function __construct(array $config = []) |
|
38 | { |
|
39 | $this->setup($config); |
|
40 | ||
41 | if (!$this->driverCheck()) { |
|
42 | throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); |
|
43 | } |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @return bool |
|
48 | */ |
|
49 | public function driverCheck() |
|
50 | { |
|
51 | return true; |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * @param \Psr\Cache\CacheItemInterface $item |
|
56 | * @return mixed |
|
57 | * @throws \InvalidArgumentException |
|
58 | */ |
|
59 | protected function driverWrite(CacheItemInterface $item) |
|
60 | { |
|
61 | /** |
|
62 | * Check for Cross-Driver type confusion |
|
63 | */ |
|
64 | if ($item instanceof Item) { |
|
65 | return false; |
|
66 | } else { |
|
67 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * @param \Psr\Cache\CacheItemInterface $item |
|
73 | * @return array [ |
|
74 | * 'd' => 'THE ITEM DATA' |
|
75 | * 't' => 'THE ITEM DATE EXPIRATION' |
|
76 | * 'g' => 'THE ITEM TAGS' |
|
77 | * ] |
|
78 | */ |
|
79 | protected function driverRead(CacheItemInterface $item) |
|
80 | { |
|
81 | return [ |
|
82 | self::DRIVER_DATA_WRAPPER_INDEX => true, |
|
83 | self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
84 | self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), |
|
85 | ]; |
|
86 | } |
|
87 | ||
88 | /** |
|
89 | * @param \Psr\Cache\CacheItemInterface $item |
|
90 | * @return bool |
|
91 | * @throws \InvalidArgumentException |
|
92 | */ |
|
93 | protected function driverDelete(CacheItemInterface $item) |
|
94 | { |
|
95 | /** |
|
96 | * Check for Cross-Driver type confusion |
|
97 | */ |
|
98 | if ($item instanceof Item) { |
|
99 | return false; |
|
100 | } else { |
|
101 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
102 | } |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * @return bool |
|
107 | */ |
|
108 | protected function driverClear() |
|
109 | { |
|
110 | return false; |
|
111 | } |
|
112 | ||
113 | /** |
|
114 | * @return bool |
|
115 | */ |
|
116 | protected function driverConnect() |
|
117 | { |
|
118 | return false; |
|
119 | } |
|
120 | ||
121 | /******************** |
|
122 | * |
|
123 | * PSR-6 Extended Methods |
|
124 | * |
|
125 | *******************/ |
|
126 | ||
127 | /** |
|
128 | * @return driverStatistic |
|
129 | */ |
|
130 | public function getStats() |
|
131 | { |
|
132 | $stat = new driverStatistic(); |
|
133 | $stat->setInfo('[Devtrue] A void info string') |
|
134 | ->setSize(0) |
|
135 | ->setData(implode(', ', array_keys($this->itemInstances))) |
|
136 | ->setRawData(true); |
|
137 | ||
138 | return $stat; |
|
139 | } |
|
140 | } |
@@ 28-139 (lines=112) @@ | ||
25 | * Class Driver |
|
26 | * @package phpFastCache\Drivers |
|
27 | */ |
|
28 | class Driver implements ExtendedCacheItemPoolInterface |
|
29 | { |
|
30 | use DriverBaseTrait; |
|
31 | ||
32 | /** |
|
33 | * Driver constructor. |
|
34 | * @param array $config |
|
35 | * @throws phpFastCacheDriverException |
|
36 | */ |
|
37 | public function __construct(array $config = []) |
|
38 | { |
|
39 | $this->setup($config); |
|
40 | ||
41 | if (!$this->driverCheck()) { |
|
42 | throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); |
|
43 | } |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * @return bool |
|
48 | */ |
|
49 | public function driverCheck() |
|
50 | { |
|
51 | return true; |
|
52 | } |
|
53 | ||
54 | /** |
|
55 | * @param \Psr\Cache\CacheItemInterface $item |
|
56 | * @return mixed |
|
57 | * @throws \InvalidArgumentException |
|
58 | */ |
|
59 | protected function driverWrite(CacheItemInterface $item) |
|
60 | { |
|
61 | /** |
|
62 | * Check for Cross-Driver type confusion |
|
63 | */ |
|
64 | if ($item instanceof Item) { |
|
65 | return true; |
|
66 | } else { |
|
67 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
68 | } |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * @param \Psr\Cache\CacheItemInterface $item |
|
73 | * @return array [ |
|
74 | * 'd' => 'THE ITEM DATA' |
|
75 | * 't' => 'THE ITEM DATE EXPIRATION' |
|
76 | * 'g' => 'THE ITEM TAGS' |
|
77 | * ] |
|
78 | */ |
|
79 | protected function driverRead(CacheItemInterface $item) |
|
80 | { |
|
81 | return [ |
|
82 | self::DRIVER_DATA_WRAPPER_INDEX => false, |
|
83 | self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
84 | self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(), |
|
85 | ]; |
|
86 | } |
|
87 | /** |
|
88 | * @param \Psr\Cache\CacheItemInterface $item |
|
89 | * @return bool |
|
90 | * @throws \InvalidArgumentException |
|
91 | */ |
|
92 | protected function driverDelete(CacheItemInterface $item) |
|
93 | { |
|
94 | /** |
|
95 | * Check for Cross-Driver type confusion |
|
96 | */ |
|
97 | if ($item instanceof Item) { |
|
98 | return true; |
|
99 | } else { |
|
100 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
|
101 | } |
|
102 | } |
|
103 | ||
104 | /** |
|
105 | * @return bool |
|
106 | */ |
|
107 | protected function driverClear() |
|
108 | { |
|
109 | return true; |
|
110 | } |
|
111 | ||
112 | /** |
|
113 | * @return bool |
|
114 | */ |
|
115 | protected function driverConnect() |
|
116 | { |
|
117 | return true; |
|
118 | } |
|
119 | ||
120 | /******************** |
|
121 | * |
|
122 | * PSR-6 Extended Methods |
|
123 | * |
|
124 | *******************/ |
|
125 | ||
126 | /** |
|
127 | * @return driverStatistic |
|
128 | */ |
|
129 | public function getStats() |
|
130 | { |
|
131 | $stat = new driverStatistic(); |
|
132 | $stat->setInfo('[Devfalse] A void info string') |
|
133 | ->setSize(0) |
|
134 | ->setData(implode(', ', array_keys($this->itemInstances))) |
|
135 | ->setRawData(false); |
|
136 | ||
137 | return $stat; |
|
138 | } |
|
139 | } |