woocommerce-pos
/
vendor_prefixed
/
phpfastcache
/
phpfastcache
/
lib
/
Phpfastcache
/
Drivers
/
Files
/
Driver.php
Driver.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.15, at vendor_prefixed/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * |
| 5 | * This file is part of phpFastCache. |
| 6 | * |
| 7 | * @license MIT License (MIT) |
| 8 | * |
| 9 | * For full copyright and license information, please see the docs/CREDITS.txt file. |
| 10 | * |
| 11 | * @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> https://www.phpfastcache.com |
| 12 | * @author Georges.L (Geolim4) <contact@geolim4.com> |
| 13 | * |
| 14 | */ |
| 15 | declare (strict_types=1); |
| 16 | namespace WCPOS\Vendor\Phpfastcache\Drivers\Files; |
| 17 | |
| 18 | use Exception; |
| 19 | use FilesystemIterator; |
| 20 | use WCPOS\Vendor\Phpfastcache\Cluster\AggregatablePoolInterface; |
| 21 | use WCPOS\Vendor\Phpfastcache\Core\Pool\DriverBaseTrait; |
| 22 | use WCPOS\Vendor\Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; |
| 23 | use WCPOS\Vendor\Phpfastcache\Core\Pool\IO\IOHelperTrait; |
| 24 | use WCPOS\Vendor\Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; |
| 25 | use WCPOS\Vendor\Phpfastcache\Exceptions\PhpfastcacheIOException; |
| 26 | use WCPOS\Vendor\Phpfastcache\Util\Directory; |
| 27 | use WCPOS\Vendor\Psr\Cache\CacheItemInterface; |
| 28 | /** |
| 29 | * Class Driver |
| 30 | * @package phpFastCache\Drivers |
| 31 | * @property Config $config Config object |
| 32 | * @method Config getConfig() Return the config object |
| 33 | * |
| 34 | * Important NOTE: |
| 35 | * We are using getKey instead of getEncodedKey since this backend create filename that are |
| 36 | * managed by defaultFileNameHashFunction and not defaultKeyHashFunction |
| 37 | */ |
| 38 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
| 39 | { |
| 40 | use IOHelperTrait; |
| 41 | use DriverBaseTrait { |
| 42 | DriverBaseTrait::__construct as private __parentConstruct; |
| 43 | } |
| 44 | /** |
| 45 | * Driver constructor. |
| 46 | * @param Config $config |
| 47 | * @param string $instanceId |
| 48 | */ |
| 49 | public function __construct(Config $config, string $instanceId) |
| 50 | { |
| 51 | $this->__parentConstruct($config, $instanceId); |
| 52 | } |
| 53 | /** |
| 54 | * @return bool |
| 55 | */ |
| 56 | public function driverCheck() : bool |
| 57 | { |
| 58 | return \is_writable($this->getPath()) || \mkdir($concurrentDirectory = $this->getPath(), $this->getDefaultChmod(), \true) || \is_dir($concurrentDirectory); |
| 59 | } |
| 60 | /** |
| 61 | * @return bool |
| 62 | */ |
| 63 | protected function driverConnect() : bool |
| 64 | { |
| 65 | return \true; |
| 66 | } |
| 67 | /** |
| 68 | * @param CacheItemInterface $item |
| 69 | * @return null|array |
| 70 | */ |
| 71 | protected function driverRead(CacheItemInterface $item) |
| 72 | { |
| 73 | $file_path = $this->getFilePath($item->getKey(), \true); |
| 74 | try { |
| 75 | $content = $this->readFile($file_path); |
| 76 | } catch (PhpfastcacheIOException $e) { |
| 77 | return null; |
| 78 | } |
| 79 | return $this->decode($content); |
| 80 | } |
| 81 | /** |
| 82 | * @param CacheItemInterface $item |
| 83 | * @return bool |
| 84 | * @throws PhpfastcacheInvalidArgumentException |
| 85 | */ |
| 86 | protected function driverWrite(CacheItemInterface $item) : bool |
| 87 | { |
| 88 | /** |
| 89 | * Check for Cross-Driver type confusion |
| 90 | */ |
| 91 | if ($item instanceof Item) { |
| 92 | $file_path = $this->getFilePath($item->getKey()); |
| 93 | $data = $this->encode($this->driverPreWrap($item)); |
| 94 | /** |
| 95 | * Force write |
| 96 | */ |
| 97 | try { |
| 98 | return $this->writefile($file_path, $data, $this->getConfig()->isSecureFileManipulation()); |
| 99 | } catch (Exception $e) { |
| 100 | return \false; |
| 101 | } |
| 102 | } |
| 103 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
| 104 | } |
| 105 | /** |
| 106 | * @param CacheItemInterface $item |
| 107 | * @return bool |
| 108 | * @throws PhpfastcacheInvalidArgumentException |
| 109 | */ |
| 110 | protected function driverDelete(CacheItemInterface $item) : bool |
| 111 | { |
| 112 | /** |
| 113 | * Check for Cross-Driver type confusion |
| 114 | */ |
| 115 | if ($item instanceof Item) { |
| 116 | $file_path = $this->getFilePath($item->getKey(), \true); |
| 117 | if (\file_exists($file_path) && @\unlink($file_path)) { |
| 118 | \clearstatcache(\true, $file_path); |
| 119 | $dir = \dirname($file_path); |
| 120 | if (!(new FilesystemIterator($dir))->valid()) { |
| 121 | \rmdir($dir); |
| 122 | } |
| 123 | return \true; |
| 124 | } |
| 125 | return \false; |
| 126 | } |
| 127 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
| 128 | } |
| 129 | /** |
| 130 | * @return bool |
| 131 | * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException |
| 132 | */ |
| 133 | protected function driverClear() : bool |
| 134 | { |
| 135 | return Directory::rrmdir($this->getPath(\true)); |
| 136 | } |
| 137 | } |
| 138 |