diff --git a/.gitignore b/.gitignore index 5b14845..f9380db 100644 --- a/.gitignore +++ b/.gitignore @@ -193,8 +193,6 @@ PublishScripts/ csx/ *.build.csdef -._* - # Microsoft Azure Emulator ecf/ rcf/ @@ -330,3 +328,9 @@ ASALocalRun/ # MFractors (Xamarin productivity tool) working folder .mfractor/ + +macOS hidden filesystem meta info +._* + +Zip Files +*.zip \ No newline at end of file diff --git a/README.md b/README.md index 3eae496..477a708 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ A super easy PHP Framework for web development! ## Requirements - - PHP 5.3+ (PHP 7.0+ recommended) - - OPCache PHP Extension - - HTTP Web Server (Apache 2.4+ recommended) + - PHP 5.3+ (PHP 7.0+ recommended with OPCache and igbinary extensions) + - HTTP Web Server (Apache 2.4+ recommended with mod_rewrite) + - Some writable directories (like logs and cache) ## Structure @@ -31,111 +31,114 @@ This is a simple Hello World! for this framework. 1. In **controller** folder, create a folder called *common* and create a file called *home.php*. 2. Edit **controller/common/home.php** like that. - - ```php - data['variable'] = "Hello World!"; - - $this->out(); - } - } - ``` + ```php + data['variable'] = "Hello World!"; + + $this->out(); + } + } + ``` 3. Now create a folder inside view called **default** and a subfolder called **common** and a file home.twig. 4. Edit the **view/default/common/home.twig** like this. - - ```html -

{{ variable }}

- ``` + ```html +

{{ variable }}

+ ``` 5. Edit the constants *HTTP_URL* and *DIR_APPLICATION* in file **config.php**. Edit others *DIR_** constants path if necessary. - ```php - ' - ExacTI phacil', + $configs = array( + 'PatternSiteTitle'=>' - ExacTI phacil', 'config_mail_protocol'=>'smtp', 'config_error_display' => 1, 'config_template' => "default", 'config_error_filename'=> 'error.log'); -//App folders -define('DIR_APPLICATION', '/Applications/MAMP/htdocs/phacil/'); -define('DIR_LOGS', DIR_APPLICATION.'logs/'); -define('DIR_PUBLIC', DIR_APPLICATION.'public_html/'); -define('DIR_SYSTEM', DIR_APPLICATION.'system/'); -define('DIR_IMAGE', DIR_APPLICATION.'public_html/imagens/'); -define('DIR_TEMPLATE', DIR_APPLICATION.'view/'); -define('DIR_CACHE', DIR_APPLICATION.'cache/'); - ``` + //App folders + define('DIR_APPLICATION', '/Applications/MAMP/htdocs/phacil/'); + define('DIR_LOGS', DIR_APPLICATION.'logs/'); + define('DIR_PUBLIC', DIR_APPLICATION.'public_html/'); + define('DIR_SYSTEM', DIR_APPLICATION.'system/'); + define('DIR_IMAGE', DIR_APPLICATION.'public_html/imagens/'); + define('DIR_TEMPLATE', DIR_APPLICATION.'view/'); + define('DIR_CACHE', DIR_APPLICATION.'cache/'); + ``` 6. Access your web app in your favorite browser and enjoy this magnify Hello World! + #### Explanation All routes are a mapping class with extends the primary Controller class. In a simple term, the class name in controller is *Controller****Folder****Filename*. - - `class ControllerFolderFile extends Controller { + + `class ControllerFolderFile extends Controller { }` The public function named `index()` is a default function to generate the page. - - `public function index() { }` - - Array `$this->data` receives in array format the variables to send to template, in this sample called **variable** with the string *Hello World!*. - + + `public function index() { }` + + Array `$this->data` receives in array format the variables to send to template, in this sample called **variable** with the string *Hello World!*. + In the last we finish with a simple `$this->out();` to indicate the output and process template file. It's an automated mechanism to link this controller with the respective viewer. - + The viewer in this sample is a twig template format ([Twig page](https://twig.symfony.com)). ExacTI Phacil Framework permits to use various PHP template engines, like Twig, Mustache, Dwoo and Smarty. - - ## Config file Parameters - + +## Config file Parameters + A simple description of default constants configurations in *config.php* file. - | Constant | Type | Description | Required | - | ----- | ----- | ----- | ----- | - | HTTP_URL | string | Contains the URL for this WEB APP | Yes | - | HTTPS_URL | string | Same this HTTP_URL, but in SSL format | - | HTTP_IMAGE | string | The image URL | - | CDN | string | CDN URL to use for static content | - | DB_CONFIG | boolean | Permit to use configurations direct in database. Requires database installation. Values: true or false. | Yes | - | DEBUG | boolean | Indicate the debug mode. | Yes | - | `$configs` | array | No-SQL configs | - | DIR_APPLICATION | string | Absolute path to application folder | Yes | - | DIR_LOGS | string | Path to log folder | - | DIR_PUBLIC | string | Path to the public folder. This directory is a directory to configure in your HTTP server. | Yes | - | DIR_SYSTEM | string | System directory | Yes | - | DIR_IMAGE | string | Directory to store images used by Image library. | - | DIR_TEMPLATE | string | Directory with templates folder | Yes | - | DIR_CACHE | string | Directory to storage the generated caches. | Yes | - | DIR_CONFIG | string | Directory with extra configs files | - | DB_DRIVER | string | Driver to connect a database source. See below the default's drivers available. | - | DB_HOSTNAME | string | Database host | - | DB_USERNAME | string | Username to connect a database | - | DB_PASSWORD | string | Database password | - | DB_DATABASE | string | Database name | - | SQL_CACHE | boolean | Use the SQL Select cache system | - | ROUTES | array | Specify manually routes | - | DEFAULT_ROUTE | string | Define the default route to assume with initial page. Default is *common/home*. | - | CUSTOM_DB_CONFIG | string | Custom SQL to load application configs in database. | - | NOT_FOUND | string | Custom route to not found page. Default is error/not_found. | - - ## Outputs and renders - - Phacil Framework count with three methods for output content: `$this->response->setOutput()`, `$this->render()` and `$this->out()`. - - ### setOutput +| Constant | Type | Description | Required | +| ----- | ----- | ----- | ----- | +| HTTP_URL | string | Contains the URL for this WEB APP | Yes | +| HTTPS_URL | string | Same this HTTP_URL, but in SSL format | +| HTTP_IMAGE | string | The image URL | +| CDN | string | CDN URL to use for static content | +| DB_CONFIG | boolean | Permit to use configurations direct in database. Requires database installation. Values: true or false. | Yes | +| DEBUG | boolean | Indicate the debug mode. | Yes | +| `$configs` | array | No-SQL configs | +| DIR_APPLICATION | string | Absolute path to application folder | Yes | +| DIR_LOGS | string | Path to log folder | +| DIR_PUBLIC | string | Path to the public folder. This directory is a directory to configure in your HTTP server. | Yes | +| DIR_SYSTEM | string | System directory | Yes | +| DIR_IMAGE | string | Directory to store images used by Image library. | +| DIR_TEMPLATE | string | Directory with templates folder | Yes | +| DIR_CACHE | string | Directory to storage the generated caches. | Yes | +| CACHE_EXPIRE | timestamp | Time in UNIX timestamp format with seconds for valid cache. Default value is 3600. (1 Hour) | +| CACHE_DRIVER | string | Cache method for Phpfastcache. Default is file. | +| CACHE_SETTINGS | array | Settings for Phpfastcache (https://www.phpfastcache.com). | +| DIR_CONFIG | string | Directory with extra configs files | +| DB_DRIVER | string | Driver to connect a database source. See below the default's drivers available. | +| DB_HOSTNAME | string | Database host | +| DB_USERNAME | string | Username to connect a database | +| DB_PASSWORD | string | Database password | +| DB_DATABASE | string | Database name | +| SQL_CACHE | boolean | Use the SQL Select cache system | +| ROUTES | array | Specify manually routes | +| DEFAULT_ROUTE | string | Define the default route to assume with initial page. Default is *common/home*. | +| CUSTOM_DB_CONFIG | string | Custom SQL to load application configs in database. | +| NOT_FOUND | string | Custom route to not found page. Default is error/not_found. | + +## Outputs and renders + +Phacil Framework count with three methods for output content: `$this->response->setOutput()`, `$this->render()` and `$this->out()`. + +### setOutput When you call a `$this->response->setOutput` inside a controller, you specify an output of content to screen without template. It's very useful for JSON, XML or others data contents. - ##### Sample +##### Sample ```php render` just render the controller with template but not output this. Needs to specify a `$this->template` to associate with template file. It's much used in children's controllers, like headers and footers. @@ -195,7 +198,7 @@ For functions inside the controller that are different from index, for automatic - ## Template Engines Support +## Template Engines Support This framework supports this PHP templates engines: - TPL (basic template with PHP and HTML); @@ -207,18 +210,18 @@ For functions inside the controller that are different from index, for automatic To use a determined template engine, just create a file with name of engine in extension, for sample, if you like to use a Twig, the template file is **demo.twig**, if desire the Mustache template, use **demo.mustache** extension file. The ExacTI Phacil Framework allows to use various template engines in the same project. - ## Easy made functions +## Easy made functions This framework is very focused in agile, security and reusable code in PHP. Contains a very utile functions we see in the next section. - ### Database +### Database To execute a query: ```php $variable = $this->db->query("SELECT * FROM mundo"); ``` - Without SQL Cache (if enabled): + Without SQL Cache (if config enabled): ```php $variable = $this->db->query("SELECT * FROM mundo", false); ``` @@ -232,7 +235,7 @@ To get these rows: Number of rows: `$variable->num_rows`; - Sample: +##### Sample: ```php cache->set($key, $value)` to set a cache and `$this->cache->get($key)` to obtain a cache value. + + +### Document easy made Use the especial Document class to manipulate easily informations about your final HTML. @@ -281,7 +305,7 @@ Document HTML Title: `$this->document->setTitle($title)`; Page description: `$this->document->setDescription($description)`; - Sample: +##### Sample: ```php request` method. For sample, to obtain a POST value, use `$this->request->post['field']` to get the post value with security. - For a \$_SERVER predefined variables, use `$this->request->server['VALUE']` and $this->request->get() for \$_GET values. + For a $_SERVER predefined variables, use `$this->request->server['VALUE']` and `$this->request->get[key]` for $_GET values. The advantages to use this requests instead the predefined variables of PHP are more the more security, upgradable and unicode values. - ### Sessions +### Sessions Sessions is a little different method, you can define and use with `$this->session->data['name']`. @@ -454,7 +478,7 @@ In a sample case, we have this controller: Private and protected functions is only for internal use, if we tried to access *index.php?route=folder/file/foo*, the framework return 404 HTTP error. - ### SEO URL +### SEO URL If you need a beautiful URL for SEO or other optimizations, you can use the url_alias database table. Is very simple and "translate" the routes in URL. @@ -472,14 +496,14 @@ In a sample case, we have this controller: Imagine this SQL table called url_alias: - | url_alias_id | query | get | keyword | - | ----- | ----- | ----- | ----- | - | 1 | contact/contato | | contact| - | 2 | webservice/sitemap | | sitemap | +| url_alias_id | query | get | keyword | +| ----- | ----- | ----- | ----- | +| 1 | contact/contato | | contact| +| 2 | webservice/sitemap | | sitemap | With the url_alias, the access to route *http://example.com/index.php?route=contact/contato* and *http://example.com/contact* is the same!(and very pretty!). - #### SEO URL without Database +#### SEO URL without Database You can create URL without a SQL Database configuration. For this you just need specify routes in the config file using the ***ROUTES*** constant with array content, like this: @@ -489,7 +513,7 @@ In a sample case, we have this controller: 'json' => 'common/home/json')); ``` - ### Links +### Links We have a function to create a strict and dynamic links automatic: `$this->url->link($route, $args = '', $connection = 'NONSSL')`. Is a simple function to generate internal links with correct URL encode. @@ -523,18 +547,18 @@ In a sample case, we have this controller: ***Note:*** *It's necessary specify the config `config_seo_url` for correctly function of this URLs. If you use the SQL url_alias table, you need specify the `USE_DB_CONFIG` to true in config file.* - ### Passing URI Segments to your Functions +### Passing URI Segments to your Functions - Use the *'%'* character and its variations (see below) to create a route with wildcard. All contents in the URL will matches with wildcard is passed to your controller function as argument. + Use the *'__%__'* character and its variations (see below) to create a route with wildcard. All contents in the URL will matches with wildcard is passed to your controller function as argument. - | Wildcard | Description | - | ----- | -----| - | %d | Matches any decimal digit equivalent to [0-9].| - | %w | Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_]. Spaces or others character is not allowed. | - | %a | Matches any character in the valid ASCII range. Latin characters like *'ç'* or *'ã'* is not accepted. | - | % | Accept any character.| +| Wildcard | Description | +| ----- | -----| +| %d | Matches any decimal digit equivalent to [0-9].| +| %w | Matches any letter, digit or underscore. Equivalent to [a-zA-Z0-9_]. Spaces or others character is not allowed. | +| %a | Matches any character in the valid ASCII range. Latin characters like *'ç'* or *'ã'* is not accepted. | +| % | Accept any character.| - ##### Sample: +##### Sample: ```php define("ROUTES", array( "produto/%d/%/promo" => "feriado/natal/presentes" @@ -551,11 +575,11 @@ In a sample case, we have this controller: } ``` - In this sample above, imagine the URL *http://yoursite.com/produto/**87**/**alfajor**/promo*, this URL is sending to function *presentes* values for `$id` and `$name` arguments in sequential method, in other words, the value of `$id` is set to `87` and `$name` to `alfajor`. The wildcard *%d* in router relative to `$id` argument define is only accepted number values. + In this sample above, imagine the URL _http://yoursite.com/produto/**87**/**alfajor**/promo_, this URL is sending to function *presentes* values for `$id` and `$name` arguments in sequential method, in other words, the value of `$id` is set to `87` and `$name` to `alfajor`. The wildcard *%d* in router relative to `$id` argument define is only accepted number values. In this moment, this resource is only available in constant ROUTES method. SQL routes not support wildcard at this moment. - ## JSON, XML and others custom responses +## JSON, XML and others custom responses If you need to output in another format or another response, you can use the Response method `$this->response`. @@ -613,7 +637,7 @@ In a sample case, we have this controller: ``` - ## Set and load configurations +## Set and load configurations The config library in Phacil Framework obtains values to use in entire web app of: `$config` array in *config.php* file, the settings table in your configured database or both. @@ -623,7 +647,7 @@ In a sample case, we have this controller: To storage a config value, use a SQL table called settings or an array. - #### Sample of storage in array method +#### Sample of storage in array method ```php $config = array( @@ -635,16 +659,16 @@ In a sample case, we have this controller: "USA" => '+1 (845) 579-0362') ); ``` - #### Sample of storage in SQL table +#### Sample of storage in SQL table - | setting_id | group | key | value | serialized | - | ----- | ----- | ----- | ----- | ----- | - | 1 | | title | ExacTI Phacil Framework | 0 | - | 2 | config | config_error_display | 1 | 0 | - | 3 | config | config_error_log | 0 | 0| - | 4 | | phones | a:2:{s:2:"BR";s:16:"+55 11 4115-5161";s:3:"USA";s:17:"+1 (845) 579-0362";} | 1 | +| setting_id | group | key | value | serialized | +| ----- | ----- | ----- | ----- | ----- | +| 1 | | title | ExacTI Phacil Framework | 0 | +| 2 | config | config_error_display | 1 | 0 | +| 3 | config | config_error_log | 0 | 0| +| 4 | | phones | a:2:{s:2:"BR";s:16:"+55 11 4115-5161";s:3:"USA";s:17:"+1 (845) 579-0362";} | 1 | - ### Reserved config keys +### Reserved config keys This config keys are reserved to use for framework. @@ -671,7 +695,7 @@ In a sample case, we have this controller: PRIMARY KEY (`setting_id`) ) AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; ``` - #### MS SQL Server sample +#### MS SQL Server sample ```SQL CREATE TABLE settings ( [setting_id] int NOT NULL IDENTITY PRIMARY KEY, @@ -683,12 +707,12 @@ In a sample case, we have this controller: ); ``` - ## Registrations +## Registrations If you need to register a class or other resource to use in your entire application, you can create using the file *registrations.php* in the **system** folder. Use to specify a `$registry->set('name', $function);` with the function, class or method if you need. After this, just use `$this->name` to access this registry inside a controller or model. - #### Sample to register a simple class +#### Sample to register a simple class Declare in /system/registrations.php ```php + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath.'\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/system/caches/Phpfastcache/composer/LICENSE b/system/caches/Phpfastcache/composer/LICENSE new file mode 100644 index 0000000..f27399a --- /dev/null +++ b/system/caches/Phpfastcache/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/system/caches/Phpfastcache/composer/autoload_classmap.php b/system/caches/Phpfastcache/composer/autoload_classmap.php new file mode 100644 index 0000000..7a91153 --- /dev/null +++ b/system/caches/Phpfastcache/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($vendorDir . '/psr/simple-cache/src'), + 'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'), + 'Phpfastcache\\' => array($vendorDir . '/phpfastcache/phpfastcache/lib/Phpfastcache'), +); diff --git a/system/caches/Phpfastcache/composer/autoload_real.php b/system/caches/Phpfastcache/composer/autoload_real.php new file mode 100644 index 0000000..c1e827f --- /dev/null +++ b/system/caches/Phpfastcache/composer/autoload_real.php @@ -0,0 +1,52 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInitc3ab4c61f64ed5b4625d22b9465a323a::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/system/caches/Phpfastcache/composer/autoload_static.php b/system/caches/Phpfastcache/composer/autoload_static.php new file mode 100644 index 0000000..4f1c55e --- /dev/null +++ b/system/caches/Phpfastcache/composer/autoload_static.php @@ -0,0 +1,41 @@ + + array ( + 'Psr\\SimpleCache\\' => 16, + 'Psr\\Cache\\' => 10, + 'Phpfastcache\\' => 13, + ), + ); + + public static $prefixDirsPsr4 = array ( + 'Psr\\SimpleCache\\' => + array ( + 0 => __DIR__ . '/..' . '/psr/simple-cache/src', + ), + 'Psr\\Cache\\' => + array ( + 0 => __DIR__ . '/..' . '/psr/cache/src', + ), + 'Phpfastcache\\' => + array ( + 0 => __DIR__ . '/..' . '/phpfastcache/phpfastcache/lib/Phpfastcache', + ), + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->prefixLengthsPsr4 = ComposerStaticInitc3ab4c61f64ed5b4625d22b9465a323a::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitc3ab4c61f64ed5b4625d22b9465a323a::$prefixDirsPsr4; + + }, null, ClassLoader::class); + } +} diff --git a/system/caches/Phpfastcache/composer/installed.json b/system/caches/Phpfastcache/composer/installed.json new file mode 100644 index 0000000..2c2fb8e --- /dev/null +++ b/system/caches/Phpfastcache/composer/installed.json @@ -0,0 +1,202 @@ +[ + { + "name": "phpfastcache/phpfastcache", + "version": "7.0.5", + "version_normalized": "7.0.5.0", + "source": { + "type": "git", + "url": "https://github.com/PHPSocialNetwork/phpfastcache.git", + "reference": "64638b27f473aa26603e84288d91a2b80a4aa388" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPSocialNetwork/phpfastcache/zipball/64638b27f473aa26603e84288d91a2b80a4aa388", + "reference": "64638b27f473aa26603e84288d91a2b80a4aa388", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=7.0", + "psr/cache": "~1.0.0", + "psr/simple-cache": "~1.0.0" + }, + "conflict": { + "basho/riak": "*", + "doctrine/couchdb": "*" + }, + "suggest": { + "ext-apc": "*", + "ext-couchbase": "*", + "ext-intl": "*", + "ext-leveldb": "*", + "ext-memcache": "*", + "ext-memcached": "*", + "ext-redis": "*", + "ext-sqlite": "*", + "ext-wincache": "*", + "ext-xcache": "*", + "mongodb/mongodb": "^1.1", + "phpfastcache/couchdb": "~1.0.0", + "phpfastcache/phpssdb": "~1.0.0", + "phpfastcache/riak-client": "~1.4.4", + "predis/predis": "~1.1.0" + }, + "time": "2019-03-03T14:39:16+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-4": { + "Phpfastcache\\": "lib/Phpfastcache/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Georges.L", + "email": "contact@geolim4.com", + "homepage": "https://github.com/Geolim4", + "role": "Actual Project Manager/Developer" + }, + { + "name": "Khoa Bui", + "email": "khoaofgod@gmail.com", + "homepage": "https://www.phpfastcache.com", + "role": "Former Project Developer/Original Creator" + } + ], + "description": "PHP Abstract Cache Class - Reduce your database call using cache system. PhpFastCache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.", + "homepage": "https://www.phpfastcache.com", + "keywords": [ + "LevelDb", + "abstract", + "apc", + "apcu", + "cache", + "cache class", + "caching", + "cassandra", + "cookie", + "couchbase", + "couchdb", + "files cache", + "memcache", + "memcached", + "mongodb", + "mysql cache", + "pdo cache", + "php cache", + "predis", + "redis", + "ssdb", + "wincache", + "xcache", + "zend", + "zend data cache", + "zend disk cache", + "zend memory cache", + "zend server" + ] + }, + { + "name": "psr/cache", + "version": "1.0.1", + "version_normalized": "1.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2016-08-06T20:24:11+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ] + }, + { + "name": "psr/simple-cache", + "version": "1.0.1", + "version_normalized": "1.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/simple-cache.git", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/simple-cache/zipball/408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "reference": "408d5eafb83c57f6365a3ca330ff23aa4a5fa39b", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "time": "2017-10-23T01:57:42+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for simple caching", + "keywords": [ + "cache", + "caching", + "psr", + "psr-16", + "simple-cache" + ] + } +] diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG.md b/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG.md new file mode 100644 index 0000000..a4a7bd3 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG.md @@ -0,0 +1,276 @@ +## 7.0.5 +#### _"Rusted"_ +##### 3 march 2019 +- __Drivers__ + - Fixed #675 // Memcached ignores custom host/port configurations (@Geolim4) +- __Global__ + - Fix composer package name should be all lowercase (@jfcherng) +- __Misc__ + - Updated Mongodb\Config docs (@mikepsinn) + - Fixed "Files" example in docs (@hriziya) + +## 7.0.4 +#### _"Rust-in"_ +##### 22 december 2018 +- __Core__ + - Moved exclusive files-related configurations keys to IOConfigurationTrait (@Geolim4) + - Added CacheManager::clearInstance() method (@Geolim4) +- __Drivers__ + - Adds drivers options parameter when building Mongo DB client (@vainj) +- __Misc__ + - Fixes PHPdoc issues (@vainj) + +## 7.0.3 +#### _"Rust is part of beauty after all !"_ +##### 5 september 2018 +- __Core__ + - Fixed wrong copyright annotation in some file headers (@Geolim4) + - Added `PhpfastcacheDriverConnectException` exception in case that a driver failed to connect (@Geolim4) +- __Drivers__ + - Added missing option "timeout" for `Predis` oO (@Geolim4) + - Settings up default `Couchbase` port to 8091 (@Geolim4) + - Fixed #647 // Unwanted echo in exception (@Geolim4) +- __Misc__ + - Fixed #637 // Corrupted badges on Github readme pages + +## 7.0.2 +#### _"Rust is getting some gold !"_ +##### 23 july 2018 +- __Core__ + - Added more Opcache/Type hint optimizations (@Geolim4) +- __Drivers__ + - Implemented #627 // Redis/Predis "prefix" option (@Geolim4) + - Fixed bug in Apcu driver with abstract getStats() method (@afdaniele) + - Added Mongodb cluster support and uri options (@UnRyongPark) +- __Misc__ + - Updated readme as we are sure that Apc(u) is ported to php7 (@Geolim4) + - Described clear() abstract method (@Geolim4) + - Added new option to PULL_REQUEST_TEMPLATE.md (@Geolim4) + - Fixed #620 // migration guide for v7 uses CamelCase in example (@Geolim4) + +## 7.0.1 +#### _"Gold is getting some rust !"_ +##### 22 june 2018 +- __Global__ + - Updated php constraint to be more reliable over the years (@Geolim4) +- __Core__ + - Fixed possible notice in some contexts (@Geolim4) +- __Drivers__ + - IOException in `Files` driver: Preventive hotfix for #614, thanks to @hriziya (@Geolim4) +- __Misc__ + - Fixed typo in README & code sample mistakes (@Geolim4) + - Updated examples as per #612 (@Geolim4) + - Fixed wrong code in template issues (@Geolim4) + - Updated Github bytes (@Geolim4) + - Fixing broken badges (@Geolim4) + +## 7.0.0 +#### _"We found gold !"_ +##### 27 may 2018 +- __Global__ + - Finally achieved 8 months of development \o/ (@Geolim4) + - Applied one last code refactoring to enforce PSR2 compliance (@Geolim4) + - Fixed some mismatching annotations type hints (@Geolim4) + - Applied many Scrutinizer code style/optimisation/typo recommendations (@Geolim4) +- __Core__ + - Updated some left functions/constants namespaces that were still not absolute (@Geolim4) + - Autoload: Isolated _PFC\_*_ constant in their own namespace to not pollute php's root namespace (@Geolim4) + - Added new exception interface `Phpfastcache\Exceptions\PhpfastcacheExceptionInterface` that will handle all Phpfastcache-related exceptions (@Geolim4) + - Updated CacheManager code by splitting some portions of code into different methods (@Geolim4) +- __Drivers__ + - Upgraded Couchbase to PHP SDK 2.4 as per #599 (@git-webmaster, @Geolim4) + - Added Couchbase SDK update notice to migration guide (@Geolim4) +- __Tests__ + - Updated TestHelper to better works in Web context (if any) (@Geolim4) + - Force exit code 0 when getting an uncaught exception PhpfastcacheDriverCheckException (@Geolim4) + - Fix test helper handling PhpfastcacheDriverCheckException with HHVM (@Geolim4) +- __Misc__ + - Added Anton (@git-webmaster) to our "hall of fame" (@Geolim4) + - Added "ext-couchbase" suggestion + - Updated every annotations/comments/documentation links from HTTP to HTTPS (if available) (@Geolim4) + +## 7.0.0-rc4 +##### 15 may 2018 +- __Core__ + - Added "defaultFileNameHashFunction" option (@Geolim4) +- __Drivers__ + - Implemented #598 // Ability to use custom predis/redis client (@Geolim4, @dol) +- __Tests__ + - Added test for custom predis client (@Geolim4) + - Added test for custom redis client (@Geolim4) +- __Misc__ + - Added doc for redis and predis client options (@Geolim4) + +## 7.0.0-rc3 +##### 9 may 2018 +- __Core__ + - Added method "getConfigClass" ExtendedCacheItemPoolInterface (@Geolim4) + - Upgraded API version from 2.0.3 to 2.0.4 (@Geolim4) + - Added "FQCNAsKey" parameter to CacheManager::getDriverList() (@Geolim4) + - Fixed fallback behavior in getPhpFastCacheVersion method (@Geolim4) + +## 7.0.0-rc2 +##### 8 may 2018 +- __Global__ + - More Opcache optimizations (@Geolim4) +- __Core__ + - Updated EventManager now MUST implement `Phpfastcache\Event\EventInterface` (@Geolim4) + - Upgraded API version from 2.0.2 to 2.0.3 (@Geolim4) + - Fixed namespace issue on EventManager (@Cyperghost) +- __Helpers__ + - Improved TestHelper efficiency (@Geolim4) + - Forced return type hint to Psr16Adapter && added a getter for the internal cache instance (@Geolim4) + - The Psr16Adapter will now also accept an `ExtendedCacheItemPoolInterface` object to the $driver parameter in constructor (@Geolim4) +- __Misc__ + - Updated Readme (@Geolim4) + +## 7.0.0-rc +##### 8 april 2018 +- __Global__ + - **Added "custom driver" and "override core driver" features** (@Geolim4) + - **Updated & completely reworked Mongodb driver** (@ylorant) + - Deprecated custom namespace feature in favor of the new feature above (@Geolim4) + - Deprecated `$this->getConfigOption($optionName)` for `$this->geConfig()->getOptionName()` (@Geolim4) + - Deprecated `$this->getConfig()->getOption($optionName)` for `$this->geConfig()->getOptionName()` (@Geolim4) +- __Core__ + - Enforced more argument type hint & absolute core php function namespaces (@Geolim4) + - Removed `ExtendedCacheItemInterface::getUncommittedData()` that should have been removed before :| (@Geolim4) + - Added additional atomic methods in ExtendedCacheItemInterface (`isNull()`, `isEmpty()`, `getLength()`) (@Geolim4) +- __Drivers__ + - Improved "Auto" driver context with tests, new interface method and additional checks (@Geolim4) +- __Helpers__ + - Added "NOTE" method to testHelper (@Geolim4) +- __Utils__ + - Removed unused Util "Languages" (@Geolim4) +- __Tests__ + - Fixed randomly failing test "Github-560" (@Geolim4) + - Fixed include issue in tests (@Geolim4) + - Updated tests for custom drivers (@Geolim4) +- __Misc__ + - Added specific IoConfiguration for files-based drivers (@Geolim4) + - Updated README to re-arrange the API section more properly (@Geolim4) + - Fixed HTTP images that broke site SSL seal in README (@Geolim4) + - Updated composer description & dependencies constraints (@Geolim4) + +## 7.0.0-beta3 +##### 17 march 2018 +- __Global__ + - **Updated root namespace: "phpFastCache\" => "Phpfastcache\"** (@Geolim4) + - **Updated root directory: "src" => "lib"** (@Geolim4) + - Dismissed unneeded/inconsistent "else" statements (@Geolim4) +- __Core__ + - **Capitalized Phpfastcache classe names** (@Geolim4) Please read carefully the migration guide (MigratingFromV6ToV7.md). + - Added CacheManager::getDriverList() (@Geolim4) + - Updated strictly return type hints in CacheManager (@Geolim4) + - Deprecated CacheManager::getStaticAllDrivers() (@Geolim4) + - Deprecated CacheManager::getStaticSystemDrivers() (@Geolim4) + - Deprecated configuration option "ignoreSymfonyNotice" (@Geolim4) + - Added PhpfastcacheUnsupportedOperationException exception (@Geolim4) +- __Drivers__ + - Fixed #576 // Devnull driver returning non-dull data (@Geolim4) + - Fixed #581 // Files driver "securityKey" option configuration not working as documented +- __Configuration__ + - Added configuration option `fallbackConfig` for a better fallback configuration (@Geolim4) + - Deprecated configuration option "ignoreSymfonyNotice" (@Geolim4) +- __Helpers__ + - Added exception catcher to test Helper to FAIL or SKIP depending the exception (@Geolim4) + - Added notice/warning/error catcher to test Helper to keep a clean build report (@Geolim4) +- __Utils__ + - Added exception catcher to to test Helper to FAIL or SKIP depending the exception (@Geolim4) + - Updated strictly return type hints in Directory class (@Geolim4) +- __Tests__ + - Added duration time for each tests (@Geolim4) + - Updated Lexer Test for better compatibility with HHVM (@Geolim4) + - Fixed #581 // Issue with test file namespace imports (@Geolim4) + - Updated Travis build to include 7.2 (@Geolim4) + - Updated scrutinizer build settings (@Geolim4) +- __Misc__ + - Added deprecation section in migrating guide + - Moved API changelog to a standalone file + - Professionalized a bit more the README + - Removed lib/Phpfastcache/.htaccess that does no longer belong in its place + - Added .gitattributes file + +## 7.0.0-beta2 +##### 4 march 2018 +- __Core__ + - **Added new ConfigurationOption object syntax** (@Geolim4). Please read carefully the migration guide (MigratingFromV6ToV7.md). +- __Drivers__ + - Fixed #576 // Devnull driver returning non-dull data (@Geolim4) +- __Helpers__ + - Added exception catcher to to test Helper to FAIL or SKIP depending the exception (@Geolim4) +- __Tests__ + - Fixed nightly build that sometimes fails with Memcache + +## 7.0.0-beta +##### 30 january 2018 +- __Global__ + - Added Opcache improvements by namespacing php core's functions (@Geolim4) + - Updated contributing.md + added coding guideline (@Geolim4) + - Fixed little notice (@Geolim4) +- __Drivers__ + - Added UNIX socket support for (P)Redis and Memcache(d) as requested in #563 (@Geolim4) +- __Helpers__ + - Updated test helper and API to add the git version (if available) (@Geolim4) +- __Tests__ + - Fixed #560 // Potential delay issue in test (@Geolim4) + +## 7.0.0-alpha3 +##### 15 december 2017 +- __Global__ + - Fixed #541 // Random "key does not exist on the server" messages (@Geolim4) +- __Core__ + - Fixed #554 // Log actual mkdir() failure reason (@Geolim4) +- __Drivers__ + - Fixed #549 // Mongodb driver + itemDetailedDate option generates driverUnwrapCdate error (Using V7 getOption API) (@Geolim4) + - Fixed #548 // Wrong type hint on redis driver (@Geolim4) +- __Helpers__ + - Fixed #545 // Psr16Adapter get item even if it is expired (@Geolim4) + - Added CacheConditionalHelper TTL (@Geolim4) +- __Tests__ + - Fixed some missing text output on HHVM builds (@Geolim4) + - Fixed HHVM builds (@Geolim4) + +## 7.0.0-alpha2 +##### 10 november 2017 +- __Global__ + - Fixed some typo on CREDITS.md (@geolim4) + - Added Strict types support (@geolim4) + - Added grouped namespaces (@geolim4) + - Added VersionEye mention to credits (@geolim4) + - Added OPTIONS.md (@geolim4) + - Removed VersionEye badge :sob: (@geolim4) + - Improved our fabulous API class to add the changelog/PhpFastCache version support (@geolim4) + - Updated readme to add php7 strict types mention (@geolim4) + - Updated EVENTS.md @geolim4) + - Update withoutComposer.php (@Abs) + - Updated CREDITS.txt to markdown file (@geolim4) +- __Core__ + - Fixed #529 // Memory leak caused by item tags (@geolim4) + - Fixed missing sprintf in CacheManager + Added Riak method annotation (@geolim4) + - Updated API version (@geolim4) + - Updated composer files (@geolim4) +- __Drivers__ + - Fixed #517 // Couchbase error (@geolim4) + - Fixed Riak dependency (@geolim4) +- __Tests__ + - Fixed hhvm build with subprocesses (@geolim4) + - Added test for option "itemDetailedDate" (@geolim4) + +## 7.0.0-alpha +##### 18 october 2017 +- __Global__ + - Added php7 type hint support. Strict type support is coming in next alphas + - Added changelog as requested by @rdecourtney in #517 + - Added `phpFastCacheInstanceNotFoundException` exception +- __Drivers__ + - Added Riak driver + - Fixed wrong type hint returned by Predis +- __Cache Manager__ + - Added custom Instance ID feature as requested in #477 +- __Helpers__ + - Modified ActOnAll helper behavior, this helper now returns an array of driver returns and does no longer implements `ExtendedCacheItemPoolInterface` + +## 7.0.0-dev +##### 01 october 2017 +- Initialized v7 development \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG_API.md b/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG_API.md new file mode 100644 index 0000000..88266ec --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/CHANGELOG_API.md @@ -0,0 +1,86 @@ +## 2.0.4 +- Added ExtendedCacheItemPoolInterface::getConfigClass() that returns the config class name + +## 2.0.3 +- Updated ExtendedCacheItemPoolInterface::setEventManager() first argument that now MUSt implement `\Phpfastcache\Event\EventInterface` +- Updated ExtendedCacheItemInterface::setEventManager() first argument that now MUSt implement `\Phpfastcache\Event\EventInterface` + +## 2.0.2 +- Added ExtendedCacheItemPoolInterface::isUsableInAutoContext() to check if the driver is allowed to be used in 'Auto' context. + +## 2.0.1 +- Implemented additional atomic methods: +- Added ExtendedCacheItemInterface::isNull() to test if the data is null or not despite the hit/miss status. +- Added ExtendedCacheItemInterface::isEmpty() to test if the data is empty or not despite the hit/miss status. +- Added ExtendedCacheItemInterface::getLength() get the data length if the data is a string, array, or objects that implement \Countable interface. + +## 2.0.0 +- Introduced BC breaks: +- Updated ExtendedCacheItemPoolInterface to be compliant with the new \$config object introduced in V7. +- ExtendedCacheItemPoolInterface::getConfig() no longer returns an array but a ConfigurationOption object +- ExtendedCacheItemPoolInterface::getDefaultConfig() no longer returns an array but a ConfigurationOption object +- Removed ExtendedCacheItemInterface::getUncommittedData() that is no longer used in the V7 + +## 1.3.0 +- Implemented full PHP7 type hint support for ExtendedCacheItemPoolInterface and ExtendedCacheItemInterface +- Added instance ID getter (introduced in V7): + - ExtendedCacheItemPoolInterface::getInstanceId() +- The method ExtendedCacheItemPoolInterface::getDefaultConfig() will now returns a \phpFastCache\Util\ArrayObject + +## 1.2.5 +- Implemented additional simple helper method to direct access to a config option: + - ExtendedCacheItemPoolInterface::getConfigOption() + +## 1.2.4 +- Implemented additional simple helper method to provide basic information about the driver: + - ExtendedCacheItemPoolInterface::getHelp() + +## 1.2.3 +- Implemented additional saving method form multiple items: + ExtendedCacheItemPoolInterface::saveMultiple() + +## 1.2.2 +- Implemented additional tags methods such as: + - ExtendedCacheItemPoolInterface::getItemsByTagsAll() + - ExtendedCacheItemPoolInterface::incrementItemsByTagsAll() + - ExtendedCacheItemPoolInterface::decrementItemsByTagsAll() + - ExtendedCacheItemPoolInterface::deleteItemsByTagsAll() + - ExtendedCacheItemPoolInterface::appendItemsByTagsAll() + - ExtendedCacheItemPoolInterface::prependItemsByTagsAll() + +## 1.2.1 +- Implemented Event manager methods such as: + - ExtendedCacheItemInterface::setEventManager() + - ExtendedCacheItemPoolInterface::setEventManager() + +## 1.2.0 +- Implemented Item advanced time methods such as: + - ExtendedCacheItemInterface::setExpirationDate() (Alias of CacheItemInterface::ExpireAt() for more code logic) + - ExtendedCacheItemInterface::getCreationDate() * + - ExtendedCacheItemInterface::getModificationDate() * + - ExtendedCacheItemInterface::setCreationDate(\DateTimeInterface) * + - ExtendedCacheItemInterface::setModificationDate() * + - \* Require configuration directive "itemDetailedDate" to be enabled + +## 1.1.3 +- Added an additional CacheItemInterface method: + - ExtendedCacheItemInterface::getEncodedKey() + +## 1.1.2 +- Implemented [de|a]ttaching methods to improve memory management + - ExtendedCacheItemPoolInterface::detachItem() + - ExtendedCacheItemPoolInterface::detachAllItems() + - ExtendedCacheItemPoolInterface::attachItem() + - ExtendedCacheItemPoolInterface::isAttached() + +## 1.1.1 +- Implemented JsonSerializable interface to ExtendedCacheItemInterface + +## 1.1.0 +- Implemented JSON methods such as: + - ExtendedCacheItemPoolInterface::getItemsAsJsonString() + - ExtendedCacheItemPoolInterface::getItemsByTagsAsJsonString() + - ExtendedCacheItemInterface::getDataAsJsonString() + +## 1.0.0 +- First initial version \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/LICENCE b/system/caches/Phpfastcache/phpfastcache/phpfastcache/LICENCE new file mode 100644 index 0000000..59c1b7e --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/LICENCE @@ -0,0 +1,20 @@ +Copyright (c) 2016 phpFastCache + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +Software), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/README.md b/system/caches/Phpfastcache/phpfastcache/phpfastcache/README.md new file mode 100644 index 0000000..98cb672 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/README.md @@ -0,0 +1,333 @@ +[![Total Downloads](https://img.shields.io/packagist/dt/phpfastcache/phpfastcache.svg?maxAge=86400)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Latest Stable Version](https://img.shields.io/packagist/v/phpfastcache/phpfastcache.svg?maxAge=86400)](https://packagist.org/packages/phpfastcache/phpfastcache) [![License](https://img.shields.io/packagist/l/phpfastcache/phpfastcache.svg?maxAge=86400)](https://packagist.org/packages/phpfastcache/phpfastcache) [![Coding Standards](https://img.shields.io/badge/CI-PSR6-orange.svg?maxAge=86400)](https://github.com/php-fig/cache) [![Coding Standards](https://img.shields.io/badge/CS-PSR16-orange.svg?maxAge=86400)](https://github.com/php-fig/simple-cache) +[![Code Climate](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache/badges/gpa.svg)](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache/?branch=master) [![Build Status](https://travis-ci.org/PHPSocialNetwork/phpfastcache.svg?branch=master)](https://travis-ci.org/PHPSocialNetwork/phpfastcache) [![Semver compliant](https://img.shields.io/badge/Semver-2.0.0-yellow.svg?maxAge=86400)](https://semver.org/spec/v2.0.0.html) [![Patreon](https://img.shields.io/badge/Support%20us%20on-Patreon-f96854.svg?maxAge=86400)](https://www.patreon.com/geolim4) + +#### :warning: Please note that the V7 is a major (BC breaking) update of PhpFastCache ! +> As the V7 is **absolutely** not compatible with previous versions, please read carefully the [migration guide](./docs/migration/MigratingFromV6ToV7.md) to ensure you the smoothest migration possible. +One of the biggest change is the configuration system which is now an object that replace the primitive array that we used to implement back then. +Also please note that the V7 requires at least PHP7 or higher to work properly. + +--------------------------- +Simple Yet Powerful PHP Caching Class +--------------------------- +More information in [Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki) +The simplicity of abstraction: One class for many backend cache. You don't need to rewrite your code many times again. + +### PHP7 Strict types enforced +As of the V7 PhpFastCache enforces the php7 strict types to make sure that it's completely php7 compatible and is type aware. +This ensure you that the library is completely reliable when it come to manipulate variable types. + +### Supported drivers at this day * +:bulb: Feel free to propose a driver by making a new **[Pull Request](https://github.com/PHPSocialNetwork/phpfastcache/compare)**, they are welcome ! + +| Regular drivers | High performances drivers | Development drivers | +|---------------------------------|------------------------------------|-------------------------------| +| `Apc(u)` | `Cassandra` | `Devnull` | +| `Cookie` | `CouchBase` | `Devfalse` | +| `Files` | `Couchdb` | `Devtrue` | +| `Leveldb` :question: | `Mongodb` | `Memstatic` | +| `Memcache(d)` | `Predis` | | +| `Sqlite` | `Redis` | | +| `Wincache` :question: | `Riak` | | +| `Xcache` :question: | `Ssdb` | | +| `Zend Disk Cache` | `Zend Memory Cache` | | + +\* Driver descriptions available in DOCS/DRIVERS.md + +:question: Please note that as of PHP7 some php extensions were not yet updated (and will may not), we keep the code here but there's no guarantee that they are still working especially due to the cores changes introduced by Opcache. + +### Symfony/Drupal developers are not forgotten ! +Starting with v5, phpFastCache comes with a [Symfony Bundle](https://github.com/PHPSocialNetwork/phpfastcache-bundle). +It is now a mature project Flex -ready, so feel free to give at try and report any bug (if any). + +Also a [Drupal 8 Module](https://github.com/PHPSocialNetwork/phpfastcache-drupal) is currently in development, add it to your starred projects to get notified of the first public release. + +--------------------------- +Not a "Traditional" Caching +--------------------------- +phpFastCache is not like the traditional caching methods which keep reading and writing to +files, sqlite or keeping open massive amounts of connections to memcache, redis, mongodb...\ +Also, when you use high performances drivers, your miss hits will be drastically reduced.\ +Slightly different from the usual caching libraries you will find everywhere on the internet, +the phpFastCache library reduces the I/O and CPU load as much as possible. + +```php +has('test-key')){ + // Setter action + $data = 'lorem ipsum'; + $Psr16Adapter->set('test-key', 'lorem ipsum', 300);// 5 minutes +}else{ + // Getter action + $data = $Psr16Adapter->get('test-key'); +} + + +/** +* Do your stuff with $data +*/ +``` + +Internally, the Psr16 adapter calls the PhpFastCache Api via the cache manager. + +--------------------------- +Introducing to events +--------------------------- + +:mega: As of the V6, PhpFastCache provides an event mechanism. +You can subscribe to an event by passing a Closure to an active event: + +```php +onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){ + $item->set('[HACKED BY EVENT] ' . $item->get()); +}); + +``` + +An event callback can get unbind but you MUST provide a name to the callback previously: + +```php +onCacheGetItem(function(ExtendedCacheItemPoolInterface $itemPool, ExtendedCacheItemInterface $item){ + $item->set('[HACKED BY EVENT] ' . $item->get()); +}, 'myCallbackName'); + + +/** +* Unbind the event callback +*/ +EventManager::getInstance()->unbindEventCallback('onCacheGetItem', 'myCallbackName'); + +``` + +More information about the implementation and the events are available on the [Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Introducing-to-events) + +--------------------------- +Introducing new helpers +--------------------------- +:books: As of the V6, PhpFastCache provides some helpers to make your code easier. + +- The [ActOnAll Helper](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Act-on-all-instances) to help you to act on multiple instance at once. +- The [CacheConditional Helper](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Cache-Conditional) to help you to make the basic conditional statement more easier. +- The [Psr16 adapter](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%CB%96%5D-Psr16-adapter) to keep it simple as explained above. + +May more will come in the future, feel free to contribute ! + +--------------------------- +As Fast To Implement As Opening a Beer +--------------------------- + + +#### :thumbsup: Step 1: Include phpFastCache in your project with composer: + + +```bash +composer require phpfastcache/phpfastcache +``` + +#### :construction: Step 2: Setup your website code to implement the phpFastCache calls (with Composer) +```php + '/var/www/phpfastcache.com/dev/tmp', // or in windows "C:/tmp/" +])); + +// In your class, function, you can call the Cache +$InstanceCache = CacheManager::getInstance('files'); + +/** + * Try to get $products from Caching First + * product_page is "identity keyword"; + */ +$key = "product_page"; +$CachedString = $InstanceCache->getItem($key); + +$your_product_data = [ + 'First product', + 'Second product', + 'Third product' + /* ... */ +]; + +if (!$CachedString->isHit()) { + $CachedString->set($your_product_data)->expiresAfter(5);//in seconds, also accepts Datetime + $InstanceCache->save($CachedString); // Save the cache item just like you do with doctrine and entities + + echo 'FIRST LOAD // WROTE OBJECT TO CACHE // RELOAD THE PAGE AND SEE // '; + echo $CachedString->get(); + +} else { + echo 'READ FROM CACHE // '; + echo $CachedString->get()[0];// Will print 'First product' +} + +/** + * use your products here or return them; + */ +echo implode('
', $CachedString->get());// Will echo your product list + +``` + +##### :floppy_disk: Legacy support (Without Composer) +* See the file examples/withoutComposer.php for more information. + +#### :zap: Step 3: Enjoy ! Your website is now faster than lightning ! +For curious developers, there is a lot of other examples available [here](./docs/examples). + +#### :boom: phpFastCache support +Found an issue or have an idea ? Come **[here](https://github.com/PHPSocialNetwork/phpfastcache/issues)** and let us know ! diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Api.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Api.php new file mode 100644 index 0000000..276c9de --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Api.php @@ -0,0 +1,162 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache; + +use Phpfastcache\Exceptions\PhpfastcacheIOException; +use Phpfastcache\Exceptions\PhpfastcacheLogicException; + +/** + * Class Api + * @package phpFastCache + */ +class Api +{ + protected static $version = '2.0.4'; + + /** + * Api constructor. + */ + final private function __construct() + { + } + + /** + * This method will returns the current + * API version, the API version will be + * updated by following the semantic versioning + * based on changes of: + * - ExtendedCacheItemPoolInterface + * - ExtendedCacheItemInterface + * + * @see https://semver.org/ + * @return string + */ + public static function getVersion(): string + { + return self::$version; + } + + /** + * @param bool $fallbackOnChangelog + * @param bool $cacheable + * @return string + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException + */ + public static function getPhpFastCacheVersion($fallbackOnChangelog = true, $cacheable = true): string + { + /** + * Cache the version statically to improve + * performances on multiple calls + */ + static $version; + + if ($version && $cacheable) { + return $version; + } + + if (\function_exists('shell_exec')) { + $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags'; + $stdout = shell_exec($command); + if (\is_string($stdout)) { + $version = \trim($stdout); + return $version; + } + if (!$fallbackOnChangelog) { + throw new PhpfastcacheLogicException('The git command used to retrieve the PhpFastCache version has failed.'); + } + } + + if (!$fallbackOnChangelog) { + throw new PhpfastcacheLogicException('shell_exec is disabled therefore the PhpFastCache version cannot be retrieved.'); + } + + $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; + if (\file_exists($changelogFilename)) { + $versionPrefix = '## '; + $changelog = \explode("\n", self::getPhpFastCacheChangelog()); + foreach ($changelog as $line) { + if (\strpos($line, $versionPrefix) === 0) { + $version = \trim(\str_replace($versionPrefix, '', $line)); + return $version; + } + } + throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache version through the CHANGELOG.md as no valid string were found in it.'); + } + throw new PhpfastcacheLogicException('shell_exec being disabled we attempted to retrieve the PhpFastCache version through the CHANGELOG.md file but it is not readable or has been removed.'); + } + + /** + * @param bool $cacheable + * @return string + */ + public static function getPhpFastCacheGitHeadHash($cacheable = true): string + { + static $hash; + + if ($hash && $cacheable) { + return $hash; + } + + if (\function_exists('shell_exec')) { + $stdout = \shell_exec('git rev-parse --short HEAD'); + if (\is_string($stdout)) { + $hash = \trim($stdout); + return "#{$hash}"; + } + } + return ''; + } + + + /** + * Return the API changelog, as a string. + * @return string + * @throws PhpfastcacheLogicException + * @throws PhpfastcacheIOException + */ + public static function getChangelog(): string + { + $changelogFilename = __DIR__ . '/../../CHANGELOG_API.md'; + if (\file_exists($changelogFilename)) { + $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); + if ($string) { + return $string; + } + throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache API changelog as it seems to be empty.'); + } + throw new PhpfastcacheIOException('The CHANGELOG_API.md file is not readable or has been removed.'); + } + + /** + * Return the PhpFastCache changelog, as a string. + * @return string + * @throws PhpfastcacheLogicException + * @throws PhpfastcacheIOException + */ + public static function getPhpFastCacheChangelog(): string + { + $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; + if (\file_exists($changelogFilename)) { + $string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename))); + if ($string) { + return $string; + } + throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache changelog as it seems to be empty.'); + } + throw new PhpfastcacheIOException('The CHANGELOG.md file is not readable or has been removed.'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Autoload/Autoload.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Autoload/Autoload.php new file mode 100644 index 0000000..bc0eca9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Autoload/Autoload.php @@ -0,0 +1,71 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +const PFC_PHP_EXT = 'php'; +const PFC_BIN_DIR = __DIR__ . '/../../../bin/'; +const PFC_LIB_DIR = __DIR__ . '/../../../lib/'; + +/** + * Register Autoload + */ +\spl_autoload_register(function ($entity) { + $module = \explode('\\', $entity, 2); + if (!\in_array($module[0], ['Phpfastcache', 'Psr'])) { + /** + * Not a part of phpFastCache file + * then we return here. + */ + return; + } + + if (\strpos($entity, 'Psr\Cache') === 0) { + $path = PFC_BIN_DIR . 'dependencies/Psr/Cache/src/' . \substr(\strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT; + + if (\is_readable($path)) { + require_once $path; + } else { + \trigger_error('Cannot locate the Psr/Cache files', \E_USER_ERROR); + } + return; + } + + if (\strpos($entity, 'Psr\SimpleCache') === 0) { + $path = PFC_BIN_DIR . 'dependencies/Psr/SimpleCache/src/' . \substr(\strrchr($entity, '\\'), 1) . '.' . PFC_PHP_EXT; + + if (\is_readable($path)) { + require_once $path; + } else { + \trigger_error('Cannot locate the Psr/SimpleCache files', \E_USER_ERROR); + } + return; + } + + $entity = \str_replace('\\', '/', $entity); + $path = PFC_LIB_DIR . $entity . '.' . PFC_PHP_EXT; + + if (\is_readable($path)) { + require_once $path; + } +}); + +if ((!\defined('PFC_IGNORE_COMPOSER_WARNING') || !PFC_IGNORE_COMPOSER_WARNING) && \class_exists(\Composer\Autoload\ClassLoader::class)) { + \trigger_error( + 'Your project already makes use of Composer. You SHOULD use the composer dependency "phpfastcache/phpfastcache" instead of hard-autoloading.', + \E_USER_WARNING + ); +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php new file mode 100644 index 0000000..056c604 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/CacheManager.php @@ -0,0 +1,614 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache; + +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverCheckException, PhpfastcacheDriverException, PhpfastcacheDriverNotFoundException, PhpfastcacheExceptionInterface, PhpfastcacheInstanceNotFoundException, PhpfastcacheInvalidArgumentException, PhpfastcacheInvalidConfigurationException, PhpfastcacheLogicException, PhpfastcacheRootException, PhpfastcacheUnsupportedOperationException +}; +use Phpfastcache\Util\ClassNamespaceResolverTrait; + +/** + * Class CacheManager + * @package phpFastCache + * + * @method static ExtendedCacheItemPoolInterface Apc() Apc($config = []) Return a driver "Apc" instance + * @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "Apcu" instance + * @method static ExtendedCacheItemPoolInterface Cassandra() Cassandra($config = []) Return a driver "Cassandra" instance + * @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "Cookie" instance + * @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "Couchbase" instance + * @method static ExtendedCacheItemPoolInterface Couchdb() Couchdb($config = []) Return a driver "Couchdb" instance + * @method static ExtendedCacheItemPoolInterface Devnull() Devnull($config = []) Return a driver "Devnull" instance + * @method static ExtendedCacheItemPoolInterface Files() Files($config = []) Return a driver "files" instance + * @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "Leveldb" instance + * @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "Memcache" instance + * @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "Memcached" instance + * @method static ExtendedCacheItemPoolInterface Memstatic() Memstatic($config = []) Return a driver "Memstatic" instance + * @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "Mongodb" instance + * @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "Predis" instance + * @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "Pedis" instance + * @method static ExtendedCacheItemPoolInterface Riak() Riak($config = []) Return a driver "Riak" instance + * @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "Sqlite" instance + * @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "Ssdb" instance + * @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "Wincache" instance + * @method static ExtendedCacheItemPoolInterface Xcache() Xcache($config = []) Return a driver "Xcache" instance + * @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "Zend disk cache" instance + * @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "Zend memory cache" instance + * + */ +class CacheManager +{ + const AUTOMATIC_DRIVER_CLASS = 'Auto'; + const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\'; + + use ClassNamespaceResolverTrait; + + /** + * @var ConfigurationOption + */ + protected static $config; + + /** + * @var int + */ + public static $ReadHits = 0; + + /** + * @var int + */ + public static $WriteHits = 0; + + /** + * @var string + */ + protected static $namespacePath; + + /** + * @var ExtendedCacheItemPoolInterface[] + */ + protected static $instances = []; + + /** + * @var array + */ + protected static $driverOverrides = []; + + /** + * @var array + */ + protected static $driverCustoms = []; + + /** + * @var array + */ + protected static $badPracticeOmeter = []; + + /** + * @param string $driver + * @param array|ConfigurationOption $config + * @param string $instanceId + * + * @return ExtendedCacheItemPoolInterface + * + * @throws PhpfastcacheDriverCheckException + * @throws PhpfastcacheInvalidConfigurationException + * @throws PhpfastcacheDriverNotFoundException + * @throws PhpfastcacheInvalidArgumentException + * @throws PhpfastcacheDriverException + */ + public static function getInstance(string $driver = self::AUTOMATIC_DRIVER_CLASS, $config = null, string $instanceId = null): ExtendedCacheItemPoolInterface + { + $config = self::validateConfig($config); + $driver = self::standardizeDriverName($driver); + + if (!$driver || $driver === self::AUTOMATIC_DRIVER_CLASS) { + $driver = self::getAutoClass($config); + } + + $instanceId = $instanceId ?: \md5($driver . \serialize($config->toArray())); + + if (!isset(self::$instances[$instanceId])) { + self::$badPracticeOmeter[$driver] = 1; + $driverClass = self::validateDriverClass(self::getDriverClass($driver)); + + try { + if (\class_exists($driverClass)) { + $configClass = $driverClass::getConfigClass(); + self::$instances[$instanceId] = new $driverClass(new $configClass($config->toArray()), $instanceId); + self::$instances[$instanceId]->setEventManager(EventManager::getInstance()); + } else { + throw new PhpfastcacheDriverNotFoundException(\sprintf('The driver "%s" does not exists', $driver)); + } + } catch (PhpfastcacheDriverCheckException $e) { + return self::getFallbackInstance($driver, $config, $e); + } + } else { + if (self::$badPracticeOmeter[$driver] >= 2) { + \trigger_error('[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances. + See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'); + } + } + + self::$badPracticeOmeter[$driver]++; + + return self::$instances[$instanceId]; + } + + /** + * @param string $driver + * @param ConfigurationOption $config + * @param PhpfastcacheDriverCheckException $e + * @return ExtendedCacheItemPoolInterface + * @throws PhpfastcacheDriverCheckException + * @throws PhpfastcacheDriverException + * @throws PhpfastcacheDriverNotFoundException + * @throws PhpfastcacheInvalidConfigurationException + */ + protected static function getFallbackInstance(string $driver, ConfigurationOption $config, PhpfastcacheDriverCheckException $e) + { + if ($config->getFallback()) { + try { + $fallback = $config->getFallback(); + $config->setFallback(''); + \trigger_error(\sprintf('The "%s" driver is unavailable at the moment, the fallback driver "%s" has been used instead.', $driver, + $fallback), \E_USER_WARNING); + return self::getInstance($fallback, $config->getFallbackConfig()); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheInvalidConfigurationException('Invalid fallback driver configuration', 0, $e); + } + } else { + throw new PhpfastcacheDriverCheckException($e->getMessage(), $e->getCode(), $e); + } + } + + /** + * @param string $instanceId + * + * @return ExtendedCacheItemPoolInterface + * + * @throws PhpfastcacheInvalidArgumentException + * @throws PhpfastcacheInstanceNotFoundException + */ + public static function getInstanceById(string $instanceId): ExtendedCacheItemPoolInterface + { + if (isset(self::$instances[$instanceId])) { + return self::$instances[$instanceId]; + } + + throw new PhpfastcacheInstanceNotFoundException(\sprintf('Instance ID %s not found', $instanceId)); + } + + /** + * Return the list of instances + * + * @return ExtendedCacheItemPoolInterface[] + */ + public static function getInstances(): array + { + return self::$instances; + } + + /** + * This method is intended for internal + * use only and should not be used for + * any external development use the + * getInstances() method instead + * + * @todo Use a proper way to passe them as a reference ? + * @internal + * @return ExtendedCacheItemPoolInterface[] + */ + public static function &getInternalInstances(): array + { + return self::$instances; + } + + /** + * @param ConfigurationOption $config + * @return string + * @throws PhpfastcacheDriverCheckException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + */ + public static function getAutoClass(ConfigurationOption $config): string + { + static $autoDriver; + + if ($autoDriver === null) { + foreach (self::getDriverList() as $driver) { + /** @var ExtendedCacheItemPoolInterface $driverClass */ + $driverClass = self::CORE_DRIVER_NAMESPACE . $driver . '\Driver'; + if ($driverClass::isUsableInAutoContext()) { + try { + self::getInstance($driver, $config); + $autoDriver = $driver; + break; + } catch (PhpfastcacheDriverCheckException $e) { + continue; + } + } + } + } + + if (!$autoDriver || !\is_string($autoDriver)) { + throw new PhpfastcacheLogicException('Unable to find out a valid driver automatically'); + } + + self::$badPracticeOmeter[$autoDriver]--; + + return $autoDriver; + } + + /** + * @param string $name + * @param array $arguments + * @return ExtendedCacheItemPoolInterface + */ + public static function __callStatic(string $name, array $arguments): ExtendedCacheItemPoolInterface + { + $options = (\array_key_exists(0, $arguments) && \is_array($arguments) ? $arguments[0] : []); + + return self::getInstance($name, $options); + } + + /** + * @return bool + */ + public static function clearInstances(): bool + { + self::$instances = []; + + \gc_collect_cycles(); + return !\count(self::$instances); + } + + /** + * @param ExtendedCacheItemPoolInterface $cachePoolInstance + * @return bool + * @since 7.0.4 + */ + public static function clearInstance(ExtendedCacheItemPoolInterface $cachePoolInstance): bool + { + $found = false; + self::$instances = \array_filter(\array_map(function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInstance, &$found){ + if(\spl_object_hash($cachePool) === \spl_object_hash($cachePoolInstance)){ + $found = true; + return null; + } + return $cachePool; + }, self::$instances)); + + return $found; + } + + /** + * @return string + */ + public static function getNamespacePath(): string + { + return self::$namespacePath ?: self::getDefaultNamespacePath(); + } + + /** + * @return string + */ + public static function getDefaultNamespacePath(): string + { + return self::CORE_DRIVER_NAMESPACE; + } + + /** + * @param string $path + * @deprecated This method has been deprecated as of V7, please use driver override feature instead + */ + public static function setNamespacePath($path) + { + \trigger_error('This method has been deprecated as of V7, please use cache manager "override" or "custom driver" features instead', E_USER_DEPRECATED); + self::$namespacePath = \trim($path, "\\") . '\\'; + } + + /** + * @param ConfigurationOption $config + */ + public static function setDefaultConfig(ConfigurationOption $config) + { + self::$config = $config; + } + + /** + * @return ConfigurationOption + */ + public static function getDefaultConfig(): ConfigurationOption + { + return self::$config ?: self::$config = new ConfigurationOption(); + } + + /** + * @return array + * @deprecated As of V7 will be removed soon or later, use CacheManager::getDriverList() instead + */ + public static function getStaticSystemDrivers(): array + { + \trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', + __METHOD__), \E_USER_DEPRECATED); + return [ + 'Apc', + 'Apcu', + 'Cassandra', + 'Couchbase', + 'Couchdb', + 'Devnull', + 'Files', + 'Leveldb', + 'Memcache', + 'Memcached', + 'Memstatic', + 'Mongodb', + 'Predis', + 'Redis', + 'Riak', + 'Ssdb', + 'Sqlite', + 'Wincache', + 'Xcache', + 'Zenddisk', + 'Zendshm', + ]; + } + + /** + * @return array + * @deprecated As of V7 will be removed soon or later, use CacheManager::getDriverList() instead + */ + public static function getStaticAllDrivers(): array + { + \trigger_error(\sprintf('Method "%s" is deprecated as of the V7 and will be removed soon or later, use CacheManager::getDriverList() instead.', + __METHOD__), \E_USER_DEPRECATED); + return \array_merge(self::getStaticSystemDrivers(), [ + 'Devtrue', + 'Devfalse', + 'Cookie', + ]); + } + + /** + * Return the list of available drivers Capitalized + * with optional FQCN as key + * + * @param bool $FQCNAsKey Describe keys with Full Qualified Class Name + * @return string[] + * @throws PhpfastcacheUnsupportedOperationException + */ + public static function getDriverList(bool $FQCNAsKey = false): array + { + static $driverList; + + if (self::getDefaultNamespacePath() === self::getNamespacePath()) { + if ($driverList === null) { + $prefix = self::CORE_DRIVER_NAMESPACE; + $classMap = self::createClassMap(__DIR__ . '/Drivers'); + $driverList = []; + + foreach ($classMap as $class => $file) { + $driverList[] = \str_replace($prefix, '', \substr($class, 0, \strrpos($class, '\\'))); + } + + $driverList = \array_values(\array_unique($driverList)); + } + + $driverList = \array_merge($driverList, \array_keys(self::$driverCustoms)); + + if ($FQCNAsKey) { + $realDriverList = []; + foreach ($driverList as $driverName) { + $realDriverList[self::getDriverClass($driverName)] = $driverName; + } + $driverList = $realDriverList; + } + + \asort($driverList); + + return $driverList; + } + + throw new PhpfastcacheUnsupportedOperationException('Cannot get the driver list if the default namespace path has changed.'); + } + + /** + * @param string $driverName + * @return string + */ + public static function standardizeDriverName(string $driverName): string + { + return \ucfirst(\strtolower(\trim($driverName))); + } + + /** + * @param string $driverName + * @return string + */ + public static function getDriverClass(string $driverName): string + { + if (!empty(self::$driverCustoms[$driverName])) { + $driverClass = self::$driverCustoms[$driverName]; + } else { + if (!empty(self::$driverOverrides[$driverName])) { + $driverClass = self::$driverOverrides[$driverName]; + } else { + $driverClass = self::getNamespacePath() . $driverName . '\Driver'; + } + } + + return $driverClass; + } + + /** + * @param string $driverName + * @param string $className + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + * @throws \Phpfastcache\Exceptions\PhpfastcacheUnsupportedOperationException + * @return void + */ + public static function addCustomDriver(string $driverName, string $className) + { + $driverName = self::standardizeDriverName($driverName); + + if (empty($driverName)) { + throw new PhpfastcacheInvalidArgumentException("Can't add a custom driver because its name is empty"); + } + + if (!\class_exists($className)) { + throw new PhpfastcacheInvalidArgumentException( + \sprintf("Can't add '%s' because the class '%s' does not exists", $driverName, $className) + ); + } + + if (!empty(self::$driverCustoms[$driverName])) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already added", $driverName)); + } + + if (\in_array($driverName, self::getDriverList(), true)) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' is already a part of the PhpFastCache core", $driverName)); + } + + self::$driverCustoms[$driverName] = $className; + } + + /** + * @param string $driverName + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + * @return void + */ + public static function removeCustomDriver(string $driverName) + { + $driverName = self::standardizeDriverName($driverName); + + if (empty($driverName)) { + throw new PhpfastcacheInvalidArgumentException("Can't remove a custom driver because its name is empty"); + } + + if (!isset(self::$driverCustoms[$driverName])) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' does not exists", $driverName)); + } + + unset(self::$driverCustoms[$driverName]); + } + + /** + * @param string $driverName + * @param string $className + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + * @throws \Phpfastcache\Exceptions\PhpfastcacheUnsupportedOperationException + * @return void + */ + public static function addCoreDriverOverride(string $driverName, string $className) + { + $driverName = self::standardizeDriverName($driverName); + + if (empty($driverName)) { + throw new PhpfastcacheInvalidArgumentException("Can't add a core driver override because its name is empty"); + } + + if (!\class_exists($className)) { + throw new PhpfastcacheInvalidArgumentException( + \sprintf("Can't override '%s' because the class '%s' does not exists", $driverName, $className) + ); + } + + if (!empty(self::$driverOverrides[$driverName])) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' has been already overridden", $driverName)); + } + + if (!\in_array($driverName, self::getDriverList(), true)) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' can't be overridden since its not a part of the PhpFastCache core", $driverName)); + } + + if (!\is_subclass_of($className, self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver', true)) { + throw new PhpfastcacheLogicException( + \sprintf("Can't override '%s' because the class '%s' MUST extend '%s'", $driverName, $className, + self::CORE_DRIVER_NAMESPACE . $driverName . '\\Driver') + ); + } + + self::$driverOverrides[$driverName] = $className; + } + + /** + * @param string $driverName + * @throws \Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + * @return void + */ + public static function removeCoreDriverOverride(string $driverName) + { + $driverName = self::standardizeDriverName($driverName); + + if (empty($driverName)) { + throw new PhpfastcacheInvalidArgumentException("Can't remove a core driver override because its name is empty"); + } + + if (!isset(self::$driverOverrides[$driverName])) { + throw new PhpfastcacheLogicException(\sprintf("Driver '%s' were not overridden", $driverName)); + } + + unset(self::$driverOverrides[$driverName]); + } + + /** + * @param array|ConfigurationOption + * @return ConfigurationOption + * @throws PhpfastcacheInvalidArgumentException + * @throws PhpfastcacheInvalidConfigurationException + */ + protected static function validateConfig($config): ConfigurationOption + { + if (\is_array($config)) { + $config = new ConfigurationOption($config); + \trigger_error( + 'The CacheManager will drops the support of primitive configuration arrays, use a "\Phpfastcache\Config\ConfigurationOption" object instead', + E_USER_DEPRECATED + ); + } elseif ($config === null) { + $config = self::getDefaultConfig(); + } else { + if (!($config instanceof ConfigurationOption)) { + throw new PhpfastcacheInvalidArgumentException(\sprintf('Unsupported config type: %s', \gettype($config))); + } + } + + return $config; + } + + /** + * @param string $driverClass + * @return string + * @throws PhpfastcacheDriverException + */ + protected static function validateDriverClass(string $driverClass): string + { + if (!\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) { + throw new PhpfastcacheDriverException(\sprintf( + 'Class "%s" does not implement "%s"', + $driverClass, + ExtendedCacheItemPoolInterface::class + )); + } + return $driverClass; + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/Config.php new file mode 100644 index 0000000..eb322f9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/Config.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); +namespace Phpfastcache\Config; + +/** + * Class Config + * Alias of ConfigurationOption + * @package phpFastCache\Config + * @see ConfigurationOption + */ +class Config extends ConfigurationOption +{ +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOption.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOption.php new file mode 100644 index 0000000..2392f74 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOption.php @@ -0,0 +1,450 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Config; + +use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; +use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; +use Phpfastcache\Util\ArrayObject; + +class ConfigurationOption extends ArrayObject implements ConfigurationOptionInterface +{ + /** + * @var bool + */ + protected $itemDetailedDate = false; + + /** + * @var bool + */ + protected $autoTmpFallback = false; + + /** + * @var bool + * @deprecated Do not use this option anymore + */ + protected $ignoreSymfonyNotice = false; + + /** + * @var int + */ + protected $defaultTtl = 900; + + /** + * @var string|Callable + */ + protected $defaultKeyHashFunction = 'md5'; + + /** + * @var string|Callable + */ + protected $defaultFileNameHashFunction = 'md5'; + + /** + * @var int + */ + protected $defaultChmod = 0777; + + /** + * @var string + */ + protected $path = ''; + + /** + * @var string + */ + protected $fallback = ''; + + /** + * @var \Phpfastcache\Config\ConfigurationOption + */ + protected $fallbackConfig; + + /** + * @var int + */ + protected $limitedMemoryByObject = 4096; + + /** + * @var bool + */ + protected $compressData = false; + + /** + * @var bool + */ + protected $preventCacheSlams = false; + + /** + * @var int + */ + protected $cacheSlamsTimeout = 15; + + + /** + * @param $args + * ArrayObject constructor. + * @throws PhpfastcacheInvalidConfigurationException + * @throws \ReflectionException + */ + public function __construct(...$args) + { + parent::__construct(...$args); + $array =& $this->getArray(); + + /** + * Detect unwanted keys and throw an exception. + * No more kidding now, it's 21th century. + */ + if (\array_diff_key($array, \get_object_vars($this))) { + throw new PhpfastcacheInvalidConfigurationException(\sprintf( + 'Invalid option(s) for the config %s: %s', + static::class, + \implode(', ', \array_keys(\array_diff_key($array, \get_object_vars($this)))) + )); + } + + foreach (\get_object_vars($this) as $property => $value) { + + if (\array_key_exists($property, $array)) { + $this->$property = &$array[$property]; + } else { + $array[$property] = &$this->$property; + } + } + + foreach (\get_class_methods($this) as $method) { + if (\strpos($method, 'set') === 0) { + $value = null; + try { + /** + * We use property instead of getter + * because of is/get conditions and + * to allow us to retrieve the value + * in catch statement bloc + */ + $value = $this->{\lcfirst(\substr($method, 3))}; + $this->{$method}($value); + } catch (\TypeError $e) { + $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); + $reflectionMethod = new \ReflectionMethod($this, $method); + $parameter = $reflectionMethod->getParameters()[0] ?? null; + $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType() === 'object' ? $parameter->getClass() : $parameter->getType()) : 'Unknown type'); + + throw new PhpfastcacheInvalidConfigurationException(\sprintf( + 'Invalid type hint found for "%s", expected "%s" got "%s"', + \lcfirst(\substr($method, 3)), + $typeHintExpected, + $typeHintGot + )); + } + } + } + } + + /** + * @param string $optionName + * @return mixed|null + * @deprecated Use ->getOptionName() instead + */ + public function getOption(string $optionName) + { + \trigger_error(\sprintf('Method "%s" is deprecated, use "getOptionName()" instead', __METHOD__), \E_USER_DEPRECATED); + return $this->$optionName ?? null; + } + + /** + * @param string $optionName + * @return mixed|null + */ + public function isValidOption(string $optionName) + { + return \property_exists($this, $optionName); + } + + /** + * @return bool + */ + public function isItemDetailedDate(): bool + { + return $this->itemDetailedDate; + } + + /** + * @param bool $itemDetailedDate + * @return ConfigurationOption + */ + public function setItemDetailedDate(bool $itemDetailedDate): self + { + $this->itemDetailedDate = $itemDetailedDate; + return $this; + } + + /** + * @return bool + */ + public function isAutoTmpFallback(): bool + { + return $this->autoTmpFallback; + } + + /** + * @param bool $autoTmpFallback + * @return ConfigurationOption + */ + public function setAutoTmpFallback(bool $autoTmpFallback): self + { + $this->autoTmpFallback = $autoTmpFallback; + return $this; + } + + /** + * @return bool + * @deprecated As of V7 + */ + public function isIgnoreSymfonyNotice(): bool + { + return $this->ignoreSymfonyNotice; + } + + /** + * @param bool $ignoreSymfonyNotice + * @return ConfigurationOption + * @deprecated As of V7 + */ + public function setIgnoreSymfonyNotice(bool $ignoreSymfonyNotice): self + { + if ($ignoreSymfonyNotice) { + \trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', \E_USER_DEPRECATED); + } + $this->ignoreSymfonyNotice = $ignoreSymfonyNotice; + return $this; + } + + /** + * @return int + */ + public function getDefaultTtl(): int + { + return $this->defaultTtl; + } + + /** + * @param int $defaultTtl + * @return ConfigurationOption + */ + public function setDefaultTtl(int $defaultTtl): self + { + $this->defaultTtl = $defaultTtl; + return $this; + } + + /** + * @return Callable|string + */ + public function getDefaultKeyHashFunction() + { + return $this->defaultKeyHashFunction; + } + + /** + * @param Callable|string $defaultKeyHashFunction + * @return ConfigurationOption + * @throws PhpfastcacheInvalidConfigurationException + */ + public function setDefaultKeyHashFunction($defaultKeyHashFunction): self + { + if (!\is_callable($defaultKeyHashFunction) && (\is_string($defaultKeyHashFunction) && !\function_exists($defaultKeyHashFunction))) { + throw new PhpfastcacheInvalidConfigurationException('defaultKeyHashFunction must be a valid function name string'); + } + $this->defaultKeyHashFunction = $defaultKeyHashFunction; + return $this; + } + + /** + * @return Callable|string + */ + public function getDefaultFileNameHashFunction() + { + return $this->defaultFileNameHashFunction; + } + + /** + * @param Callable|string $defaultFileNameHashFunction + * @return ConfigurationOption + * @throws PhpfastcacheInvalidConfigurationException + */ + public function setDefaultFileNameHashFunction($defaultFileNameHashFunction): self + { + if (!\is_callable($defaultFileNameHashFunction) && (\is_string($defaultFileNameHashFunction) && !\function_exists($defaultFileNameHashFunction))) { + throw new PhpfastcacheInvalidConfigurationException('defaultFileNameHashFunction must be a valid function name string'); + } + $this->defaultFileNameHashFunction = $defaultFileNameHashFunction; + return $this; + } + + /** + * @return int + */ + public function getDefaultChmod(): int + { + return $this->defaultChmod; + } + + /** + * @param int $defaultChmod + * @return ConfigurationOption + */ + public function setDefaultChmod(int $defaultChmod): self + { + $this->defaultChmod = $defaultChmod; + return $this; + } + + /** + * @return string + */ + public function getPath(): string + { + return $this->path; + } + + /** + * @param string $path + * @return ConfigurationOption + */ + public function setPath(string $path): self + { + $this->path = $path; + return $this; + } + + /** + * @return bool|string + */ + public function getFallback() + { + return $this->fallback; + } + + /** + * @param string $fallback + * @return ConfigurationOption + */ + public function setFallback(string $fallback): self + { + $this->fallback = $fallback; + return $this; + } + + /** + * @return \Phpfastcache\Config\ConfigurationOption|null + */ + public function getFallbackConfig() + { + return $this->fallbackConfig; + } + + /** + * @param \Phpfastcache\Config\ConfigurationOption|null $fallbackConfig + * @return ConfigurationOption + * @throws PhpfastcacheInvalidArgumentException + */ + public function setFallbackConfig($fallbackConfig): self + { + if ($fallbackConfig !== null && !($fallbackConfig instanceof self)) { + throw new PhpfastcacheInvalidArgumentException(\sprintf( + 'Invalid argument "%s" for %s', + \is_object($fallbackConfig) ? \get_class($fallbackConfig) : \gettype($fallbackConfig), + __METHOD__ + )); + } + $this->fallbackConfig = $fallbackConfig; + return $this; + } + + /** + * @return int + */ + public function getLimitedMemoryByObject(): int + { + return $this->limitedMemoryByObject; + } + + /** + * @param int $limitedMemoryByObject + * @return ConfigurationOption + */ + public function setLimitedMemoryByObject(int $limitedMemoryByObject): self + { + $this->limitedMemoryByObject = $limitedMemoryByObject; + return $this; + } + + /** + * @return bool + */ + public function isCompressData(): bool + { + return $this->compressData; + } + + /** + * @param bool $compressData + * @return ConfigurationOption + */ + public function setCompressData(bool $compressData): self + { + $this->compressData = $compressData; + return $this; + } + + /** + * @return bool + */ + public function isPreventCacheSlams(): bool + { + return $this->preventCacheSlams; + } + + /** + * @param bool $preventCacheSlams + * @return ConfigurationOption + */ + public function setPreventCacheSlams(bool $preventCacheSlams): self + { + $this->preventCacheSlams = $preventCacheSlams; + return $this; + } + + /** + * @return int + */ + public function getCacheSlamsTimeout(): int + { + return $this->cacheSlamsTimeout; + } + + /** + * @param int $cacheSlamsTimeout + * @return ConfigurationOption + */ + public function setCacheSlamsTimeout(int $cacheSlamsTimeout): self + { + $this->cacheSlamsTimeout = $cacheSlamsTimeout; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOptionInterface.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOptionInterface.php new file mode 100644 index 0000000..60a84c1 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/ConfigurationOptionInterface.php @@ -0,0 +1,38 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); +namespace Phpfastcache\Config; + + +interface ConfigurationOptionInterface +{ + /** + * @param $args + * ArrayObject constructor. + */ + public function __construct(...$args); + + /** + * @param string $optionName + * @return mixed|null + * @deprecated Use ->getOptionName() instead + */ + public function getOption(string $optionName); + + /** + * @param string $optionName + * @return mixed|null + */ + public function isValidOption(string $optionName); +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php new file mode 100644 index 0000000..1be4dda --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php @@ -0,0 +1,133 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); +namespace Phpfastcache\Config; + +use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; + +const SAFE_FILE_EXTENSIONS = 'txt|cache|db|pfc'; + +trait IOConfigurationOptionTrait +{ + /** + * @var boolean + */ + protected $secureFileManipulation = false; + + /** + * @var bool + */ + protected $htaccess = true; + + /** + * @var string + */ + protected $securityKey = ''; + + /** + * @var string + */ + protected $cacheFileExtension = 'txt'; + + /** + * @return string + */ + public function getSecurityKey(): string + { + return $this->securityKey; + } + + /** + * @param string $securityKey + * @return Config + */ + public function setSecurityKey(string $securityKey): self + { + $this->securityKey = $securityKey; + + return $this; + } + + /** + * @return bool + */ + public function getHtaccess(): bool + { + return $this->htaccess; + } + + /** + * @param bool $htaccess + * @return Config + */ + public function setHtaccess(bool $htaccess): ConfigurationOptionInterface + { + $this->htaccess = $htaccess; + + return $this; + } + + /** + * @return bool + */ + public function isSecureFileManipulation(): bool + { + return $this->secureFileManipulation; + } + + /** + * @param bool $secureFileManipulation + * @return self + */ + public function setSecureFileManipulation(bool $secureFileManipulation): self + { + $this->secureFileManipulation = $secureFileManipulation; + return $this; + } + + + /** + * @return string + */ + public function getCacheFileExtension(): string + { + return $this->cacheFileExtension; + } + + /** + * @param string $cacheFileExtension + * @return self + * @throws PhpfastcacheInvalidConfigurationException + */ + public function setCacheFileExtension(string $cacheFileExtension): self + { + /** + * Feel free to propose your own one + * by opening a pull request :) + */ + $safeFileExtensions = \explode('|', SAFE_FILE_EXTENSIONS); + + if (\strpos($cacheFileExtension, '.') !== false) { + throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."'); + } + if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { + throw new PhpfastcacheInvalidConfigurationException( + "Extension \"{$cacheFileExtension}\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions) + ); + } + + $this->cacheFileExtension = $cacheFileExtension; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php new file mode 100644 index 0000000..eb3be17 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php @@ -0,0 +1,221 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Item; + +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Interface ExtendedCacheItemInterface + * @package phpFastCache\Cache + */ +interface ExtendedCacheItemInterface extends CacheItemInterface, \JsonSerializable +{ + /** + * Returns the encoded key for the current cache item. + * Usually as a MD5 hash + * + * @return string + * The encoded key string for this cache item. + */ + public function getEncodedKey(): string; + + /** + * @return \DateTimeInterface + */ + public function getExpirationDate(): \DateTimeInterface; + + /** + * Alias of expireAt() with forced $expiration param + * + * @param \DateTimeInterface $expiration + * The point in time after which the item MUST be considered expired. + * If null is passed explicitly, a default value MAY be used. If none is set, + * the value should be stored permanently or for as long as the + * implementation allows. + * + * @return self + * The called object. + */ + public function setExpirationDate(\DateTimeInterface $expiration): self; + + /** + * @return \DateTimeInterface + * @throws PhpfastcacheLogicException + */ + public function getCreationDate(): \DateTimeInterface; + + /** + * @return \DateTimeInterface + * @throws PhpfastcacheLogicException + */ + public function getModificationDate(): \DateTimeInterface; + + /** + * @param $date \DateTimeInterface + * @return self + * @throws PhpfastcacheLogicException + */ + public function setCreationDate(\DateTimeInterface $date): self; + + /** + * @param $date \DateTimeInterface + * @return self + * @throws PhpfastcacheLogicException + */ + public function setModificationDate(\DateTimeInterface $date): self; + + /** + * @return int + */ + public function getTtl(): int; + + /** + * @return bool + */ + public function isExpired(): bool; + + /** + * @return bool + */ + public function isNull(): bool; + + /** + * @return bool + */ + public function isEmpty(): bool; + + /** + * Return the data length: + * - Either the number of char if it's a string (binary mode) + * - or the number of element if it's an array + * - or the number returned by count() if it's an object implementing \Countable interface + * - or -1 for anything else + * @return int + */ + public function getLength(): int; + + /** + * @param \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface $driver + * @return mixed + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver); + + /** + * @param bool $isHit + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function setHit($isHit): self; + + /** + * @param int $step + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function increment($step = 1): self; + + /** + * @param int $step + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function decrement($step = 1): self; + + /** + * @param array|string $data + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function append($data): self; + + /** + * @param array|string $data + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function prepend($data): self; + + /** + * @param string $tagName + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function addTag($tagName): self; + + /** + * @param array $tagNames + * @return self + */ + public function addTags(array $tagNames): self; + + + /** + * @param array $tags + * @return self + * @throws PhpfastcacheInvalidArgumentException + */ + public function setTags(array $tags): self; + + /** + * @return array + */ + public function getTags(): array; + + /** + * @param string $separator + * @return string + */ + public function getTagsAsString($separator = ', '): string; + + /** + * @param array $tagName + * @return self + */ + public function removeTag($tagName): self; + + /** + * @param array $tagNames + * @return self + */ + public function removeTags(array $tagNames): self; + + /** + * @return array + */ + public function getRemovedTags(): array; + + /** + * Return the data as a well-formatted string. + * Any scalar value will be casted to an array + * @param int $option \json_encode() options + * @param int $depth \json_encode() depth + * @return string + */ + public function getDataAsJsonString($option = 0, $depth = 512): string; + + /** + * Set the EventManager instance + * + * @param EventInterface $em + * @return self + */ + public function setEventManager(EventInterface $em): self; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemBaseTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemBaseTrait.php new file mode 100644 index 0000000..341f119 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemBaseTrait.php @@ -0,0 +1,207 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Item; + +use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; + +/** + * Trait ItemBaseTrait + * @package phpFastCache\Core\Item + */ +trait ItemBaseTrait +{ + use ItemExtendedTrait; + + /** + * @var bool + */ + protected $fetched = false; + + /** + * @var string + */ + protected $key; + + /** + * @var mixed + */ + protected $data; + + /** + * @var \DateTimeInterface + */ + protected $expirationDate; + + /** + * @var \DateTimeInterface + */ + protected $creationDate; + + /** + * @var \DateTimeInterface + */ + protected $modificationDate; + + /** + * @var array + */ + protected $tags = []; + + /** + * @var array + */ + protected $removedTags = []; + + /** + * @var bool + */ + protected $isHit = false; + + /******************** + * + * PSR-6 Methods + * + *******************/ + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @return mixed + */ + public function get() + { + return $this->data; + } + + /** + * @param mixed $value + * @return $this + */ + public function set($value) + { + /** + * The user set a value, + * therefore there is no need to + * fetch from source anymore + */ + $this->fetched = true; + $this->data = $value; + + /** + * @eventName CacheSaveDeferredItem + * @param ExtendedCacheItemInterface $this + * @param mixed $value + * + */ + $this->eventManager->dispatch('CacheItemSet', $this, $value); + + return $this; + } + + /** + * @return bool + */ + public function isHit(): bool + { + return $this->isHit; + } + + /** + * @param bool $isHit + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function setHit($isHit): ExtendedCacheItemInterface + { + if (\is_bool($isHit)) { + $this->isHit = $isHit; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('$isHit must be a boolean'); + } + + /** + * @param \DateTimeInterface $expiration + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function expiresAt($expiration): ExtendedCacheItemInterface + { + if ($expiration instanceof \DateTimeInterface) { + /** + * @eventName CacheItemExpireAt + * @param ExtendedCacheItemInterface $this + * @param \DateTimeInterface $expiration + */ + $this->eventManager->dispatch('CacheItemExpireAt', $this, $expiration); + $this->expirationDate = $expiration; + } else { + throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration)); + } + + return $this; + } + + /** + * @param \DateInterval|int $time + * @return $this + * @throws PhpfastcacheInvalidArgumentException + */ + public function expiresAfter($time) + { + if (\is_numeric($time)) { + if ($time <= 0) { + /** + * 5 years, however memcached or memory cached will gone when u restart it + * just recommended for sqlite. files + */ + $time = 30 * 24 * 3600 * 5; + } + + /** + * @eventName CacheItemExpireAt + * @param ExtendedCacheItemInterface $this + * @param \DateTimeInterface $expiration + */ + $this->eventManager->dispatch('CacheItemExpireAfter', $this, $time); + + $this->expirationDate = (new \DateTime())->add(new \DateInterval(\sprintf('PT%dS', $time))); + } else { + if ($time instanceof \DateInterval) { + /** + * @eventName CacheItemExpireAt + * @param ExtendedCacheItemInterface $this + * @param \DateTimeInterface $expiration + */ + $this->eventManager->dispatch('CacheItemExpireAfter', $this, $time); + + $this->expirationDate = (new \DateTime())->add($time); + } else { + throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time))); + } + } + + return $this; + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemExtendedTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemExtendedTrait.php new file mode 100644 index 0000000..115df7b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/ItemExtendedTrait.php @@ -0,0 +1,469 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Item; + +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheInvalidArgumentTypeException, PhpfastcacheLogicException +}; + +/** + * Class ItemExtendedTrait + * @package phpFastCache\Core\Item + * @property \DateTimeInterface $expirationDate Expiration date of the item + * @property \DateTimeInterface $creationDate Creation date of the item + * @property \DateTimeInterface $modificationDate Modification date of the item + * @property mixed $data Data of the item + * @property bool $fetched Fetch flag status + * @property array $tags The tags array + * @property array $removedTags The removed tags array + * @property string $key The item key + */ +trait ItemExtendedTrait +{ + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @var EventInterface + */ + protected $eventManager; + + + /** + * @var ExtendedCacheItemPoolInterface + */ + protected $driver; + + /** + * @var string + */ + protected $encodedKey; + + /** + * Item constructor. + * @param ExtendedCacheItemPoolInterface $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(ExtendedCacheItemPoolInterface $driver, $key) + { + if (\is_string($key)) { + $this->key = $key; + $this->driver = $driver; + $this->driver->setItem($this); + $this->expirationDate = new \DateTime(); + if ($this->driver->getConfig()->isItemDetailedDate()) { + $this->creationDate = new \DateTime(); + $this->modificationDate = new \DateTime(); + } + } else { + throw new PhpfastcacheInvalidArgumentTypeException('string', $key); + } + } + + /** + * @return string + */ + public function getEncodedKey(): string + { + if (!$this->encodedKey) { + $keyHashFunction = $this->driver->getConfig()->getDefaultKeyHashFunction(); + + if ($keyHashFunction) { + $this->encodedKey = $keyHashFunction($this->getKey()); + } else { + $this->encodedKey = \md5($this->getKey()); + } + } + + return $this->encodedKey; + } + + /** + * @return \DateTimeInterface + */ + public function getExpirationDate(): \DateTimeInterface + { + return $this->expirationDate; + } + + /** + * Alias of expireAt() with forced $expiration param + * + * @param \DateTimeInterface $expiration + * The point in time after which the item MUST be considered expired. + * If null is passed explicitly, a default value MAY be used. If none is set, + * the value should be stored permanently or for as long as the + * implementation allows. + * + * @return ExtendedCacheItemInterface + * The called object. + */ + public function setExpirationDate(\DateTimeInterface $expiration): ExtendedCacheItemInterface + { + return $this->expiresAt($expiration); + } + + /** + * @return \DateTimeInterface + * @throws PhpfastcacheLogicException + */ + public function getCreationDate(): \DateTimeInterface + { + if ($this->driver->getConfig()->isItemDetailedDate()) { + return $this->creationDate; + } + + throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.'); + } + + /** + * @param \DateTimeInterface $date + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheLogicException + */ + public function setCreationDate(\DateTimeInterface $date): ExtendedCacheItemInterface + { + if ($this->driver->getConfig()->isItemDetailedDate()) { + $this->creationDate = $date; + return $this; + } + + throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.'); + } + + /** + * @return \DateTimeInterface + * @throws PhpfastcacheLogicException + */ + public function getModificationDate(): \DateTimeInterface + { + if ($this->driver->getConfig()->isItemDetailedDate()) { + return $this->modificationDate; + } + + throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.'); + } + + /** + * @param \DateTimeInterface $date + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheLogicException + */ + public function setModificationDate(\DateTimeInterface $date): ExtendedCacheItemInterface + { + if ($this->driver->getConfig()->isItemDetailedDate()) { + $this->modificationDate = $date; + return $this; + } + + throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.'); + } + + /** + * @return int + */ + public function getTtl(): int + { + return \max(0, $this->expirationDate->getTimestamp() - \time()); + } + + /** + * @return bool + */ + public function isExpired(): bool + { + return $this->expirationDate->getTimestamp() < (new \DateTime())->getTimestamp(); + } + + /** + * @return bool + */ + public function isNull(): bool + { + return $this->data === null; + } + + /** + * @return bool + */ + public function isEmpty(): bool + { + return empty($this->data); + } + + /** + * Return the data length: + * Either the string length if it's a string (binary mode) + * # or the number of element (count) if it's an array + * # or the number returned by count() if it's an object implementing \Countable interface + * # -1 for anything else + * @return int + */ + public function getLength(): int + { + switch (\gettype($this->data)) { + case 'array': + case 'object': + if (\is_array($this->data) || $this->data instanceof \Countable) { + return \count($this->data); + } + break; + + case 'string': + return \strlen($this->data); + break; + } + + return -1; + } + + + /** + * @param int $step + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function increment($step = 1): ExtendedCacheItemInterface + { + if (\is_int($step)) { + $this->fetched = true; + $this->data += $step; + } else { + throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); + } + + return $this; + } + + /** + * @param int $step + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function decrement($step = 1): ExtendedCacheItemInterface + { + if (\is_int($step)) { + $this->fetched = true; + $this->data -= $step; + } else { + throw new PhpfastcacheInvalidArgumentException('$step must be numeric.'); + } + + return $this; + } + + /** + * @param array|string $data + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function append($data): ExtendedCacheItemInterface + { + if (\is_array($this->data)) { + $this->data[] = $data; + } else { + if (\is_string($data)) { + $this->data .= (string)$data; + } else { + throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); + } + } + + return $this; + } + + + /** + * @param array|string $data + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function prepend($data): ExtendedCacheItemInterface + { + if (\is_array($this->data)) { + \array_unshift($this->data, $data); + } else { + if (\is_string($data)) { + $this->data = (string)$data . $this->data; + } else { + throw new PhpfastcacheInvalidArgumentException('$data must be either array nor string.'); + } + } + + return $this; + } + + /** + * @param $tagName + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function addTag($tagName): ExtendedCacheItemInterface + { + if (\is_string($tagName)) { + $this->tags = \array_unique(\array_merge($this->tags, [$tagName])); + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); + } + + /** + * @param array $tagNames + * @return ExtendedCacheItemInterface + */ + public function addTags(array $tagNames): ExtendedCacheItemInterface + { + foreach ($tagNames as $tagName) { + $this->addTag($tagName); + } + + return $this; + } + + /** + * @param array $tags + * @return ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + */ + public function setTags(array $tags): ExtendedCacheItemInterface + { + if (\count($tags)) { + if (\array_filter($tags, 'is_string')) { + $this->tags = $tags; + } else { + throw new PhpfastcacheInvalidArgumentException('$tagName must be an array of string'); + } + } + + return $this; + } + + /** + * @return array + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @param string $separator + * @return string + */ + public function getTagsAsString($separator = ', '): string + { + return \implode($separator, $this->tags); + } + + /** + * @param $tagName + * @return ExtendedCacheItemInterface + */ + public function removeTag($tagName): ExtendedCacheItemInterface + { + if (($key = \array_search($tagName, $this->tags, true)) !== false) { + unset($this->tags[$key]); + $this->removedTags[] = $tagName; + } + + return $this; + } + + /** + * @param array $tagNames + * @return ExtendedCacheItemInterface + */ + public function removeTags(array $tagNames): ExtendedCacheItemInterface + { + foreach ($tagNames as $tagName) { + $this->removeTag($tagName); + } + + return $this; + } + + /** + * @return array + */ + public function getRemovedTags(): array + { + return \array_diff($this->removedTags, $this->tags); + } + + /** + * Return the data as a well-formatted string. + * Any scalar value will be casted to an array + * @param int $option \json_encode() options + * @param int $depth \json_encode() depth + * @return string + */ + public function getDataAsJsonString($option = 0, $depth = 512): string + { + $data = $this->get(); + + if (\is_object($data) || \is_array($data)) { + $data = \json_encode($data, $option, $depth); + } else { + $data = \json_encode([$data], $option, $depth); + } + + return \json_encode($data, $option, $depth); + } + + /** + * Implements \JsonSerializable interface + * @return mixed + */ + public function jsonSerialize() + { + return $this->get(); + } + + + /** + * Set the EventManager instance + * + * @param EventInterface $em + * @return ExtendedCacheItemInterface + */ + public function setEventManager(EventInterface $em): ExtendedCacheItemInterface + { + $this->eventManager = $em; + + return $this; + } + + + /** + * Prevent recursions for Debug (php 5.6+) + * @return array + */ + final public function __debugInfo() + { + $info = \get_object_vars($this); + $info['driver'] = 'object(' . \get_class($info['driver']) . ')'; + + return $info; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/AbstractDriverPoolTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/AbstractDriverPoolTrait.php new file mode 100644 index 0000000..6042491 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/AbstractDriverPoolTrait.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool; + +use Psr\Cache\CacheItemInterface; + +/** + * Trait AbstractCacheItemPoolTrait + * @package Phpfastcache\Core\Pool + */ +trait AbstractDriverPoolTrait +{ + /** + * @return bool + */ + abstract protected function driverCheck(): bool; + + /** + * @return bool + */ + abstract protected function driverConnect(): bool; + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array [ + * 'd' => 'THE ITEM DATA' + * 't' => 'THE ITEM DATE EXPIRATION' + * 'g' => 'THE ITEM TAGS' + * ] + * + */ + abstract protected function driverRead(CacheItemInterface $item); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + */ + abstract protected function driverWrite(CacheItemInterface $item): bool; + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + */ + abstract protected function driverDelete(CacheItemInterface $item): bool; + + /** + * @return bool + */ + abstract protected function driverClear(): bool; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php new file mode 100644 index 0000000..40f580d --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php @@ -0,0 +1,422 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool; + +use Phpfastcache\CacheManager; +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Entities\ItemBatch; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\EventManager; +use Phpfastcache\Exceptions\{ + PhpfastcacheCoreException, PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Phpfastcache\Util\ClassNamespaceResolverTrait; +use Psr\Cache\CacheItemInterface; + +/** + * Trait StandardPsr6StructureTrait + * @package phpFastCache\Core + * @property ConfigurationOption $config The config array + * @method ConfigurationOption getConfig() Return the config object + */ +trait CacheItemPoolTrait +{ + use ClassNamespaceResolverTrait; + + /** + * @var string + */ + protected static $unsupportedKeyChars = '{}()/\@:'; + + /** + * @var array + */ + protected $deferredList = []; + + /** + * @var ExtendedCacheItemInterface[] + */ + protected $itemInstances = []; + + /** + * @var EventInterface + */ + protected $eventManager; + + /** + * @param string $key + * @return \Phpfastcache\Core\Item\ExtendedCacheItemInterface + * @throws PhpfastcacheInvalidArgumentException + * @throws PhpfastcacheLogicException + * @throws PhpfastcacheCoreException + */ + public function getItem($key) + { + if (\is_string($key)) { + /** + * Replace array_key_exists by isset + * due to performance issue on huge + * loop dispatching operations + */ + if (!isset($this->itemInstances[$key])) { + if (\preg_match('~([' . \preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) { + throw new PhpfastcacheInvalidArgumentException('Unsupported key character detected: "' . $matches[1] . '". Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers'); + } + + CacheManager::$ReadHits++; + $cacheSlamsSpendSeconds = 0; + $class = $this->getClassNamespace() . '\Item'; + /** @var $item ExtendedCacheItemInterface */ + $item = new $class($this, $key); + $item->setEventManager($this->eventManager); + + getItemDriverRead: + { + $driverArray = $this->driverRead($item); + + if ($driverArray) { + if (!\is_array($driverArray)) { + throw new PhpfastcacheCoreException(\sprintf('The driverRead method returned an unexpected variable type: %s', + \gettype($driverArray))); + } + $driverData = $this->driverUnwrapData($driverArray); + + if ($this->getConfig()['preventCacheSlams']) { + while ($driverData instanceof ItemBatch) { + if ($driverData->getItemDate()->getTimestamp() + $this->getConfig()->getCacheSlamsTimeout() < \time()) { + /** + * The timeout has been reached + * Consider that the batch has + * failed and serve an empty item + * to avoid to get stuck with a + * batch item stored in driver + */ + goto getItemDriverExpired; + } + /** + * @eventName CacheGetItem + * @param $this ExtendedCacheItemPoolInterface + * @param $driverData ItemBatch + * @param $cacheSlamsSpendSeconds int + */ + $this->eventManager->dispatch('CacheGetItemInSlamBatch', $this, $driverData, $cacheSlamsSpendSeconds); + + /** + * Wait for a second before + * attempting to get exit + * the current batch process + */ + \sleep(1); + $cacheSlamsSpendSeconds++; + goto getItemDriverRead; + } + } + + $item->set($driverData); + $item->expiresAt($this->driverUnwrapEdate($driverArray)); + + if ($this->getConfig()->isItemDetailedDate()) { + /** + * If the itemDetailedDate has been + * set after caching, we MUST inject + * a new DateTime object on the fly + */ + $item->setCreationDate($this->driverUnwrapCdate($driverArray) ?: new \DateTime()); + $item->setModificationDate($this->driverUnwrapMdate($driverArray) ?: new \DateTime()); + } + + $item->setTags($this->driverUnwrapTags($driverArray)); + + getItemDriverExpired: + if ($item->isExpired()) { + /** + * Using driverDelete() instead of delete() + * to avoid infinite loop caused by + * getItem() call in delete() method + * As we MUST return an item in any + * way, we do not de-register here + */ + $this->driverDelete($item); + + /** + * Reset the Item + */ + $item->set(null) + ->expiresAfter(\abs((int)$this->getConfig()['defaultTtl'])) + ->setHit(false) + ->setTags([]); + if ($this->getConfig()->isItemDetailedDate()) { + + /** + * If the itemDetailedDate has been + * set after caching, we MUST inject + * a new DateTime object on the fly + */ + $item->setCreationDate(new \DateTime()); + $item->setModificationDate(new \DateTime()); + } + } else { + $item->setHit(true); + } + } else { + $item->expiresAfter(\abs((int)$this->getConfig()['defaultTtl'])); + } + } + } + } else { + throw new PhpfastcacheInvalidArgumentException(\sprintf('$key must be a string, got type "%s" instead.', \gettype($key))); + } + + /** + * @eventName CacheGetItem + * @param $this ExtendedCacheItemPoolInterface + * @param $this ExtendedCacheItemInterface + */ + $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[$key]); + + return $this->itemInstances[$key]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return $this + * @throws PhpfastcacheInvalidArgumentException + */ + public function setItem(CacheItemInterface $item) + { + if ($this->getClassNamespace() . '\\Item' === \get_class($item)) { + $this->itemInstances[$item->getKey()] = $item; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid Item Class "%s" for this driver.', \get_class($item))); + } + + /** + * @param array $keys + * @return CacheItemInterface[] + * @throws PhpfastcacheInvalidArgumentException + */ + public function getItems(array $keys = []) + { + $collection = []; + foreach ($keys as $key) { + $collection[$key] = $this->getItem($key); + } + + return $collection; + } + + /** + * @param string $key + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + public function hasItem($key) + { + return $this->getItem($key)->isHit(); + } + + /** + * @return bool + */ + public function clear() + { + /** + * @eventName CacheClearItem + * @param $this ExtendedCacheItemPoolInterface + * @param $itemInstances ExtendedCacheItemInterface[] + */ + $this->eventManager->dispatch('CacheClearItem', $this, $this->itemInstances); + + CacheManager::$WriteHits++; + // Faster than detachAllItems() + $this->itemInstances = []; + + return $this->driverClear(); + } + + /** + * @param string $key + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + public function deleteItem($key) + { + $item = $this->getItem($key); + if ($item->isHit() && $this->driverDelete($item)) { + $item->setHit(false); + CacheManager::$WriteHits++; + + /** + * @eventName CacheCommitItem + * @param $this ExtendedCacheItemPoolInterface + * @param $item ExtendedCacheItemInterface + */ + $this->eventManager->dispatch('CacheDeleteItem', $this, $item); + + /** + * De-register the item instance + * then collect gc cycles + */ + $this->deregisterItem($key); + + /** + * Perform a tag cleanup to avoid memory leaks + */ + if (\strpos($key, self::DRIVER_TAGS_KEY_PREFIX) !== 0) { + $this->cleanItemTags($item); + } + + return true; + } + + return false; + } + + /** + * @param array $keys + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + public function deleteItems(array $keys) + { + $return = null; + foreach ($keys as $key) { + $result = $this->deleteItem($key); + if ($result !== false) { + $return = $result; + } + } + + return (bool)$return; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + * @throws \RuntimeException + */ + public function save(CacheItemInterface $item) + { + /** + * @var ExtendedCacheItemInterface $item + * + * Replace array_key_exists by isset + * due to performance issue on huge + * loop dispatching operations + */ + if (!isset($this->itemInstances[$item->getKey()])) { + $this->itemInstances[$item->getKey()] = $item; + } else { + if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { + throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); + } + } + + /** + * @eventName CacheSaveItem + * @param $this ExtendedCacheItemPoolInterface + * @param $this ExtendedCacheItemInterface + */ + $this->eventManager->dispatch('CacheSaveItem', $this, $item); + + + if ($this->getConfig()->isPreventCacheSlams()) { + /** + * @var $itemBatch ExtendedCacheItemInterface + */ + $class = new \ReflectionClass((new \ReflectionObject($this))->getNamespaceName() . '\Item'); + $itemBatch = $class->newInstanceArgs([$this, $item->getKey()]); + $itemBatch->setEventManager($this->eventManager) + ->set(new ItemBatch($item->getKey(), new \DateTime())) + ->expiresAfter($this->getConfig()->getCacheSlamsTimeout()); + + /** + * To avoid SPL mismatches + * we have to re-attach the + * original item to the pool + */ + $this->driverWrite($itemBatch); + $this->detachItem($itemBatch); + $this->attachItem($item); + } + + + if ($this->driverWrite($item) && $this->driverWriteTags($item)) { + $item->setHit(true); + CacheManager::$WriteHits++; + + return true; + } + + return false; + } + + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return \Psr\Cache\CacheItemInterface + * @throws \RuntimeException + */ + public function saveDeferred(CacheItemInterface $item) + { + if (!\array_key_exists($item->getKey(), $this->itemInstances)) { + $this->itemInstances[$item->getKey()] = $item; + } else { + if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { + throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); + } + } + + /** + * @eventName CacheSaveDeferredItem + * @param $this ExtendedCacheItemPoolInterface + * @param $this ExtendedCacheItemInterface + */ + $this->eventManager->dispatch('CacheSaveDeferredItem', $this, $item); + + return $this->deferredList[$item->getKey()] = $item; + } + + /** + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + public function commit() + { + /** + * @eventName CacheCommitItem + * @param $this ExtendedCacheItemPoolInterface + * @param $deferredList ExtendedCacheItemInterface[] + */ + $this->eventManager->dispatch('CacheCommitItem', $this, $this->deferredList); + + $return = null; + foreach ($this->deferredList as $key => $item) { + $result = $this->save($item); + if ($return !== false) { + unset($this->deferredList[$key]); + $return = $result; + } + } + + return (bool) $return; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php new file mode 100644 index 0000000..53e3b91 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php @@ -0,0 +1,373 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool; + +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Exceptions\{PhpfastcacheDriverCheckException, PhpfastcacheDriverConnectException, PhpfastcacheLogicException}; + + +/** + * Class DriverBaseTrait + * @package phpFastCache\Cache + */ +trait DriverBaseTrait +{ + use ExtendedCacheItemPoolTrait; + + /** + * @var ConfigurationOption the options + */ + protected $config = []; + + /** + * @var bool + */ + protected $fallback = false; + + /** + * @var mixed Instance of driver service + */ + protected $instance; + + /** + * @var string + */ + protected $driverName; + + /** + * @internal This variable is read-access only + * @var string + */ + protected $instanceId; + + /** + * Driver constructor. + * @param ConfigurationOption $config + * @param string $instanceId + * @throws PhpfastcacheDriverCheckException + * @throws PhpfastcacheDriverConnectException + */ + public function __construct(ConfigurationOption $config, $instanceId) + { + $this->setConfig($config); + $this->instanceId = $instanceId; + + if (!$this->driverCheck()) { + throw new PhpfastcacheDriverCheckException(\sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName())); + } + + try{ + $this->driverConnect(); + }catch(\Exception $e){ + throw new PhpfastcacheDriverConnectException(\sprintf( + self::DRIVER_CONNECT_FAILURE, + $this->getDriverName(), + $e->getMessage(), + $e->getLine() ?: 'unknown line', + $e->getFile() ?: 'unknown file' + )); + } + } + + /** + * @param ConfigurationOption $config + */ + public function setConfig(ConfigurationOption $config) + { + $this->config = $config; + } + + /** + * @return ConfigurationOption + */ + public function getConfig(): ConfigurationOption + { + return $this->config; + } + + + /** + * @param $optionName + * @return mixed + * @deprecated Use getConfig()->getOptionName() instead + */ + public function getConfigOption($optionName) + { + \trigger_error(\sprintf('Method "%s" is deprecated, use "getConfig()->getOptionName()" instead', __METHOD__), \E_USER_DEPRECATED); + return $this->getConfig()->getOption($optionName); + } + + /** + * @return ConfigurationOption + */ + public function getDefaultConfig(): ConfigurationOption + { + $className = self::getConfigClass(); + return new $className; + } + + /** + * Encode data types such as object/array + * for driver that does not support + * non-scalar value + * @param $data + * @return string + */ + protected function encode($data): string + { + if (function_exists('igbinary_serialize')) { + return igbinary_serialize($data); + } else { + return \serialize($data); + } + //return \serialize($data); + } + + /** + * Decode data types such as object/array + * for driver that does not support + * non-scalar value + * @param string|null $value + * @return mixed + */ + protected function decode($value) + { + if (function_exists('igbinary_serialize')) { + return igbinary_unserialize($value); + } else { + return \unserialize($value); + } + //return \unserialize((string)$value); + } + + /** + * Check if phpModule or CGI + * @return bool + */ + protected function isPHPModule(): bool + { + return (\PHP_SAPI === 'apache2handler' || \strpos(\PHP_SAPI, 'handler') !== false); + } + + /** + * @param \Phpfastcache\Core\Item\ExtendedCacheItemInterface $item + * @return array + */ + public function driverPreWrap(ExtendedCacheItemInterface $item): array + { + $wrap = [ + self::DRIVER_DATA_WRAPPER_INDEX => $item->get(), + self::DRIVER_TAGS_WRAPPER_INDEX => $item->getTags(), + self::DRIVER_EDATE_WRAPPER_INDEX => $item->getExpirationDate(), + ]; + + if ($this->getConfig()->isItemDetailedDate()) { + $wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = new \DateTime(); + /** + * If the creation date exists + * reuse it else set a new Date + */ + $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate() ?: new \DateTime(); + } else { + $wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = null; + $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = null; + } + + return $wrap; + } + + /** + * @param array $wrapper + * @return mixed + */ + public function driverUnwrapData(array $wrapper) + { + return $wrapper[self::DRIVER_DATA_WRAPPER_INDEX]; + } + + /** + * @param array $wrapper + * @return mixed + */ + public function driverUnwrapTags(array $wrapper) + { + return $wrapper[self::DRIVER_TAGS_WRAPPER_INDEX]; + } + + + /** + * @param array $wrapper + * @return \DateTime + */ + public function driverUnwrapEdate(array $wrapper) + { + return $wrapper[self::DRIVER_EDATE_WRAPPER_INDEX]; + } + + /** + * @param array $wrapper + * @return \DateTime + */ + public function driverUnwrapCdate(array $wrapper) + { + return $wrapper[self::DRIVER_CDATE_WRAPPER_INDEX]; + } + + + /** + * @param array $wrapper + * @return \DateTime + */ + public function driverUnwrapMdate(array $wrapper) + { + return $wrapper[self::DRIVER_MDATE_WRAPPER_INDEX]; + } + + /** + * @return string + */ + public function getDriverName(): string + { + if (!$this->driverName) { + $this->driverName = \ucfirst(\substr(\strrchr((new \ReflectionObject($this))->getNamespaceName(), '\\'), 1)); + } + return $this->driverName; + } + + /** + * @return string + */ + public function getInstanceId(): string + { + return $this->instanceId; + } + + /** + * @param \Phpfastcache\Core\Item\ExtendedCacheItemInterface $item + * @return bool + * @throws PhpfastcacheLogicException + */ + public function driverWriteTags(ExtendedCacheItemInterface $item): bool + { + /** + * Do not attempt to write tags + * on tags item, it can leads + * to an infinite recursive calls + */ + if (\strpos($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX) === 0) { + throw new PhpfastcacheLogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey()); + } + + if (!$item->getTags() && !$item->getRemovedTags()) { + return true; + } + + /** + * @var $tagsItems ExtendedCacheItemInterface[] + */ + $tagsItems = $this->getItems($this->getTagKeys($item->getTags())); + + foreach ($tagsItems as $tagsItem) { + $data = $tagsItem->get(); + $expTimestamp = $item->getExpirationDate()->getTimestamp(); + + /** + * Using the key will + * avoid to use array_unique + * that has slow performances + */ + + $tagsItem->set(\array_merge((array)$data, [$item->getKey() => $expTimestamp])); + + /** + * Set the expiration date + * of the $tagsItem based + * on the older $item + * expiration date + */ + if ($expTimestamp > $tagsItem->getExpirationDate()->getTimestamp()) { + $tagsItem->expiresAt($item->getExpirationDate()); + } + $this->driverWrite($tagsItem); + $tagsItem->setHit(true); + } + + /** + * Also update removed tags to + * keep the index up to date + */ + $tagsItems = $this->getItems($this->getTagKeys($item->getRemovedTags())); + + foreach ($tagsItems as $tagsItem) { + $data = (array)$tagsItem->get(); + + unset($data[$item->getKey()]); + $tagsItem->set($data); + + /** + * Recalculate the expiration date + * + * If the $tagsItem does not have + * any cache item references left + * then remove it from tagsItems index + */ + if (\count($data)) { + $tagsItem->expiresAt((new \DateTime())->setTimestamp(\max($data))); + $this->driverWrite($tagsItem); + $tagsItem->setHit(true); + } else { + $this->deleteItem($tagsItem->getKey()); + } + } + + return true; + } + + /** + * @param $key + * @return string + */ + public function getTagKey($key):string + { + return self::DRIVER_TAGS_KEY_PREFIX . $key; + } + + /** + * @param array $keys + * @return array + */ + public function getTagKeys(array $keys): array + { + foreach ($keys as &$key) { + $key = $this->getTagKey($key); + } + + return $keys; + } + + /** + * @return string + */ + public static function getConfigClass(): string + { + $localConfigClass = \substr(static::class, 0, \strrpos(static::class, '\\')) . '\Config'; + if (\class_exists($localConfigClass) && \is_a($localConfigClass, ConfigurationOption::class, true)) { + return $localConfigClass; + } + return ConfigurationOption::class; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php new file mode 100644 index 0000000..128c8f0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php @@ -0,0 +1,550 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool; + +use InvalidArgumentException; +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\{ + CacheItemInterface, CacheItemPoolInterface +}; + + +/** + * Interface ExtendedCacheItemPoolInterface + * + * IMPORTANT NOTICE + * + * If you modify this file please make sure that + * the ActOnAll helper will also get those modifications + * since it does no longer implements this interface + * @see \Phpfastcache\Helper\ActOnAll + * + * @package phpFastCache\Core\Pool + */ +interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface +{ + const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue. + Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required.'; + + const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s'; + + const DRIVER_TAGS_KEY_PREFIX = '_TAG_'; + const DRIVER_TAGS_WRAPPER_INDEX = 'g'; + const DRIVER_DATA_WRAPPER_INDEX = 'd'; + + /** + * Expiration date Index + */ + const DRIVER_EDATE_WRAPPER_INDEX = 'e'; + + /** + * Creation date Index + */ + const DRIVER_CDATE_WRAPPER_INDEX = 'c'; + + /** + * Modification date Index + */ + const DRIVER_MDATE_WRAPPER_INDEX = 'm'; + + + /** + * @return ConfigurationOption + */ + public function getConfig(): ConfigurationOption; + + /** + * @return ConfigurationOption + */ + public function getDefaultConfig(): ConfigurationOption; + + /** + * @param string $optionName + * @return mixed + */ + public function getConfigOption($optionName); + + /** + * @return string + */ + public function getDriverName(): string; + + /** + * @return mixed + */ + public function getInstanceId(): string; + + /** + * [phpFastCache phpDoc Override] + * Returns a Cache Item representing the specified key. + * + * This method must always return a CacheItemInterface object, even in case of + * a cache miss. It MUST NOT return null. + * + * @param string $key + * The key for which to return the corresponding Cache Item. + * + * @throws PhpfastcacheInvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface + * The corresponding Cache Item. + */ + public function getItem($key); + + /** + * [phpFastCache phpDoc Override] + * Returns a traversable set of cache items. + * + * @param array $keys + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItems(array $keys = []); + + /** + * Returns A json string that represents an array of items. + * + * @param array $keys + * An indexed array of keys of items to retrieve. + * @param int $option \json_encode() options + * @param int $depth \json_encode() depth + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return string + */ + public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512): string; + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + */ + public function setItem(CacheItemInterface $item); + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic; + + + /** + * Get a quick help guide + * about the current driver + * + * @return string + */ + public function getHelp(): string; + + /** + * Returns a traversable set of cache items by a tag name. + * + * @param string $tagName + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItemsByTag($tagName): array; + + /** + * Returns a traversable set of cache items by one of multiple tag names. + * + * @param string[] $tagNames + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItemsByTags(array $tagNames): array; + + /** + * Returns a traversable set of cache items by all of multiple tag names. + * + * @param string[] $tagNames + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return ExtendedCacheItemInterface[] + * A traversable collection of Cache Items keyed by the cache keys of + * each item. A Cache item will be returned for each key, even if that + * key is not found. However, if no keys are specified then an empty + * traversable MUST be returned instead. + */ + public function getItemsByTagsAll(array $tagNames): array; + + /** + * Returns A json string that represents an array of items by tags-based. + * + * @param string[] $tagNames + * An indexed array of keys of items to retrieve. + * @param int $option \json_encode() options + * @param int $depth \json_encode() depth + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return string + */ + public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512): string; + + /** + * Removes the item from the pool by tag. + * + * @param string $tagName + * The tag for which to delete + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully removed. False if there was an error. + */ + public function deleteItemsByTag($tagName): bool; + + /** + * Removes the item from the pool by one of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to delete + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully removed. False if there was an error. + */ + public function deleteItemsByTags(array $tagNames): bool; + + /** + * Removes the item from the pool by all of multiple tag names. + * + * @param string[] $tagNames + * An indexed array of keys of items to retrieve. + * + * @throws InvalidArgumentException + * If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully removed. False if there was an error. + */ + public function deleteItemsByTagsAll(array $tagNames): bool; + + /** + * Increment the items from the pool by tag. + * + * @param string $tagName + * The tag for which to increment + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully incremented. False if there was an error. + */ + public function incrementItemsByTag($tagName, $step = 1): bool; + + /** + * Increment the items from the pool by one of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to increment + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully incremented. False if there was an error. + */ + public function incrementItemsByTags(array $tagNames, $step = 1): bool; + + /** + * Increment the items from the pool by all of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to increment + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully incremented. False if there was an error. + */ + public function incrementItemsByTagsAll(array $tagNames, $step = 1): bool; + + /** + * Decrement the items from the pool by tag. + * + * @param string $tagName + * The tag for which to decrement + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully decremented. False if there was an error. + */ + public function decrementItemsByTag($tagName, $step = 1): bool; + + /** + * Decrement the items from the pool by one of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to decrement + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully decremented. False if there was an error. + */ + public function decrementItemsByTags(array $tagNames, $step = 1): bool; + + /** + * Decrement the items from the pool by all of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to decrement + * + * @param int $step + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully decremented. False if there was an error. + */ + public function decrementItemsByTagsAll(array $tagNames, $step = 1): bool; + + /** + * Decrement the items from the pool by tag. + * + * @param string $tagName + * The tag for which to append + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully appended. False if there was an error. + */ + public function appendItemsByTag($tagName, $data): bool; + + /** + * Append the items from the pool by one of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to append + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully appended. False if there was an error. + */ + public function appendItemsByTags(array $tagNames, $data): bool; + + /** + * Append the items from the pool by all of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to append + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully appended. False if there was an error. + */ + public function appendItemsByTagsAll(array $tagNames, $data): bool; + + /** + * Prepend the items from the pool by tag. + * + * @param string $tagName + * The tag for which to prepend + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully prepended. False if there was an error. + */ + public function prependItemsByTag($tagName, $data): bool; + + /** + * Prepend the items from the pool by one of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to prepend + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the item was successfully prepended. False if there was an error. + */ + public function prependItemsByTags(array $tagNames, $data): bool; + + /** + * Prepend the items from the pool by all of multiple tag names. + * + * @param string[] $tagNames + * The tag for which to prepend + * + * @param array|string $data + * + * @throws InvalidArgumentException + * If the $key string is not a legal value a phpfastcacheInvalidArgumentException + * MUST be thrown. + * + * @return bool + * True if the items were successfully prepended. False if there was an error. + */ + public function prependItemsByTagsAll(array $tagNames, $data): bool; + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + */ + public function detachItem(CacheItemInterface $item); + + /** + * @return void + */ + public function detachAllItems(); + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + * @throws PhpfastcacheLogicException + */ + public function attachItem(CacheItemInterface $item); + + /** + * Returns true if the item exists, is attached and the Spl Hash matches + * Returns false if the item exists, is attached and the Spl Hash mismatches + * Returns null if the item does not exists + * + * @param \Psr\Cache\CacheItemInterface $item + * @return bool|null + * @throws PhpfastcacheLogicException + */ + public function isAttached(CacheItemInterface $item); + + + /** + * Set the EventManager instance + * + * @param EventInterface $em + * @return self + */ + public function setEventManager(EventInterface $em): self; + + /** + * Save multiple items, possible uses: + * saveMultiple([$item1, $item2, $item3]); + * saveMultiple($item1, $item2, $item3); + * + * @param ExtendedCacheItemInterface[] $items + * @return bool + */ + public function saveMultiple(...$items): bool; + + /** + * Defines if the driver is allowed + * to be used in "Auto" driver. + * + * @return bool + */ + public static function isUsableInAutoContext(): bool; + + /** + * Return the config class name + * @return string + */ + public static function getConfigClass(): string; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php new file mode 100644 index 0000000..8316487 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php @@ -0,0 +1,500 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool; + +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Trait ExtendedCacheItemPoolTrait + * @package Phpfastcache\Core\Pool + * @method bool driverWriteTags(ExtendedCacheItemInterface $item) Imported from DriverBaseTrait + */ +trait ExtendedCacheItemPoolTrait +{ + use CacheItemPoolTrait, AbstractDriverPoolTrait; + + /** + * @inheritdoc + */ + public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512): string + { + $callback = function (CacheItemInterface $item) { + return $item->get(); + }; + return \json_encode(\array_map($callback, \array_values($this->getItems($keys))), $option, $depth); + } + + /** + * @inheritdoc + */ + public function getItemsByTag($tagName): array + { + if (\is_string($tagName)) { + $driverResponse = $this->getItem($this->getTagKey($tagName)); + if ($driverResponse->isHit()) { + $items = (array)$driverResponse->get(); + + /** + * getItems() may provides expired item(s) + * themselves provided by a cache of item + * keys based stored the tag item. + * Therefore we pass a filter callback + * to remove the expired Item(s) provided by + * the item keys passed through getItems() + * + * #headache + */ + return \array_filter($this->getItems(\array_unique(\array_keys($items))), function (ExtendedCacheItemInterface $item) { + return $item->isHit(); + }); + } + return []; + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); + } + + /** + * @inheritdoc + */ + public function getItemsByTags(array $tagNames): array + { + $items = []; + foreach (\array_unique($tagNames) as $tagName) { + if (\is_string($tagName)) { + $items = \array_merge($items, $this->getItemsByTag($tagName)); + } else { + throw new PhpfastcacheInvalidArgumentException('$tagName must be a a string'); + } + } + + return $items; + } + + + /** + * @inheritdoc + */ + public function getItemsByTagsAll(array $tagNames): array + { + $items = $this->getItemsByTags($tagNames); + + foreach ($items as $key => $item) { + if (\array_diff($tagNames, $item->getTags())) { + unset($items[$key]); + } + } + + return $items; + } + + + /** + * @inheritdoc + */ + public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512): string + { + $callback = function (CacheItemInterface $item) { + return $item->get(); + }; + + return \json_encode(\array_map($callback, \array_values($this->getItemsByTags($tagNames))), $option, $depth); + } + + /** + * @inheritdoc + */ + public function deleteItemsByTag($tagName): bool + { + if (\is_string($tagName)) { + $return = null; + foreach ($this->getItemsByTag($tagName) as $item) { + $result = $this->deleteItem($item->getKey()); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); + } + + /** + * @inheritdoc + */ + public function deleteItemsByTags(array $tagNames): bool + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->deleteItemsByTag($tagName); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function deleteItemsByTagsAll(array $tagNames): bool + { + $return = null; + $items = $this->getItemsByTagsAll($tagNames); + + foreach ($items as $key => $item) { + $result = $this->deleteItem($item->getKey()); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function incrementItemsByTag($tagName, $step = 1): bool + { + if (\is_string($tagName) && \is_int($step)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->increment($step); + $this->saveDeferred($item); + } + + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string and $step an integer'); + } + + /** + * @inheritdoc + */ + public function incrementItemsByTags(array $tagNames, $step = 1): bool + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->incrementItemsByTag($tagName, $step); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function incrementItemsByTagsAll(array $tagNames, $step = 1): bool + { + if (\is_int($step)) { + $items = $this->getItemsByTagsAll($tagNames); + + foreach ($items as $key => $item) { + $item->increment($step); + $this->saveDeferred($item); + } + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$step must be an integer'); + } + + /** + * @inheritdoc + */ + public function decrementItemsByTag($tagName, $step = 1): bool + { + if (\is_string($tagName) && \is_int($step)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->decrement($step); + $this->saveDeferred($item); + } + + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string and $step an integer'); + } + + /** + * @inheritdoc + */ + public function decrementItemsByTags(array $tagNames, $step = 1): bool + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->decrementItemsByTag($tagName, $step); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function decrementItemsByTagsAll(array $tagNames, $step = 1): bool + { + if (\is_int($step)) { + $items = $this->getItemsByTagsAll($tagNames); + + foreach ($items as $key => $item) { + $item->decrement($step); + $this->saveDeferred($item); + } + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$step must be an integer'); + } + + /** + * @inheritdoc + */ + public function appendItemsByTag($tagName, $data): bool + { + if (\is_string($tagName)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->append($data); + $this->saveDeferred($item); + } + + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); + } + + /** + * @inheritdoc + */ + public function appendItemsByTags(array $tagNames, $data): bool + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->appendItemsByTag($tagName, $data); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function appendItemsByTagsAll(array $tagNames, $data): bool + { + if (is_scalar($data)) { + $items = $this->getItemsByTagsAll($tagNames); + + foreach ($items as $key => $item) { + $item->append($data); + $this->saveDeferred($item); + } + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$data must be scalar'); + } + + /** + * @inheritdoc + */ + public function prependItemsByTag($tagName, $data): bool + { + if (\is_string($tagName)) { + foreach ($this->getItemsByTag($tagName) as $item) { + $item->prepend($data); + $this->saveDeferred($item); + } + + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$tagName must be a string'); + } + + /** + * @inheritdoc + */ + public function prependItemsByTags(array $tagNames, $data): bool + { + $return = null; + foreach ($tagNames as $tagName) { + $result = $this->prependItemsByTag($tagName, $data); + if ($return !== false) { + $return = $result; + } + } + + return (bool) $return; + } + + /** + * @inheritdoc + */ + public function prependItemsByTagsAll(array $tagNames, $data): bool + { + if (\is_scalar($data)) { + $items = $this->getItemsByTagsAll($tagNames); + + foreach ($items as $key => $item) { + $item->prepend($data); + $this->saveDeferred($item); + } + return (bool) $this->commit(); + } + + throw new PhpfastcacheInvalidArgumentException('$data must be scalar'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return void + */ + public function detachItem(CacheItemInterface $item) + { + if (isset($this->itemInstances[$item->getKey()])) { + $this->deregisterItem($item->getKey()); + } + } + + /** + * @inheritdoc + */ + public function detachAllItems() + { + foreach ($this->itemInstances as $item) { + $this->detachItem($item); + } + } + + /** + * @inheritdoc + */ + public function attachItem(CacheItemInterface $item) + { + if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { + throw new PhpfastcacheLogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.'); + } + + $this->itemInstances[$item->getKey()] = $item; + } + + + /** + * @internal This method de-register an item from $this->itemInstances + * @param string $item + */ + protected function deregisterItem(string $item) + { + unset($this->itemInstances[$item]); + + if (\gc_enabled()) { + \gc_collect_cycles(); + } + } + + /** + * @param ExtendedCacheItemInterface $item + */ + protected function cleanItemTags(ExtendedCacheItemInterface $item) + { + $this->driverWriteTags($item->removeTags($item->getTags())); + } + + /** + * Returns true if the item exists, is attached and the Spl Hash matches + * Returns false if the item exists, is attached and the Spl Hash mismatches + * Returns null if the item does not exists + * + * @param \Psr\Cache\CacheItemInterface $item + * @return bool|null + */ + public function isAttached(CacheItemInterface $item) + { + if (isset($this->itemInstances[$item->getKey()])) { + return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]); + } + return null; + } + + /** + * Set the EventManager instance + * + * @param EventInterface $em + * @return ExtendedCacheItemPoolInterface + */ + public function setEventManager(EventInterface $em): ExtendedCacheItemPoolInterface + { + $this->eventManager = $em; + + return $this; + } + + /** + * @inheritdoc + */ + public function saveMultiple(...$items): bool + { + if (isset($items[0]) && \is_array($items[0])) { + foreach ($items[0] as $item) { + $this->save($item); + } + return true; + } + + if (\is_array($items)) { + foreach ($items as $item) { + $this->save($item); + } + return true; + } + return false; + } + + /** + * @inheritdoc + */ + public static function isUsableInAutoContext(): bool + { + return true; + } + + /** + * @return string + */ + public function getHelp(): string + { + return ''; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php new file mode 100644 index 0000000..ce92ec0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php @@ -0,0 +1,353 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Core\Pool\IO; + +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Files\Config; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\PhpfastcacheIOException; +use Phpfastcache\Util\Directory; + +/** + * Trait IOHelperTrait + * @package phpFastCache\Core\Pool\IO + * @property array $config The configuration array passed via DriverBaseTrait + * @property ExtendedCacheItemInterface[] $itemInstances The item instance passed via CacheItemPoolTrait + * @property EventInterface $eventManager The event manager passed via CacheItemPoolTrait + * @method Config getConfig() Return the config object + * @method bool isPHPModule() Return true if is a php module + * @method string getDriverName() Get the driver name + */ +trait IOHelperTrait +{ + /** + * @var array + */ + public $tmp = []; + + /** + * @param bool $readonly + * @return string + * @throws PhpfastcacheIOException + */ + public function getPath($readonly = false): string + { + /** + * Get the base system temporary directory + */ + $tmp_dir = \rtrim(\ini_get('upload_tmp_dir') ?: \sys_get_temp_dir(), '\\/') . \DIRECTORY_SEPARATOR . 'phpfastcache'; + + /** + * Calculate the security key + */ + { + $securityKey = $this->getConfig()->getSecurityKey(); + if (!$securityKey || \mb_strtolower($securityKey) === 'auto') { + if (isset($_SERVER['HTTP_HOST'])) { + $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $_SERVER['HTTP_HOST']))); + } else { + $securityKey = ($this->isPHPModule() ? 'web' : 'cli'); + } + } + + if ($securityKey !== '') { + $securityKey .= '/'; + } + + $securityKey = static::cleanFileName($securityKey); + } + + /** + * Extends the temporary directory + * with the security key and the driver name + */ + $tmp_dir = \rtrim($tmp_dir, '/') . \DIRECTORY_SEPARATOR; + + if (empty($this->getConfig()->getPath())) { + $path = $tmp_dir; + } else { + $path = rtrim($this->getConfig()->getPath(), '/') . \DIRECTORY_SEPARATOR; + } + + $path_suffix = $securityKey . \DIRECTORY_SEPARATOR . $this->getDriverName(); + $full_path = Directory::getAbsolutePath($path . $path_suffix); + $full_path_tmp = Directory::getAbsolutePath($tmp_dir . $path_suffix); + $full_path_hash = $this->getConfig()->getDefaultFileNameHashFunction()($full_path); + + /** + * In readonly mode we only attempt + * to verify if the directory exists + * or not, if it does not then we + * return the temp dir + */ + if ($readonly === true) { + if ($this->getConfig()->isAutoTmpFallback() && (!@\file_exists($full_path) || !@\is_writable($full_path))) { + return $full_path_tmp; + } + return $full_path; + } + + if (!isset($this->tmp[$full_path_hash]) || (!@\file_exists($full_path) || !@\is_writable($full_path))) { + if (!@\file_exists($full_path)) { + if (@mkdir($full_path, $this->getDefaultChmod(), true) === false && !\is_dir($full_path) ) { + throw new PhpfastcacheIOException('The directory '.$full_path.' could not be created.'); + } + } else { + if (!@\is_writable($full_path)) { + if (!@chmod($full_path, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) { + /** + * Switch back to tmp dir + * again if the path is not writable + */ + $full_path = $full_path_tmp; + if (!@\file_exists($full_path)) { + if(@mkdir($full_path, $this->getDefaultChmod(), true) && !\is_dir($full_path)){ + throw new PhpfastcacheIOException('The directory '.$full_path.' could not be created.'); + } + } + } + } + } + + /** + * In case there is no directory + * writable including the temporary + * one, we must throw an exception + */ + if (!@\file_exists($full_path) || !@\is_writable($full_path)) { + throw new PhpfastcacheIOException('Path "' . $full_path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'); + } + + $this->tmp[$full_path_hash] = $full_path; + $this->htaccessGen($full_path, $this->getConfig()->isValidOption('htaccess') ? $this->getConfig()->getHtaccess() : false); + } + + return realpath($full_path); + } + + + /** + * @param $keyword + * @param bool $skip + * @return string + * @throws PhpfastcacheIOException + */ + protected function getFilePath($keyword, $skip = false): string + { + $path = $this->getPath(); + + if ($keyword === false) { + return $path; + } + + $filename = $this->encodeFilename($keyword); + $folder = \substr($filename, 0, 2) . \DIRECTORY_SEPARATOR . \substr($filename, 2, 2); + $path = \rtrim($path, '/\\') . \DIRECTORY_SEPARATOR . $folder; + + /** + * Skip Create Sub Folders; + */ + if (!$skip && !\is_dir($path) && @!\mkdir($path, $this->getDefaultChmod(), true) && !\is_dir($path)) { + throw new PhpfastcacheIOException('Path "' . $path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'); + } + + return $path . '/' . $filename . '.' . $this->getConfig()->getCacheFileExtension(); + } + + + /** + * @param $keyword + * @return string + */ + protected function encodeFilename($keyword): string + { + return $this->getConfig()->getDefaultFileNameHashFunction()($keyword); + } + + /** + * @return int + */ + protected function getDefaultChmod(): int + { + if (!$this->getConfig()->getDefaultChmod()) { + return 0777; + } + + return $this->getConfig()->getDefaultChmod(); + } + + /** + * @param $filename + * @return string + */ + protected static function cleanFileName($filename): string + { + $regex = [ + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', + '/\.$/', + '/^\./', + ]; + $replace = ['-', '', '']; + + return \trim(\preg_replace($regex, $replace, \trim($filename)), '-'); + } + + /** + * @param $path + * @param bool $create + * @throws PhpfastcacheIOException + */ + protected function htaccessGen($path, $create = true) + { + if ($create === true) { + if (!\is_writable($path)) { + try { + if (!\chmod($path, 0777)) { + throw new PhpfastcacheIOException('Chmod failed on : ' . $path); + } + } catch (PhpfastcacheIOException $e) { + throw new PhpfastcacheIOException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!', 0, $e); + } + } + + if (!\file_exists($path . "/.htaccess")) { + $content = << +Require all denied + + +Order Allow,Deny +Deny from all + +HTACCESS; + + $file = @\fopen($path . '/.htaccess', 'w+b'); + if (!$file) { + throw new PhpfastcacheIOException('PLEASE CHMOD ' . $path . ' - 0777 OR ANY WRITABLE PERMISSION!'); + } + \fwrite($file, $content); + \fclose($file); + } + } + } + + + /** + * @param $file + * @return string + * @throws PhpfastcacheIOException + */ + protected function readfile($file): string + { + if (\function_exists('file_get_contents')) { + return \file_get_contents($file); + } + + $string = ''; + + $file_handle = @\fopen($file, 'rb'); + if (!$file_handle) { + throw new PhpfastcacheIOException("Cannot read file located at: {$file}"); + } + while (!\feof($file_handle)) { + $line = \fgets($file_handle); + $string .= $line; + } + \fclose($file_handle); + + return $string; + } + + /** + * @param string $file + * @param string $data + * @param bool $secureFileManipulation + * @return bool + * @throws PhpfastcacheIOException + */ + protected function writefile($file, $data, $secureFileManipulation = false): bool + { + /** + * @eventName CacheWriteFileOnDisk + * @param ExtendedCacheItemPoolInterface $this + * @param string $file + * @param bool $secureFileManipulation + * + */ + $this->eventManager->dispatch('CacheWriteFileOnDisk', $this, $file, $secureFileManipulation); + + if ($secureFileManipulation) { + $tmpFilename = Directory::getAbsolutePath(\dirname($file) . '/tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()( + \str_shuffle(\uniqid($this->getDriverName(), false)) + . \str_shuffle(\uniqid($this->getDriverName(), false)) + )); + + $f = \fopen($tmpFilename, 'w+b'); + if(\is_resource($f)){ + \flock($f, \LOCK_EX); + $octetWritten = fwrite($f, $data); + \flock($f, \LOCK_UN); + \fclose($f); + } + + if (!\rename($tmpFilename, $file)) { + throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file)); + } + } else { + $f = \fopen($file, 'w+b'); + if(\is_resource($f)){ + $octetWritten = \fwrite($f, $data); + \fclose($f); + } + } + + return (bool) ($octetWritten ?? false); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * Provide a generic getStats() method + * for files-based drivers + * @return DriverStatistic + * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $path = $this->getFilePath(false); + + if (!\is_dir($path)) { + throw new PhpfastcacheIOException("Can't read PATH:" . $path); + } + + $stat->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData([ + 'tmp' => $this->tmp, + ]) + ->setSize(Directory::dirSize($path)) + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Config.php new file mode 100644 index 0000000..30b9e7c --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apc; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Driver.php new file mode 100644 index 0000000..2c7edf9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Driver.php @@ -0,0 +1,144 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apc; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait { + DriverBaseTrait::__construct as private __parentConstruct; + } + + /** + * Driver constructor. + * @param Config $config + * @param string $instanceId + */ + public function __construct(Config $config, string $instanceId) + { + $this->__parentConstruct($config, $instanceId); + } + + /** + * @return bool + */ + public function driverCheck(): bool + { + return extension_loaded('apc') && ini_get('apc.enabled'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $data = apc_fetch($item->getKey(), $success); + if ($success === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + return (bool)apc_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)apc_delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return @apc_clear_cache() && @apc_clear_cache('user'); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stats = (array)apc_cache_info('user'); + $date = (new \DateTime())->setTimestamp($stats['start_time']); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("The APC cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(\DATE_RFC2822), + $stats['num_entries'])) + ->setRawData($stats) + ->setSize($stats['mem_size']); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Item.php new file mode 100644 index 0000000..803b49b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apc/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apc; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Apc\Driver as ApcDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Apc + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Apc\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(ApcDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ApcDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Config.php new file mode 100644 index 0000000..b333aea --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apcu; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Driver.php new file mode 100644 index 0000000..4a39d72 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Driver.php @@ -0,0 +1,132 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apcu; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('apcu') && ini_get('apc.enabled'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + return (bool)apcu_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $data = apcu_fetch($item->getKey(), $success); + if ($success === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)apcu_delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return @apcu_clear_cache(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stats = (array)apcu_cache_info(); + $date = (new \DateTime())->setTimestamp($stats['start_time']); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("The APCU cache is up since %s, and have %d item(s) in cache.\n For more information see RawData.", $date->format(\DATE_RFC2822), + $stats['num_entries'])) + ->setRawData($stats) + ->setSize((int)$stats['mem_size']); + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Item.php new file mode 100644 index 0000000..45baf16 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Apcu/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Apcu; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Apcu\Driver as ApcuDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Apcu + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Apcu\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(ApcuDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ApcuDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Config.php new file mode 100644 index 0000000..82253ca --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Config.php @@ -0,0 +1,177 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cassandra; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + /** + * @var int + */ + protected $port = 9042; + /** + * @var int + */ + protected $timeout = 2; + /** + * @var string + */ + protected $username = ''; + /** + * @var string + */ + protected $password = ''; + /** + * @var bool + */ + protected $sslEnabled = false; + /** + * @var bool + */ + protected $sslVerify = false; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return self + */ + public function setTimeout(int $timeout): self + { + $this->timeout = $timeout; + return $this; + } + + /** + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * @param string $username + * @return self + */ + public function setUsername(string $username): self + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @param string $password + * @return self + */ + public function setPassword(string $password): self + { + $this->password = $password; + return $this; + } + + /** + * @return bool + */ + public function isSslEnabled(): bool + { + return $this->sslEnabled; + } + + /** + * @param bool $sslEnabled + * @return self + */ + public function setSslEnabled(bool $sslEnabled): self + { + $this->sslEnabled = $sslEnabled; + return $this; + } + + /** + * @return bool + */ + public function isSslVerify(): bool + { + return $this->sslVerify; + } + + /** + * @param bool $sslVerify + * @return self + */ + public function setSslVerify(bool $sslVerify): self + { + $this->sslVerify = $sslVerify; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Driver.php new file mode 100644 index 0000000..bfa2057 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Driver.php @@ -0,0 +1,287 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cassandra; + +use Cassandra; +use Cassandra\Session as CassandraSession; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property CassandraSession $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + const CASSANDRA_KEY_SPACE = 'phpfastcache'; + const CASSANDRA_TABLE = 'cacheItems'; + + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('Cassandra') && \class_exists(\Cassandra::class); + } + + /** + * @return bool + * @throws PhpfastcacheLogicException + * @throws \Cassandra\Exception + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof CassandraSession) { + throw new PhpfastcacheLogicException('Already connected to Couchbase server'); + } + + $clientConfig = $this->getConfig(); + + $clusterBuilder = Cassandra::cluster() + ->withContactPoints($clientConfig->getHost()) + ->withPort($clientConfig->getPort()); + + if (!empty($clientConfig->isSslEnabled())) { + if (!empty($clientConfig->isSslVerify())) { + $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); + } else { + $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); + } + + $clusterBuilder->withSSL($sslBuilder->build()); + } + + $clusterBuilder->withConnectTimeout($clientConfig->getTimeout()); + + if ($clientConfig->getUsername()) { + $clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword()); + } + + $this->instance = $clusterBuilder->build()->connect(); + + /** + * In case of emergency: + * $this->instance->execute( + * new Cassandra\SimpleStatement(\sprintf("DROP KEYSPACE %s;", self::CASSANDRA_KEY_SPACE)) + * ); + */ + + $this->instance->execute(new Cassandra\SimpleStatement(\sprintf( + "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", + self::CASSANDRA_KEY_SPACE + ))); + $this->instance->execute(new Cassandra\SimpleStatement(\sprintf('USE %s;', self::CASSANDRA_KEY_SPACE))); + $this->instance->execute(new Cassandra\SimpleStatement(\sprintf(' + CREATE TABLE IF NOT EXISTS %s ( + cache_uuid uuid, + cache_id varchar, + cache_data text, + cache_creation_date timestamp, + cache_expiration_date timestamp, + cache_length int, + PRIMARY KEY (cache_id) + );', self::CASSANDRA_TABLE + ))); + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + try { + $options = new Cassandra\ExecutionOptions([ + 'arguments' => ['cache_id' => $item->getKey()], + 'page_size' => 1, + ]); + $query = \sprintf( + 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', + self::CASSANDRA_KEY_SPACE, + self::CASSANDRA_TABLE + ); + $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); + + if ($results instanceof Cassandra\Rows && $results->count() === 1) { + return $this->decode($results->first()['cache_data']); + } + + return null; + } catch (Cassandra\Exception $e) { + return null; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $cacheData = $this->encode($this->driverPreWrap($item)); + $options = new Cassandra\ExecutionOptions([ + 'arguments' => [ + 'cache_uuid' => new Cassandra\Uuid(), + 'cache_id' => $item->getKey(), + 'cache_data' => $cacheData, + 'cache_creation_date' => new Cassandra\Timestamp((new \DateTime())->getTimestamp()), + 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()), + 'cache_length' => strlen($cacheData), + ], + 'consistency' => Cassandra::CONSISTENCY_ALL, + 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL, + ]); + + $query = \sprintf('INSERT INTO %s.%s + ( + cache_uuid, + cache_id, + cache_data, + cache_creation_date, + cache_expiration_date, + cache_length + ) + VALUES (:cache_uuid, :cache_id, :cache_data, :cache_creation_date, :cache_expiration_date, :cache_length); + ', self::CASSANDRA_KEY_SPACE, self::CASSANDRA_TABLE); + + $result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); + /** + * There's no real way atm + * to know if the item has + * been really upserted + */ + return $result instanceof Cassandra\Rows; + } catch (\Cassandra\Exception\InvalidArgumentException $e) { + throw new PhpfastcacheInvalidArgumentException($e, 0, $e); + } + } else { + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $options = new Cassandra\ExecutionOptions([ + 'arguments' => [ + 'cache_id' => $item->getKey(), + ], + ]); + $result = $this->instance->execute(new Cassandra\SimpleStatement(\sprintf( + 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', + self::CASSANDRA_KEY_SPACE, + self::CASSANDRA_TABLE + )), $options); + + /** + * There's no real way atm + * to know if the item has + * been really deleted + */ + return $result instanceof Cassandra\Rows; + } catch (Cassandra\Exception $e) { + return false; + } + } else { + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + try { + $this->instance->execute(new Cassandra\SimpleStatement(\sprintf( + 'TRUNCATE %s.%s;', + self::CASSANDRA_KEY_SPACE, self::CASSANDRA_TABLE + ))); + + return true; + } catch (Cassandra\Exception $e) { + return false; + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return string + */ + public function getHelp(): string + { + return << +To install the php Cassandra extension via Pecl: +sudo pecl install cassandra +More information on: https://github.com/datastax/php-driver +Please not that this repository only provide php stubs and C/C++ sources, it does NOT provide php client. +

+HELP; + } + + /** + * @return DriverStatistic + * @throws \Cassandra\Exception + */ + public function getStats(): DriverStatistic + { + $result = $this->instance->execute(new Cassandra\SimpleStatement(\sprintf( + 'SELECT SUM(cache_length) as cache_size FROM %s.%s', + self::CASSANDRA_KEY_SPACE, + self::CASSANDRA_TABLE + ))); + + return (new DriverStatistic()) + ->setSize($result->first()['cache_size']) + ->setRawData([]) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Item.php new file mode 100644 index 0000000..226a434 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cassandra/Item.php @@ -0,0 +1,62 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cassandra; + +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Item\ItemBaseTrait; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Cassandra\Driver as CassandraDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Cassandra + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Cassandra\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(CassandraDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CassandraDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Config.php new file mode 100644 index 0000000..de4099c --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Config.php @@ -0,0 +1,23 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cookie; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Driver.php new file mode 100644 index 0000000..bf2d10b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Driver.php @@ -0,0 +1,191 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cookie; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + const PREFIX = 'PFC_'; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \function_exists('setcookie'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return !(!\array_key_exists('phpFastCache', $_COOKIE) && !@setcookie('phpFastCache', 1, 10)); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverException + */ + protected function driverRead(CacheItemInterface $item) + { + $this->driverConnect(); + $keyword = self::PREFIX . $item->getKey(); + $x = isset($_COOKIE[$keyword]) ? \json_decode($_COOKIE[$keyword], true) : false; + + if ($x == false) { + return null; + } + + if (!is_scalar($this->driverUnwrapData($x)) && !is_null($this->driverUnwrapData($x))) { + throw new PhpfastcacheDriverException('Hacking attempt: The decoding returned a non-scalar value, Cookie driver does not allow this.'); + } + + return $x; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->driverConnect(); + $keyword = self::PREFIX . $item->getKey(); + $v = \json_encode($this->driverPreWrap($item)); + + if ($this->getConfig()->getLimitedMemoryByObject() !== null && \strlen($v) > $this->getConfig()->getLimitedMemoryByObject()) { + return false; + } + + return setcookie($keyword, $v, $item->getExpirationDate()->getTimestamp(), '/'); + } + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param string $key + * @return int + */ + protected function driverReadExpirationDate($key): int + { + $this->driverConnect(); + $keyword = self::PREFIX . $key; + $x = isset($_COOKIE[$keyword]) ? $this->decode(\json_decode($_COOKIE[$keyword])->t) : 0; + + return $x ? $x - \time() : $x; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->driverConnect(); + $keyword = self::PREFIX . $item->getKey(); + $_COOKIE[$keyword] = null; + + return @setcookie($keyword, null, -10); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + $return = null; + $this->driverConnect(); + foreach ($_COOKIE as $keyword => $value) { + if (\strpos($keyword, self::PREFIX) !== false) { + $_COOKIE[$keyword] = null; + $result = @setcookie($keyword, null, -10); + if ($return !== false) { + $return = $result; + } + } + } + + return $return; + } + + /** + * @inheritdoc + */ + public static function isUsableInAutoContext(): bool + { + return false; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $size = 0; + $stat = new DriverStatistic(); + $stat->setData($_COOKIE); + + /** + * Only count PFC Cookie + */ + foreach ($_COOKIE as $key => $value) { + if (\strpos($key, self::PREFIX) === 0) { + $size += \strlen($value); + } + } + + $stat->setSize($size); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Item.php new file mode 100644 index 0000000..27aa148 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Cookie/Item.php @@ -0,0 +1,64 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Cookie; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Cookie\Driver as CookieDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Cookie + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Cookie\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(CookieDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CookieDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Config.php new file mode 100644 index 0000000..d70cfd2 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Config.php @@ -0,0 +1,137 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchbase; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 8091;// SSL: 18091 + + /** + * @var string + */ + protected $username = ''; + + /** + * @var string + */ + protected $password = ''; + + /** + * @var string + */ + protected $bucketName = 'default'; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return Config + */ + public function setHost(string $host): Config + { + $this->host = $host; + return $this; + } + + /** + * @return int|null + */ + public function getPort() + { + return $this->port; + } + + /** + * @param int $port + * @return Config + */ + public function setPort(int $port = null): Config + { + $this->port = $port; + return $this; + } + + /** + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * @param string $username + * @return Config + */ + public function setUsername(string $username): Config + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @param string $password + * @return Config + */ + public function setPassword(string $password): Config + { + $this->password = $password; + return $this; + } + + /** + * @return string + */ + public function getBucketName(): string + { + return $this->bucketName; + } + + /** + * @param string $bucketName + * @return Config + */ + public function setBucketName(string $bucketName): Config + { + $this->bucketName = $bucketName; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Driver.php new file mode 100644 index 0000000..9652854 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Driver.php @@ -0,0 +1,195 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchbase; + +use CouchbaseCluster as CouchbaseClient; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property CouchbaseClient $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @var \CouchbaseBucket[] + */ + protected $bucketInstances = []; + + /** + * @var \CouchbaseBucket + */ + protected $bucketInstance; + + /** + * @var string + */ + protected $currentBucket = ''; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('couchbase'); + } + + /** + * @return bool + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof CouchbaseClient) { + throw new PhpfastcacheLogicException('Already connected to Couchbase server'); + } + + $clientConfig = $this->getConfig(); + + + $authenticator = new \Couchbase\PasswordAuthenticator(); + $authenticator->username($clientConfig->getUsername())->password($clientConfig->getPassword()); + + $this->instance = new CouchbaseClient( + 'couchbase://' . $clientConfig->getHost() . ($clientConfig->getPort() ? ":{$clientConfig->getPort()}" : '') + ); + + $this->instance->authenticate($authenticator); + $this->setBucket($this->instance->openBucket($clientConfig->getBucketName())); + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + try { + /** + * CouchbaseBucket::get() returns a CouchbaseMetaDoc object + */ + return $this->decode($this->getBucket()->get($item->getEncodedKey())->value); + } catch (\CouchbaseException $e) { + return null; + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + return (bool)$this->getBucket()->upsert( + $item->getEncodedKey(), + $this->encode($this->driverPreWrap($item)), + ['expiry' => $item->getTtl()] + ); + } catch (\CouchbaseException $e) { + return false; + } + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + return (bool)$this->getBucket()->remove($item->getEncodedKey()); + } catch (\Couchbase\Exception $e) { + return $e->getCode() === COUCHBASE_KEY_ENOENT; + } + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + $this->getBucket()->manager()->flush(); + return true; + } + + /** + * @return \CouchbaseBucket + */ + protected function getBucket(): \CouchbaseBucket + { + return $this->bucketInstance; + } + + /** + * @param \CouchbaseBucket $CouchbaseBucket + */ + protected function setBucket(\CouchbaseBucket $CouchbaseBucket) + { + $this->bucketInstance = $CouchbaseBucket; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $info = $this->getBucket()->manager()->info(); + + return (new DriverStatistic()) + ->setSize($info['basicStats']['diskUsed']) + ->setRawData($info) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo('CouchBase version ' . $info['nodes'][0]['version'] . ', Uptime (in days): ' . round($info['nodes'][0]['uptime'] / 86400, + 1) . "\n For more information see RawData."); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Item.php new file mode 100644 index 0000000..40f51b3 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchbase/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchbase; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Couchbase\Driver as CouchbaseDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Couchbase + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Couchbase\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(CouchbaseDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CouchbaseDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Config.php new file mode 100644 index 0000000..07f2bfb --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Config.php @@ -0,0 +1,184 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchdb; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + /** + * @var int + */ + protected $port = 5984; + + /** + * @var string + */ + protected $path = '/'; + + /** + * @var string + */ + protected $username = ''; + /** + * @var string + */ + protected $password = ''; + /** + * @var bool + */ + protected $ssl = false; + /** + * @var int + */ + protected $timeout = 10; + + /** + * @var string + */ + protected $database = Driver::COUCHDB_DEFAULT_DB_NAME; + + /** + * @return string + */ + public function getDatabase(): string + { + return $this->database; + } + + /** + * @param string $database + * @return Config + */ + public function setDatabase(string $database): Config + { + $this->database = $database; + return $this; + } + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * @param string $username + * @return self + */ + public function setUsername(string $username): self + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @param string $password + * @return self + */ + public function setPassword(string $password): self + { + $this->password = $password; + return $this; + } + + /** + * @return bool + */ + public function isSsl(): bool + { + return $this->ssl; + } + + /** + * @param bool $ssl + * @return self + */ + public function setSsl(bool $ssl): self + { + $this->ssl = $ssl; + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return self + */ + public function setTimeout(int $timeout): self + { + $this->timeout = $timeout; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Driver.php new file mode 100644 index 0000000..9c731c0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Driver.php @@ -0,0 +1,244 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchdb; + +use Doctrine\CouchDB\{ + CouchDBClient, CouchDBException +}; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property CouchdbClient $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + const COUCHDB_DEFAULT_DB_NAME = 'phpfastcache'; + + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \class_exists(CouchDBClient::class); + } + + /** + * @return bool + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof CouchDBClient) { + throw new PhpfastcacheLogicException('Already connected to Couchdb server'); + } + + $clientConfig = $this->getConfig(); + + $url = ($clientConfig->isSsl() ? 'https://' : 'http://'); + if ($clientConfig->getUsername()) { + $url .= $clientConfig->getUsername(); + if ($clientConfig->getPassword()) { + $url .= ":{$clientConfig->getPassword()}"; + } + $url .= '@'; + } + $url .= $clientConfig->getHost(); + $url .= ":{$clientConfig->getPort()}"; + $url .= $clientConfig->getPath(); + + $this->instance = CouchDBClient::create([ + 'dbname' => $this->getDatabaseName(), + 'url' => $url, + 'timeout' => $clientConfig->getTimeout(), + ]); + + $this->createDatabase(); + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + * @throws PhpfastcacheDriverException + */ + protected function driverRead(CacheItemInterface $item) + { + try { + $response = $this->instance->findDocument($item->getEncodedKey()); + } catch (CouchDBException $e) { + throw new PhpfastcacheDriverException('Got error while trying to get a document: ' . $e->getMessage(), null, $e); + } + + if ($response->status === 404 || empty($response->body['data'])) { + return null; + } + + if ($response->status === 200) { + return $this->decode($response->body['data']); + } + + throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status); + } + + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheDriverException + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $this->instance->putDocument(['data' => $this->encode($this->driverPreWrap($item))], $item->getEncodedKey(), + $this->getLatestDocumentRevision($item->getEncodedKey())); + } catch (CouchDBException $e) { + throw new PhpfastcacheDriverException('Got error while trying to upsert a document: ' . $e->getMessage(), null, $e); + } + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheDriverException + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $this->instance->deleteDocument($item->getEncodedKey(), $this->getLatestDocumentRevision($item->getEncodedKey())); + } catch (CouchDBException $e) { + throw new PhpfastcacheDriverException('Got error while trying to delete a document: ' . $e->getMessage(), null, $e); + } + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + * @throws PhpfastcacheDriverException + */ + protected function driverClear(): bool + { + try { + $this->instance->deleteDatabase($this->getDatabaseName()); + $this->createDatabase(); + } catch (CouchDBException $e) { + throw new PhpfastcacheDriverException('Got error while trying to delete and recreate the database: ' . $e->getMessage(), null, $e); + } + + return true; + } + + /** + * @return string|null + */ + protected function getLatestDocumentRevision($docId) + { + $path = '/' . $this->getDatabaseName() . '/' . urlencode($docId); + + $response = $this->instance->getHttpClient()->request( + 'HEAD', + $path, + null, + false + ); + if (!empty($response->headers['etag'])) { + return \trim($response->headers['etag'], " '\"\t\n\r\0\x0B"); + } + + return null; + } + + /** + * @return string + */ + protected function getDatabaseName(): string + { + return $this->getConfig()->getDatabase() ?: self::COUCHDB_DEFAULT_DB_NAME; + } + + /** + * @return void + */ + protected function createDatabase() + { + if (!\in_array($this->instance->getDatabase(), $this->instance->getAllDatabases(), true)) { + $this->instance->createDatabase($this->instance->getDatabase()); + } + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return string + */ + public function getHelp(): string + { + return << +To install the Couchdb HTTP client library via Composer: +composer require "doctrine/couchdb" "@dev" +

+HELP; + } + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $info = $this->instance->getDatabaseInfo(); + + return (new DriverStatistic()) + ->setSize($info['sizes']['active']) + ->setRawData($info) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo('Couchdb version ' . $this->instance->getVersion() . "\n For more information see RawData."); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Item.php new file mode 100644 index 0000000..9d64f6c --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Couchdb/Item.php @@ -0,0 +1,62 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Couchdb; + +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Item\ItemBaseTrait; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Couchdb\Driver as CouchdbDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Couchdb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Couchdb\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(CouchdbDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof CouchdbDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Config.php new file mode 100644 index 0000000..05b0e13 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devfalse; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Driver.php new file mode 100644 index 0000000..e941453 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Driver.php @@ -0,0 +1,135 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devfalse; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + protected function driverRead(CacheItemInterface $item): array + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => false, + self::DRIVER_TAGS_WRAPPER_INDEX => [], + self::DRIVER_EDATE_WRAPPER_INDEX => new \DateTime(), + ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return true; + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @inheritdoc + */ + public static function isUsableInAutoContext(): bool + { + return false; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $stat->setInfo('[Devfalse] A void info string') + ->setSize(0) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData(false); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Item.php new file mode 100644 index 0000000..d9c18b8 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devfalse/Item.php @@ -0,0 +1,62 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devfalse; + +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Item\ItemBaseTrait; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Devfalse\Driver as DevfalseDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Devfalse + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Devfalse\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(DevfalseDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevfalseDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Config.php new file mode 100644 index 0000000..be5fab9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devnull; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Driver.php new file mode 100644 index 0000000..28856ac --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Driver.php @@ -0,0 +1,131 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devnull; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null + */ + protected function driverRead(CacheItemInterface $item) + { + return null; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return true; + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @inheritdoc + */ + public static function isUsableInAutoContext(): bool + { + return false; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $stat->setInfo('[Devnull] A void info string') + ->setSize(0) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData(null); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Item.php new file mode 100644 index 0000000..2c2590f --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devnull/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devnull; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Devnull\Driver as DevnullDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Devnull + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Devnull\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(DevnullDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevnullDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Config.php new file mode 100644 index 0000000..fc59c1f --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devtrue; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Driver.php new file mode 100644 index 0000000..8eb5b6a --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Driver.php @@ -0,0 +1,135 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devtrue; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return false; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + protected function driverRead(CacheItemInterface $item): array + { + return [ + self::DRIVER_DATA_WRAPPER_INDEX => true, + self::DRIVER_TAGS_WRAPPER_INDEX => [], + self::DRIVER_EDATE_WRAPPER_INDEX => new \DateTime(), + ]; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return false; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return false; + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return false; + } + + /** + * @inheritdoc + */ + public static function isUsableInAutoContext(): bool + { + return false; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $stat->setInfo('[Devtrue] A void info string') + ->setSize(0) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData(true); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Item.php new file mode 100644 index 0000000..d4130a0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Devtrue/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Devtrue; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Devtrue\Driver as DevtrueDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Devtrue + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Devtrue\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(DevtrueDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof DevtrueDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Config.php new file mode 100644 index 0000000..52fee20 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Config.php @@ -0,0 +1,26 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Files; + +use Phpfastcache\Config\{ + ConfigurationOption, IOConfigurationOptionTrait +}; + +class Config extends ConfigurationOption +{ + use IOConfigurationOptionTrait; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php new file mode 100644 index 0000000..5ff8a86 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Driver.php @@ -0,0 +1,151 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Files; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface, IO\IOHelperTrait +}; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Phpfastcache\Util\Directory; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use IOHelperTrait; + use DriverBaseTrait { + DriverBaseTrait::__construct as private __parentConstruct; + } + /** + * + */ + const FILE_DIR = 'files'; + + /** + * Driver constructor. + * @param Config $config + * @param string $instanceId + */ + public function __construct(Config $config, string $instanceId) + { + $this->__parentConstruct($config, $instanceId); + } + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \is_writable($this->getPath()) || @\mkdir($this->getPath(), $this->getDefaultChmod(), true); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + /** + * Check for Cross-Driver type confusion + */ + $file_path = $this->getFilePath($item->getKey(), true); + if (!\file_exists($file_path)) { + return null; + } + + $content = $this->readfile($file_path); + + return $this->decode($content); + + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $file_path = $this->getFilePath($item->getKey()); + $data = $this->encode($this->driverPreWrap($item)); + + /** + * Force write + */ + try { + return $this->writefile($file_path, $data, $this->getConfig()->isSecureFileManipulation()); + } catch (\Exception $e) { + return false; + } + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $file_path = $this->getFilePath($item->getKey(), true); + if (\file_exists($file_path) && @\unlink($file_path)) { + \clearstatcache(true, $file_path); + $dir = \dirname($file_path); + if (!(new \FilesystemIterator($dir))->valid()) { + \rmdir($dir); + } + return true; + } + + return false; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return Directory::rrmdir($this->getPath(true)); + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Item.php new file mode 100644 index 0000000..cf397f4 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Files/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Files; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Files\Driver as FilesDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Files + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Files\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(FilesDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof FilesDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Config.php new file mode 100644 index 0000000..58d2074 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Config.php @@ -0,0 +1,45 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Leveldb; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $htaccess = true; + + /** + * @return string + */ + public function getHtaccess(): string + { + return $this->htaccess; + } + + /** + * @param string $htaccess + * @return self + */ + public function setHtaccess(string $htaccess): self + { + $this->htaccess = $htaccess; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Driver.php new file mode 100644 index 0000000..5ca8d81 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Driver.php @@ -0,0 +1,146 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Leveldb; + +use LevelDB as LeveldbClient; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface, IO\IOHelperTrait +}; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property LeveldbClient $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait, IOHelperTrait; + + const LEVELDB_FILENAME = '.database'; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('Leveldb'); + } + + /** + * @return bool + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof LeveldbClient) { + throw new PhpfastcacheLogicException('Already connected to Leveldb database'); + } + + $this->instance = $this->instance ?: new LeveldbClient($this->getLeveldbFile()); + + return true; + } + + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } + + return $this->decode($val); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)$this->instance->set($item->getKey(), $this->encode($this->driverPreWrap($item))); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + if ($this->instance instanceof LeveldbClient) { + $this->instance->close(); + $this->instance = null; + } + $result = (bool)LeveldbClient::destroy($this->getLeveldbFile()); + $this->driverConnect(); + + return $result; + } + + /** + * @return string + * @throws \Phpfastcache\Exceptions\PhpfastcacheCoreException + */ + public function getLeveldbFile(): string + { + return $this->getPath() . '/' . self::LEVELDB_FILENAME; + } + + /** + * Close connection on destruct + */ + public function __destruct() + { + if ($this->instance instanceof LeveldbClient) { + $this->instance->close(); + $this->instance = null; + } + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Item.php new file mode 100644 index 0000000..8d5d0d3 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Leveldb/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Leveldb; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Leveldb\Driver as LeveldbDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Leveldb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Leveldb\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(LeveldbDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof LeveldbDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Config.php new file mode 100644 index 0000000..cfcad6a --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Config.php @@ -0,0 +1,163 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcache; + +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; + +class Config extends ConfigurationOption +{ + /** + * @var array + * + * Multiple server can be added this way: + * $cfg->setServers([ + * [ + * 'host' => '127.0.0.1', + * 'port' => 11211, + * 'saslUser' => false, + * 'saslPassword' => false, + * ] + * ]); + */ + protected $servers = []; + + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 11211; + + /** + * @var string + */ + protected $saslUser = ''; + + /** + * @var string + */ + protected $saslPassword = ''; + + /** + * @return bool + */ + public function getSaslUser(): string + { + return $this->saslUser; + } + + /** + * @param string $saslUser + * @return self + */ + public function setSaslUser(string $saslUser): self + { + $this->saslUser = $saslUser; + return $this; + } + + /** + * @return string + */ + public function getSaslPassword(): string + { + return $this->saslPassword; + } + + /** + * @param string $saslPassword + * @return self + */ + public function setSaslPassword(string $saslPassword): self + { + $this->saslPassword = $saslPassword; + return $this; + } + + /** + * @return array + */ + public function getServers(): array + { + return $this->servers; + } + + /** + * @param array $servers + * @throws PhpfastcacheInvalidConfigurationException + * @return self + */ + public function setServers(array $servers): self + { + foreach ($servers as $server) { + if($diff = \array_diff(['host', 'port', 'saslUser', 'saslPassword'], \array_keys($server))){ + throw new PhpfastcacheInvalidConfigurationException('Missing keys for memcached server: '. \implode(', ', $diff)); + } + if($diff = \array_diff( \array_keys($server), ['host', 'port', 'saslUser', 'saslPassword'])){ + throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: '. \implode(', ', $diff)); + } + if(!\is_string($server['host'])){ + throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array'); + } + if(!\is_int($server['port'])){ + throw new PhpfastcacheInvalidConfigurationException('Port must be a valid integer in "$server" configuration array'); + } + } + $this->servers = $servers; + return $this; + } + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Driver.php new file mode 100644 index 0000000..ff018a1 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Driver.php @@ -0,0 +1,212 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcache; + +use Memcache as MemcacheSoftware; +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException +}; +use Phpfastcache\Util\{ + MemcacheDriverCollisionDetectorTrait +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property MemcacheSoftware $instance + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait { + __construct as protected __parentConstruct; + } + use MemcacheDriverCollisionDetectorTrait; + + /** + * @var int + */ + protected $memcacheFlags = 0; + + /** + * Driver constructor. + * @param ConfigurationOption $config + * @param string $instanceId + * @throws PhpfastcacheDriverException + */ + public function __construct(ConfigurationOption $config, string $instanceId) + { + self::checkCollision('Memcache'); + $this->__parentConstruct($config, $instanceId); + } + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \class_exists('Memcache'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + $this->instance = new MemcacheSoftware(); + $servers = $this->getConfig()->getServers(); + + if (\count($servers) < 1) { + $servers = [ + [ + 'host' => $this->getConfig()->getHost(), + 'path' => $this->getConfig()->getPath(), + 'port' => $this->getConfig()->getPort(), + 'saslUser' => $this->getConfig()->getSaslUser() ?: false, + 'saslPassword' => $this->getConfig()->getSaslPassword() ?: false, + ], + ]; + } + + foreach ($servers as $server) { + try { + /** + * If path is provided we consider it as an UNIX Socket + */ + if (!empty($server['path']) && !$this->instance->addServer($server['path'], 0)) { + $this->fallback = true; + } else { + if (!empty($server['host']) && !$this->instance->addServer($server['host'], $server['port'])) { + $this->fallback = true; + } + } + + if (!empty($server['saslUser']) && !empty($server['saslPassword'])) { + throw new PhpfastcacheDriverException('Unlike Memcached, Memcache does not support SASL authentication'); + } + } catch (\Exception $e) { + $this->fallback = true; + } + + /** + * Since Memcached does not throw + * any error if not connected ... + */ + if (!$this->instance->getServerStatus(!empty($server['path']) ? $server['path'] : $server['host'], + !empty($server['port']) ? $server['port'] : 0)) { + throw new PhpfastcacheDriverException('Memcache seems to not be connected'); + } + } + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + + if ($val === false) { + return null; + } + + return $val; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + // Memcache will only allow a expiration timer less than 2592000 seconds, + // otherwise, it will assume you're giving it a UNIX timestamp. + if ($ttl > 2592000) { + $ttl = \time() + $ttl; + } + return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $this->memcacheFlags, $ttl); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->instance->flush(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stats = (array)$this->instance->getstats(); + $stats['uptime'] = (isset($stats['uptime']) ? $stats['uptime'] : 0); + $stats['version'] = (isset($stats['version']) ? $stats['version'] : 'UnknownVersion'); + $stats['bytes'] = (isset($stats['bytes']) ? $stats['version'] : 0); + + $date = (new \DateTime())->setTimestamp(\time() - $stats['uptime']); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats['version'], $date->format(\DATE_RFC2822))) + ->setRawData($stats) + ->setSize((int)$stats['bytes']); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Item.php new file mode 100644 index 0000000..bdfe317 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcache/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcache; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Memcache\Driver as MemcacheDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Memcache + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Memcache\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(MemcacheDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MemcacheDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php new file mode 100644 index 0000000..c1bee5f --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Config.php @@ -0,0 +1,163 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcached; + +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException; + +class Config extends ConfigurationOption +{ + /** + * @var array + * + * Multiple server can be added this way: + * $cfg->setServers([ + * [ + * 'host' => '127.0.0.1', + * 'port' => 11211, + * 'saslUser' => false, + * 'saslPassword' => false, + * ] + * ]); + */ + protected $servers = []; + + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 11211; + + /** + * @var string + */ + protected $saslUser = ''; + + /** + * @var string + */ + protected $saslPassword = ''; + + /** + * @return string + */ + public function getSaslUser(): string + { + return $this->saslUser; + } + + /** + * @param string $saslUser + * @return self + */ + public function setSaslUser(string $saslUser): self + { + $this->saslUser = $saslUser; + return $this; + } + + /** + * @return string + */ + public function getSaslPassword(): string + { + return $this->saslPassword; + } + + /** + * @param string $saslPassword + * @return self + */ + public function setSaslPassword(string $saslPassword): self + { + $this->saslPassword = $saslPassword; + return $this; + } + + /** + * @return array + */ + public function getServers(): array + { + return $this->servers; + } + + /** + * @param array $servers + * @throws PhpfastcacheInvalidConfigurationException + * @return self + */ + public function setServers(array $servers): self + { + foreach ($servers as $server) { + if($diff = \array_diff(['host', 'port', 'saslUser', 'saslPassword'], \array_keys($server))){ + throw new PhpfastcacheInvalidConfigurationException('Missing keys for memcached server: '. \implode(', ', $diff)); + } + if($diff = \array_diff( \array_keys($server), ['host', 'port', 'saslUser', 'saslPassword'])){ + throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: '. \implode(', ', $diff)); + } + if(!\is_string($server['host'])){ + throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array'); + } + if(!\is_int($server['port'])){ + throw new PhpfastcacheInvalidConfigurationException('Port must be a valid integer in "$server" configuration array'); + } + } + $this->servers = $servers; + return $this; + } + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return Config + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Driver.php new file mode 100644 index 0000000..a7e1c74 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Driver.php @@ -0,0 +1,209 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcached; + +use Memcached as MemcachedSoftware; +use Phpfastcache\Config\ConfigurationOption; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException +}; +use Phpfastcache\Util\{ + MemcacheDriverCollisionDetectorTrait +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property MemcachedSoftware $instance + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait { + __construct as protected __parentConstruct; + } + use MemcacheDriverCollisionDetectorTrait; + + /** + * Driver constructor. + * @param ConfigurationOption $config + * @param string $instanceId + * @throws PhpfastcacheDriverException + */ + public function __construct(ConfigurationOption $config, string $instanceId) + { + self::checkCollision('Memcached'); + $this->__parentConstruct($config, $instanceId); + } + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \class_exists('Memcached'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + $this->instance = new MemcachedSoftware(); + $this->instance->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); + $servers = $this->getConfig()->getServers(); + + if (\count($servers) < 1) { + $servers = [ + [ + 'host' => $this->getConfig()->getHost(), + 'path' => $this->getConfig()->getPath(), + 'port' => $this->getConfig()->getPort(), + 'saslUser' => $this->getConfig()->getSaslUser() ?: false, + 'saslPassword' => $this->getConfig()->getSaslPassword() ?: false, + ], + ]; + } + + foreach ($servers as $server) { + try { + /** + * If path is provided we consider it as an UNIX Socket + */ + if (!empty($server['path']) && !$this->instance->addServer($server['path'], 0)) { + $this->fallback = true; + } else { + if (!empty($server['host']) && !$this->instance->addServer($server['host'], $server['port'])) { + $this->fallback = true; + } + } + + if (!empty($server['saslUser']) && !empty($server['saslPassword'])) { + $this->instance->setSaslAuthData($server['saslUser'], $server['saslPassword']); + } + + } catch (\Exception $e) { + $this->fallback = true; + } + } + + /** + * Since Memcached does not throw + * any error if not connected ... + */ + $version = $this->instance->getVersion(); + if (!$version || $this->instance->getResultCode() !== MemcachedSoftware::RES_SUCCESS) { + throw new PhpfastcacheDriverException('Memcached seems to not be connected'); + } + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + + if ($val === false) { + return null; + } + + return $val; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + // Memcache will only allow a expiration timer less than 2592000 seconds, + // otherwise, it will assume you're giving it a UNIX timestamp. + if ($ttl > 2592000) { + $ttl = \time() + $ttl; + } + + return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->instance->flush(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stats = current($this->instance->getStats()); + $stats['uptime'] = (isset($stats['uptime']) ? $stats['uptime'] : 0); + $stats['version'] = (isset($stats['version']) ? $stats['version'] : $this->instance->getVersion()); + $stats['bytes'] = (isset($stats['bytes']) ? $stats['version'] : 0); + + $date = (new \DateTime())->setTimestamp(\time() - $stats['uptime']); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats['version'], $date->format(\DATE_RFC2822))) + ->setRawData($stats) + ->setSize((int)$stats['bytes']); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Item.php new file mode 100644 index 0000000..efa5b76 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memcached/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memcached; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Memcached\Driver as MemcachedDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Memcached + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Memcached\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(MemcachedDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MemcachedDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Config.php new file mode 100644 index 0000000..72baab4 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memstatic; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Driver.php new file mode 100644 index 0000000..4d79d7e --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Driver.php @@ -0,0 +1,140 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memstatic; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @var array + */ + protected $staticStack = []; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return true; + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $key = \md5($item->getKey()); + if (isset($this->staticStack[$key])) { + return $this->staticStack[$key]; + } + return null; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->staticStack[\md5($item->getKey())] = $this->driverPreWrap($item); + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $key = \md5($item->getKey()); + if (isset($this->staticStack[$key])) { + unset($this->staticStack[$key]); + return true; + } + return false; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + unset($this->staticStack); + $this->staticStack = []; + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $stat->setInfo('[Memstatic] A memory static driver') + ->setSize(mb_strlen(\serialize($this->staticStack))) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData($this->staticStack); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Item.php new file mode 100644 index 0000000..ef3a514 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Memstatic/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Memstatic; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Memstatic\Driver as MemstaticDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Devnull + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Memstatic\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(MemstaticDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MemstaticDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Config.php new file mode 100644 index 0000000..543c3fe --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Config.php @@ -0,0 +1,253 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Mongodb; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 27017; + + /** + * @var int + */ + protected $timeout = 3; + + /** + * @var string + */ + protected $username = ''; + + /** + * @var string + */ + protected $password = ''; + + /** + * @var array + */ + protected $servers = []; + + /** + * @var string + */ + protected $collectionName = 'Cache'; + + /** + * @var string + */ + protected $databaseName = Driver::MONGODB_DEFAULT_DB_NAME; + + /** + * @var array + */ + protected $options = []; + + /** + * @var array + */ + protected $driverOptions = []; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return self + */ + public function setTimeout(int $timeout): self + { + $this->timeout = $timeout; + return $this; + } + + /** + * @return string + */ + public function getUsername(): string + { + return $this->username; + } + + /** + * @param string $username + * @return self + */ + public function setUsername(string $username): self + { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @param string $password + * @return self + */ + public function setPassword(string $password): self + { + $this->password = $password; + return $this; + } + + /** + * @return array + */ + public function getServers(): array + { + return $this->servers; + } + + /** + * @param array $servers + * @return self + */ + public function setServers(array $servers): self + { + $this->servers = $servers; + return $this; + } + + /** + * @return string + */ + public function getCollectionName(): string + { + return $this->collectionName; + } + + /** + * @param string $collectionName + * @return self + */ + public function setCollectionName(string $collectionName): self + { + $this->collectionName = $collectionName; + return $this; + } + + /** + * @return string + */ + public function getDatabaseName(): string + { + return $this->databaseName; + } + + /** + * @param string $databaseName + * @return self + */ + public function setDatabaseName(string $databaseName): self + { + $this->databaseName = $databaseName; + return $this; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @see https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options + * @param array $options + * @return Config + */ + public function setOptions(array $options): self + { + $this->options = $options; + return $this; + } + + /** + * @return array + */ + public function getDriverOptions(): array + { + return $this->driverOptions; + } + + /** + * @param array $driverOptions + * @return self + */ + public function setDriverOptions(array $driverOptions): self + { + $this->driverOptions = $driverOptions; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Driver.php new file mode 100644 index 0000000..a78ce42 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Driver.php @@ -0,0 +1,324 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * @author Fabio Covolo Mazzo (fabiocmazzo) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Mongodb; + +use LogicException; +use MongoDB\{ + BSON\Binary, BSON\UTCDateTime, Client, Collection, Database, DeleteResult, Driver\Command, Driver\Exception\Exception as MongoDBException +}; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Client $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + const MONGODB_DEFAULT_DB_NAME = 'phpfastcache'; + + use DriverBaseTrait; + + /** + * @var Collection + */ + public $collection; + + /** + * @var Database + */ + public $database; + + /** + * @return bool + */ + public function driverCheck(): bool + { + $mongoExtensionExists = class_exists(\MongoDB\Driver\Manager::class); + + if (!$mongoExtensionExists && class_exists(\MongoClient::class)) { + \trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library. + For MongoDb with Mongo PECL support use Mongo Driver.', \E_USER_ERROR); + } + + return $mongoExtensionExists && class_exists(\MongoDB\Collection::class); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $document = $this->getCollection()->findOne(['_id' => $item->getEncodedKey()]); + + if ($document) { + $return = [ + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), + ]; + + if (!empty($this->getConfig()->isItemDetailedDate())) { + $return += [ + self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime() + ->getTimestamp()), + self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime() + ->getTimestamp()), + ]; + } + + return $return; + } + + return null; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + * @throws PhpfastcacheDriverException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $set = [ + self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), + self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), + self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), + ]; + + if (!empty($this->getConfig()->isItemDetailedDate())) { + $set += [ + self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate() + ->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), + self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate() + ->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), + ]; + } + $result = (array)$this->getCollection()->updateOne( + ['_id' => $item->getEncodedKey()], + [ + '$set' => $set, + ], + ['upsert' => true, 'multiple' => false] + ); + } catch (MongoDBException $e) { + throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); + } + + return isset($result['ok']) ? $result['ok'] == 1 : true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + /** + * @var DeleteResult $deletionResult + */ + $deletionResult = $this->getCollection()->deleteOne(['_id' => $item->getEncodedKey()]); + + return $deletionResult->isAcknowledged(); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->collection->deleteMany([])->isAcknowledged(); + } + + /** + * @return bool + * @throws MongodbException + * @throws LogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof Client) { + throw new LogicException('Already connected to Mongodb server'); + } + + $timeout = $this->getConfig()->getTimeout() * 1000; + $collectionName = $this->getConfig()->getCollectionName(); + $databaseName = $this->getConfig()->getDatabaseName(); + $driverOptions = $this->getConfig()->getDriverOptions(); + + $this->instance = $this->instance ?: new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout], $driverOptions); + $this->database = $this->database ?: $this->instance->selectDatabase($databaseName); + + if (!$this->collectionExists($collectionName)) { + $this->database->createCollection($collectionName); + } + + $this->collection = $this->database->selectCollection($collectionName); + + return true; + } + + /** + * Checks if a collection name exists on the Mongo database. + * + * @param string $collectionName The collection name to check. + * + * @return bool True if the collection exists, false if not. + */ + protected function collectionExists($collectionName): bool + { + foreach ($this->database->listCollections() as $collection) { + if ($collection->getName() === $collectionName) { + return true; + } + } + + return false; + } + + /** + * Builds the connection URI from the given parameters. + * + * @param string $databaseName + * @return string The connection URI. + */ + protected function buildConnectionURI($databaseName = ''): string + { + $servers = $this->getConfig()->getServers(); + $options = $this->getConfig()->getOptions(); + + $host = $this->getConfig()->getHost(); + $port = $this->getConfig()->getPort(); + $username = $this->getConfig()->getUsername(); + $password = $this->getConfig()->getPassword(); + + if( \count($servers) > 0 ){ + $host = \array_reduce($servers, function($carry, $data){ + $carry .= ($carry === '' ? '' : ',').$data['host'].':'.$data['port']; + return $carry; + }, ''); + $port = false; + } + + return implode('', [ + 'mongodb://', + ($username ?: ''), + ($password ? ":{$password}" : ''), + ($username ? '@' : ''), + $host, + ($port !== 27017 && $port !== false ? ":{$port}" : ''), + ($databaseName ? "/{$databaseName}" : ''), + (\count($options) > 0 ? '?'.\http_build_query($options) : ''), + ]); + } + + /** + * @return Collection + */ + protected function getCollection(): Collection + { + return $this->collection; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $serverStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ + 'serverStatus' => 1, + 'recordStats' => 0, + 'repl' => 0, + 'metrics' => 0, + ]))->toArray()[0]; + + $collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ + 'collStats' => (isset($this->getConfig()['collectionName']) ? $this->getConfig()['collectionName'] : 'Cache'), + 'verbose' => true, + ]))->toArray()[0]; + + $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { + $array = $callback($array); + + if (\is_object($array) || \is_array($array)) { + foreach ($array as &$value) { + $value = \call_user_func($array_filter_recursive, $value, $callback); + } + } + + return $array; + }; + + $callback = function ($item) { + /** + * Remove unserializable properties + */ + if ($item instanceof \MongoDB\BSON\UTCDateTime) { + return (string)$item; + } + return $item; + }; + + $serverStats = $array_filter_recursive($serverStats, $callback); + $collectionStats = $array_filter_recursive($collectionStats, $callback); + + $stats = (new DriverStatistic()) + ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . \round($serverStats->uptime / 86400, + 1) . "\n For more information see RawData.") + ->setSize($collectionStats->size) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData([ + 'serverStatus' => $serverStats, + 'collStats' => $collectionStats, + ]); + + return $stats; + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Item.php new file mode 100644 index 0000000..59a2b1b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Mongodb/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Mongodb; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Mongodb\Driver as MongodbDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Mongodb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Mongodb\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(MongodbDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof MongodbDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Config.php new file mode 100644 index 0000000..44d2442 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Config.php @@ -0,0 +1,199 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Predis; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 6379; + + /** + * @var string + */ + protected $password = ''; + + /** + * @var int + */ + protected $database = 0; + + /** + * @var \Predis\Client + */ + protected $predisClient; + + /** + * @var string + */ + protected $optPrefix = ''; + + /** + * @var int + */ + protected $timeout = 5; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return Config + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return Config + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return null + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param null $password + * @return self + */ + public function setPassword(string $password): self + { + $this->password = $password; + return $this; + } + + /** + * @return int + */ + public function getDatabase(): int + { + return $this->database; + } + + /** + * @param int $database + * @return Config + */ + public function setDatabase(int $database): self + { + $this->database = $database; + return $this; + } + + /** + * @return array + */ + public function getPredisConfigArray(): array + { + return [ + 'host' => $this->getHost(), + 'port' => $this->getPort(), + 'password' => $this->getPassword() ?: null, + 'database' => $this->getDatabase(), + 'timeout' => $this->getTimeout(), + ]; + } + + /** + * @return \Predis\Client|null + */ + public function getPredisClient() + { + return $this->predisClient; + } + + /** + * @param \Predis\Client $predisClient |null + * @return Config + */ + public function setPredisClient(\Predis\Client $predisClient = null): Config + { + $this->predisClient = $predisClient; + return $this; + } + + /** + * @return string + * @since 7.0.2 + */ + public function getOptPrefix(): string + { + return $this->optPrefix; + } + + /** + * @param string $optPrefix + * @return Config + * @since 7.0.2 + */ + public function setOptPrefix(string $optPrefix): Config + { + $this->optPrefix = trim($optPrefix); + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return self + */ + public function setTimeout(int $timeout): self + { + $this->timeout = $timeout; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Driver.php new file mode 100644 index 0000000..98fb496 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Driver.php @@ -0,0 +1,208 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Predis; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Predis\Client as PredisClient; +use Predis\Connection\ConnectionException as PredisConnectionException; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property PredisClient $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + if (extension_loaded('Redis')) { + \trigger_error('The native Redis extension is installed, you should use Redis instead of Predis to increase performances', \E_USER_NOTICE); + } + + return \class_exists('Predis\Client'); + } + + /** + * @return bool + * @throws PhpfastcacheDriverException + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof PredisClient) { + throw new PhpfastcacheLogicException('Already connected to Predis server'); + } + + /** + * In case of an user-provided + * Predis client just return here + */ + if ($this->getConfig()->getPredisClient() instanceof PredisClient) { + $this->instance = $this->getConfig()->getPredisClient(); + if (!$this->instance->isConnected()) { + $this->instance->connect(); + } + return true; + } + + $options = []; + + if($this->getConfig()->getOptPrefix()){ + $options['prefix'] = $this->getConfig()->getOptPrefix(); + } + + if (!empty($this->getConfig()->getPath())) { + $this->instance = new PredisClient([ + 'scheme' => 'unix', + 'timeout' => $this->getConfig()->getTimeout(), + 'path' => $this->getConfig()->getPath(), + ], $options); + } else { + $this->instance = new PredisClient($this->getConfig()->getPredisConfigArray(), $options); + } + + try { + $this->instance->connect(); + } catch (PredisConnectionException $e) { + throw new PhpfastcacheDriverException( + 'Failed to connect to predis server. Check the Predis documentation: https://github.com/nrk/predis/tree/v1.1#how-to-install-and-use-predis', + 0, + $e + ); + } + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } + + return $this->decode($val); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + /** + * @see https://redis.io/commands/setex + * @see https://redis.io/commands/expire + */ + if ($ttl <= 0) { + return (bool)$this->instance->expire($item->getKey(), 0); + } + + return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item)))->getPayload() === 'OK'; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)$this->instance->del([$item->getKey()]); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->instance->flushdb()->getPayload() === 'OK'; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + + /** + * @return string + */ + public function getHelp(): string + { + return << +To install the Predis library via Composer: +composer require "predis/predis" "~1.1.0" +

+HELP; + } + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $info = $this->instance->info(); + $size = (isset($info['Memory']['used_memory']) ? $info['Memory']['used_memory'] : 0); + $version = (isset($info['Server']['redis_version']) ? $info['Server']['redis_version'] : 0); + $date = (isset($info['Server']['uptime_in_seconds']) ? (new \DateTime())->setTimestamp(\time() - $info['Server']['uptime_in_seconds']) : 'unknown date'); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData($info) + ->setSize((int)$size) + ->setInfo(\sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", + $version, $date->format(\DATE_RFC2822))); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Item.php new file mode 100644 index 0000000..128928f --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Predis/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Predis; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Predis\Driver as PredisDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Predis + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Predis\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(PredisDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof PredisDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Config.php new file mode 100644 index 0000000..2c94ceb --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Config.php @@ -0,0 +1,186 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Redis; + +use Phpfastcache\Config\ConfigurationOption; +use Redis as RedisClient; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 6379; + + /** + * @var string + */ + protected $password = ''; + + /** + * @var int + */ + protected $database = 0; + + /** + * @var int + */ + protected $timeout = 5; + + /** + * @var RedisClient + */ + protected $redisClient; + + /** + * @var string + */ + protected $optPrefix = ''; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return mixed + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $password + * @return self + */ + public function setPassword(string $password): self + { + $this->password = $password; + return $this; + } + + /** + * @return int + */ + public function getDatabase(): int + { + return $this->database; + } + + /** + * @param int $database + * @return self + */ + public function setDatabase(int $database): self + { + $this->database = $database; + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return self + */ + public function setTimeout(int $timeout): self + { + $this->timeout = $timeout; + return $this; + } + + /** + * @return RedisClient|null + */ + public function getRedisClient() + { + return $this->redisClient; + } + + /** + * @param RedisClient $predisClient |null + * @return Config + */ + public function setRedisClient(RedisClient $redisClient = null): Config + { + $this->redisClient = $redisClient; + return $this; + } + + /** + * @return string + * @since 7.0.2 + */ + public function getOptPrefix(): string + { + return $this->optPrefix; + } + + /** + * @param string $optPrefix + * @return Config + * @since 7.0.2 + */ + public function setOptPrefix(string $optPrefix): Config + { + $this->optPrefix = trim($optPrefix); + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Driver.php new file mode 100644 index 0000000..311e860 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Driver.php @@ -0,0 +1,188 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Redis; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; +use Redis as RedisClient; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('Redis'); + } + + /** + * @return bool + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof RedisClient) { + throw new PhpfastcacheLogicException('Already connected to Redis server'); + } + + /** + * In case of an user-provided + * Redis client just return here + */ + if ($this->getConfig()->getRedisClient() instanceof RedisClient) { + /** + * Unlike Predis, we can't test if we're are connected + * or not, so let's just assume that we are + */ + $this->instance = $this->getConfig()->getRedisClient(); + return true; + } + + $this->instance = $this->instance ?: new RedisClient(); + + /** + * If path is provided we consider it as an UNIX Socket + */ + if ($this->getConfig()->getPath()) { + $isConnected = $this->instance->connect($this->getConfig()->getPath()); + } else { + $isConnected = $this->instance->connect($this->getConfig()->getHost(), $this->getConfig()->getPort(), $this->getConfig()->getTimeout()); + } + + if (!$isConnected && $this->getConfig()->getPath()) { + return false; + } + + if($this->getConfig()->getOptPrefix()){ + $this->instance->setOption(RedisClient::OPT_PREFIX, $this->getConfig()->getOptPrefix()); + } + + if (!$this->getConfig()->getPath()) { + if ($this->getConfig()->getPassword() && !$this->instance->auth($this->getConfig()->getPassword())) { + return false; + } + } + + if ($this->getConfig()->getDatabase() !== null) { + $this->instance->select($this->getConfig()->getDatabase()); + } + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getKey()); + if ($val == false) { + return null; + } + + return $this->decode($val); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + /** + * @see https://redis.io/commands/setex + * @see https://redis.io/commands/expire + */ + if ($ttl <= 0) { + return $this->instance->expire($item->getKey(), 0); + } + + return $this->instance->setex($item->getKey(), $ttl, $this->encode($this->driverPreWrap($item))); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)$this->instance->del($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->instance->flushDB(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + // used_memory + $info = $this->instance->info(); + $date = (new \DateTime())->setTimestamp(\time() - $info['uptime_in_seconds']); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData($info) + ->setSize((int)$info['used_memory']) + ->setInfo(\sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", + $info['redis_version'], $date->format(\DATE_RFC2822))); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Item.php new file mode 100644 index 0000000..c844fbc --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Redis/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Redis; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Redis\Driver as RedisDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Redis + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Redis\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(RedisDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof RedisDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Config.php new file mode 100644 index 0000000..8d4a037 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Config.php @@ -0,0 +1,114 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Riak; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 8098; + + /** + * @var string + */ + protected $prefix = 'riak'; + + /** + * @var string + */ + protected $bucketName = Driver::RIAK_DEFAULT_BUCKET_NAME; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return self + */ + public function setHost(string $host): self + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return self + */ + public function setPort(int $port): self + { + $this->port = $port; + return $this; + } + + /** + * @return string + */ + public function getPrefix(): string + { + return $this->prefix; + } + + /** + * @param string $prefix + * @return self + */ + public function setPrefix(string $prefix): self + { + $this->prefix = $prefix; + return $this; + } + + /** + * @return string + */ + public function getBucketName(): string + { + return $this->bucketName; + } + + /** + * @param string $bucketName + * @return self + */ + public function setBucketName(string $bucketName): self + { + $this->bucketName = $bucketName; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Driver.php new file mode 100644 index 0000000..2c15a62 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Driver.php @@ -0,0 +1,151 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Riak; + +use Basho\Riak\Riak; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Riak $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + const RIAK_DEFAULT_BUCKET_NAME = 'phpfastcache'; + + /** + * @var string + */ + protected $bucketName = self::RIAK_DEFAULT_BUCKET_NAME; + + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \class_exists('Basho\Riak\Riak'); + } + + + /** + * @return bool + * @throws PhpfastcacheLogicException + */ + protected function driverConnect(): bool + { + if ($this->instance instanceof Riak) { + throw new PhpfastcacheLogicException('Already connected to Riak server'); + } + + $this->bucketName = $this->getConfig()->getBucketName(); + + $this->instance = new Riak($this->getConfig()->getHost(), $this->getConfig()->getPort(), $this->getConfig()->getPrefix()); + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + return $this->decode($this->instance->bucket($this->bucketName)->getBinary($item->getKey())->getData()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->instance + ->bucket($this->bucketName) + ->newBinary($item->getKey(), $this->encode($this->driverPreWrap($item))) + ->store(); + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $this->instance->bucket($this->bucketName)->get($item->getKey())->delete(); + return true; + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + $bucket = $this->instance->bucket($this->bucketName); + foreach ($bucket->getKeys() as $key) { + $bucket->get($key)->delete(); + } + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $info = $this->instance->bucket($this->bucketName)->getProperties(); + + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData($info) + ->setSize(false) + ->setInfo('Riak does not provide size/date information att all :('); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Item.php new file mode 100644 index 0000000..051dc7a --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Riak/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Riak; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Riak\Driver as RiakDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Riak + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Riak\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(RiakDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof RiakDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Config.php new file mode 100644 index 0000000..ce1dc8e --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Config.php @@ -0,0 +1,26 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Sqlite; + +use Phpfastcache\Config\{ + ConfigurationOption, IOConfigurationOptionTrait +}; + +class Config extends ConfigurationOption +{ + use IOConfigurationOptionTrait; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Driver.php new file mode 100644 index 0000000..d0dc42e --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Driver.php @@ -0,0 +1,363 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Sqlite; + +use PDO; +use PDOException; +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface, IO\IOHelperTrait +}; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException, PhpfastcacheIOException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait, IOHelperTrait; + + /** + * + */ + const FILE_DIR = 'sqlite'; + /** + * + */ + const INDEXING_FILE = 'indexing'; + + /** + * @var int + */ + protected $maxSize = 10; // 10 mb + + /** + * @var int + */ + protected $currentDB = 1; + + /** + * @var string + */ + protected $SqliteDir = ''; + + /** + * @var \PDO + */ + protected $indexing; + + + /** + * @return string + * @throws \Phpfastcache\Exceptions\PhpfastcacheCoreException + */ + public function getSqliteDir(): string + { + return $this->SqliteDir ?: $this->getPath() . \DIRECTORY_SEPARATOR . self::FILE_DIR; + } + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('pdo_sqlite') && (\is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)); + } + + /** + * @return bool + * @throws PhpfastcacheIOException + */ + protected function driverConnect(): bool + { + if (!\file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)) { + throw new PhpfastcacheIOException(\sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); + } + if (!\file_exists($this->getPath() . '/' . self::FILE_DIR)) { + if (!mkdir($this->getPath() . '/' . self::FILE_DIR, $this->getDefaultChmod(), true) + ) { + $this->fallback = true; + } + } + $this->SqliteDir = $this->getPath() . '/' . self::FILE_DIR; + + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $item->getKey(), + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + + } catch (PDOException $e) { + try { + $stm = $this->getDb($item->getKey(), true) + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $item->getKey(), + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + } catch (PDOException $e) { + return null; + } + } + + if (isset($row['object'])) { + return $this->decode($row['object']); + } + + return null; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); + $stm->execute([ + ':keyword' => $item->getKey(), + ':object' => $this->encode($this->driverPreWrap($item)), + ':exp' => $item->getExpirationDate()->getTimestamp(), + ]); + + return true; + } catch (\PDOException $e) { + return false; + } + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + try { + $stm = $this->getDb($item->getKey()) + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); + + return $stm->execute([ + ':keyword' => $item->getKey(), + ':U' => \time(), + ]); + } catch (PDOException $e) { + return false; + } + } else { + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + $this->instance = []; + $this->indexing = null; + + // delete everything before reset indexing + $dir = opendir($this->getSqliteDir()); + while ($file = readdir($dir)) { + if ($file != '.' && $file != '..') { + unlink($this->getSqliteDir() . '/' . $file); + } + } + + return true; + } + + /** + * INIT NEW DB + * @param \PDO $db + */ + public function initDB(\PDO $db) + { + $db->exec('drop table if exists "caching"'); + $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); + $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); + $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); + $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); + } + + /** + * INIT Indexing DB + * @param \PDO $db + */ + public function initIndexing(\PDO $db) + { + + // delete everything before reset indexing + $dir = opendir($this->SqliteDir); + while ($file = readdir($dir)) { + if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') { + unlink($this->SqliteDir . '/' . $file); + } + } + + $db->exec('DROP TABLE if exists "balancing"'); + $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); + $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); + $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); + + } + + /** + * INIT Instant DB + * Return Database of Keyword + * @param $keyword + * @return int + */ + public function indexing($keyword) + { + if ($this->indexing == null) { + $tableCreated = false; + if (!\file_exists($this->SqliteDir . '/indexing')) { + $tableCreated = true; + } + + $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); + $PDO->setAttribute(PDO::ATTR_ERRMODE, + PDO::ERRMODE_EXCEPTION); + + if ($tableCreated) { + $this->initIndexing($PDO); + } + $this->indexing = $PDO; + unset($PDO); + + $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); + $stm->execute(); + $row = $stm->fetch(PDO::FETCH_ASSOC); + if (!isset($row['db'])) { + $db = 1; + } elseif ($row['db'] <= 1) { + $db = 1; + } else { + $db = $row['db']; + } + + // check file size + + $size = \file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1; + $size = round($size / 1024 / 1024, 1); + + + if ($size > $this->maxSize) { + $db++; + } + $this->currentDB = $db; + + } + + // look for keyword + $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); + $stm->execute([ + ':keyword' => $keyword, + ]); + $row = $stm->fetch(PDO::FETCH_ASSOC); + if (isset($row['db']) && $row['db'] != '') { + $db = $row['db']; + } else { + /* + * Insert new to Indexing + */ + $db = $this->currentDB; + $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); + $stm->execute([ + ':keyword' => $keyword, + ':db' => $db, + ]); + } + + return $db; + } + + /** + * @param string $keyword + * @param bool $reset + * @return PDO + */ + public function getDb(string $keyword, bool $reset = false): PDO + { + /** + * Default is phpfastcache + */ + $instant = $this->indexing($keyword); + + /** + * init instant + */ + if (!isset($this->instance[$instant])) { + // check DB Files ready or not + $tableCreated = false; + if ($reset || !\file_exists($this->SqliteDir . '/db' . $instant)) { + $tableCreated = true; + } + $PDO = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant); + $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + if ($tableCreated) { + $this->initDB($PDO); + } + + $this->instance[$instant] = $PDO; + unset($PDO); + + } + + return $this->instance[$instant]; + } + + /** + * @return array + */ + public function __sleep(): array + { + return \array_diff(\array_keys(\get_object_vars($this)), ['indexing', 'instance']); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Item.php new file mode 100644 index 0000000..4f0812c --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Sqlite/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Sqlite; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Sqlite\Driver as SqliteDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Sqlite + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Sqlite\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(SqliteDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof SqliteDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Config.php new file mode 100644 index 0000000..f572eed --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Config.php @@ -0,0 +1,114 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Ssdb; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + /** + * @var string + */ + protected $host = '127.0.0.1'; + + /** + * @var int + */ + protected $port = 8888; + + /** + * @var string + */ + protected $password = ''; + + /** + * @var int + */ + protected $timeout = 2000; + + /** + * @return string + */ + public function getHost(): string + { + return $this->host; + } + + /** + * @param string $host + * @return Config + */ + public function setHost(string $host): Config + { + $this->host = $host; + return $this; + } + + /** + * @return int + */ + public function getPort(): int + { + return $this->port; + } + + /** + * @param int $port + * @return Config + */ + public function setPort(int $port): Config + { + $this->port = $port; + return $this; + } + + /** + * @return string + */ + public function getPassword(): string + { + return $this->password; + } + + /** + * @param string $password + * @return Config + */ + public function setPassword(string $password): Config + { + $this->password = $password; + return $this; + } + + /** + * @return int + */ + public function getTimeout(): int + { + return $this->timeout; + } + + /** + * @param int $timeout + * @return Config + */ + public function setTimeout(int $timeout): Config + { + $this->timeout = $timeout; + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Driver.php new file mode 100644 index 0000000..ec8353c --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Driver.php @@ -0,0 +1,159 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Ssdb; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverCheckException, PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException +}; +use phpssdb\Core\{ + SimpleSSDB, SSDBException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property SimpleSSDB $instance Instance of driver service + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + static $driverCheck; + if ($driverCheck === null) { + return ($driverCheck = \class_exists('phpssdb\Core\SSDB')); + } + + return $driverCheck; + } + + /** + * @return bool + * @throws PhpfastcacheDriverException + */ + protected function driverConnect(): bool + { + try { + $clientConfig = $this->getConfig(); + + $this->instance = new SimpleSSDB($clientConfig->getHost(), $clientConfig->getPort(), $clientConfig->getTimeout()); + if (!empty($clientConfig->getPassword())) { + $this->instance->auth($clientConfig->getPassword()); + } + + if (!$this->instance) { + return false; + } + + return true; + } catch (SSDBException $e) { + throw new PhpfastcacheDriverCheckException('Ssdb failed to connect with error: ' . $e->getMessage(), 0, $e); + } + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = $this->instance->get($item->getEncodedKey()); + if ($val == false) { + return null; + } + + return $this->decode($val); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->setx($item->getEncodedKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return $this->instance->del($item->getEncodedKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return $this->instance->flushdb('kv'); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $info = $this->instance->info(); + + /** + * Data returned by Ssdb are very poorly formatted + * using hardcoded offset of pair key-value :-( + */ + $stat->setInfo(\sprintf("Ssdb-server v%s with a total of %s call(s).\n For more information see RawData.", $info[2], $info[6])) + ->setRawData($info) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setSize($this->instance->dbsize()); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Item.php new file mode 100644 index 0000000..37216a3 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Ssdb/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Ssdb; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Ssdb\Driver as SsdbDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Ssdb + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Ssdb\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(SsdbDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof SsdbDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Config.php new file mode 100644 index 0000000..4d89fea --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Wincache; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Driver.php new file mode 100644 index 0000000..47fc835 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Driver.php @@ -0,0 +1,131 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Wincache; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('wincache') && \function_exists('wincache_ucache_set'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $val = wincache_ucache_get($item->getKey(), $suc); + + if ($suc === false) { + return null; + } + + return $val; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return wincache_ucache_delete($item->getKey()); + } + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return wincache_ucache_clear(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $memInfo = wincache_ucache_meminfo(); + $info = wincache_ucache_info(); + $date = (new \DateTime())->setTimestamp(\time() - $info['total_cache_uptime']); + + return (new DriverStatistic()) + ->setInfo(\sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(\DATE_RFC2822))) + ->setSize($memInfo['memory_free'] - $memInfo['memory_total']) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData($memInfo); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Item.php new file mode 100644 index 0000000..90d7da6 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Wincache/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Wincache; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Wincache\Driver as WincacheDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Wincache + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Wincache\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(WincacheDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof WincacheDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Config.php new file mode 100644 index 0000000..1185f37 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Xcache; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Driver.php new file mode 100644 index 0000000..9163c47 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Driver.php @@ -0,0 +1,140 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Xcache; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('xcache') && \function_exists('xcache_get'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $data = $this->decode(xcache_get($item->getKey())); + if ($data === false || $data === '') { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return xcache_set($item->getKey(), $this->encode($this->driverPreWrap($item)), $item->getTtl()); + + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return xcache_unset($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + $cnt = xcache_count(XC_TYPE_VAR); + for ($i = 0; $i < $cnt; $i++) { + xcache_clear_cache(XC_TYPE_VAR, $i); + } + + return true; + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + if (!ini_get('xcache.admin.enable_auth')) { + $info = xcache_info(XC_TYPE_VAR, 0); + + return (new DriverStatistic()) + ->setSize(abs($info['size'] - $info['avail'])) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("Xcache v%s with following modules loaded:\n %s", XCACHE_VERSION, \str_replace(' ', ', ', XCACHE_MODULES))) + ->setRawData($info); + } + throw new \RuntimeException("PhpFastCache is not able to read Xcache configuration. Please put this to your php.ini:\n + [xcache.admin] + xcache.admin.enable_auth = Off\n + Then reboot your webserver and make sure that the native Xcache ini configuration file does not override your setting."); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Item.php new file mode 100644 index 0000000..7fcdcb0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Xcache/Item.php @@ -0,0 +1,63 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Xcache; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Xcache\Driver as XcacheDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Xcache + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Xcache\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(XcacheDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof XcacheDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Config.php new file mode 100644 index 0000000..36c9057 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zenddisk; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Driver.php new file mode 100644 index 0000000..d0aecb7 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Driver.php @@ -0,0 +1,142 @@ + + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zenddisk; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver (zend disk cache) + * Requires Zend Data Cache Functions from ZendServer + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('Zend Data Cache') && \function_exists('zend_disk_cache_store'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $data = zend_disk_cache_fetch($item->getKey()); + if ($data === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)zend_disk_cache_delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return @zend_disk_cache_clear(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return string + */ + public function getHelp(): string + { + return << +This driver rely on Zend Server 8.5+, see: https://www.zend.com/en/products/zend_server +

+HELP; + } + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stat = new DriverStatistic(); + $stat->setInfo('[ZendDisk] A void info string') + ->setSize(0) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setRawData(false); + + return $stat; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Item.php new file mode 100644 index 0000000..e9b9bfd --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zenddisk/Item.php @@ -0,0 +1,63 @@ + + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zenddisk; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Zenddisk\Driver as ZendDiskDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Zenddisk + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Zenddisk\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(ZendDiskDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ZendDiskDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Config.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Config.php new file mode 100644 index 0000000..ff43929 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Config.php @@ -0,0 +1,24 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zendshm; + +use Phpfastcache\Config\ConfigurationOption; + +class Config extends ConfigurationOption +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Driver.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Driver.php new file mode 100644 index 0000000..b6eeb11 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Driver.php @@ -0,0 +1,141 @@ + + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zendshm; + +use Phpfastcache\Core\Pool\{ + DriverBaseTrait, ExtendedCacheItemPoolInterface +}; +use Phpfastcache\Entities\DriverStatistic; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; +use Psr\Cache\CacheItemInterface; + +/** + * Class Driver (zend memory cache) + * Requires Zend Data Cache Functions from ZendServer + * @package phpFastCache\Drivers + * @property Config $config Config object + * @method Config getConfig() Return the config object + */ +class Driver implements ExtendedCacheItemPoolInterface +{ + use DriverBaseTrait; + + /** + * @return bool + */ + public function driverCheck(): bool + { + return \extension_loaded('Zend Data Cache') && \function_exists('zend_shm_cache_store'); + } + + /** + * @return bool + */ + protected function driverConnect(): bool + { + return true; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return null|array + */ + protected function driverRead(CacheItemInterface $item) + { + $data = zend_shm_cache_fetch($item->getKey()); + if ($data === false) { + return null; + } + + return $data; + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return mixed + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverWrite(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + $ttl = $item->getExpirationDate()->getTimestamp() - \time(); + + return zend_shm_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return bool + * @throws PhpfastcacheInvalidArgumentException + */ + protected function driverDelete(CacheItemInterface $item): bool + { + /** + * Check for Cross-Driver type confusion + */ + if ($item instanceof Item) { + return (bool)zend_shm_cache_delete($item->getKey()); + } + + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); + } + + /** + * @return bool + */ + protected function driverClear(): bool + { + return @zend_shm_cache_clear(); + } + + /******************** + * + * PSR-6 Extended Methods + * + *******************/ + + /** + * @return string + */ + public function getHelp(): string + { + return << +This driver rely on Zend Server 8.5+, see: https://www.zend.com/en/products/zend_server +

+HELP; + } + + /** + * @return DriverStatistic + */ + public function getStats(): DriverStatistic + { + $stats = (array)zend_shm_cache_info(); + return (new DriverStatistic()) + ->setData(\implode(', ', \array_keys($this->itemInstances))) + ->setInfo(\sprintf("The Zend memory have %d item(s) in cache.\n For more information see RawData.", $stats['items_total'])) + ->setRawData($stats) + ->setSize($stats['memory_total']); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Item.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Item.php new file mode 100644 index 0000000..6ee0f09 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Drivers/Zendshm/Item.php @@ -0,0 +1,62 @@ + + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Drivers\Zendshm; + +use Phpfastcache\Core\Item\{ + ExtendedCacheItemInterface, ItemBaseTrait +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Drivers\Zendshm\Driver as ZendSHMDriver; +use Phpfastcache\Exceptions\{ + PhpfastcacheInvalidArgumentException +}; + +/** + * Class Item + * @package phpFastCache\Drivers\Zendshm + */ +class Item implements ExtendedCacheItemInterface +{ + use ItemBaseTrait { + ItemBaseTrait::__construct as __BaseConstruct; + } + + /** + * Item constructor. + * @param \Phpfastcache\Drivers\Zendshm\Driver $driver + * @param $key + * @throws PhpfastcacheInvalidArgumentException + */ + public function __construct(ZendSHMDriver $driver, $key) + { + $this->__BaseConstruct($driver, $key); + } + + /** + * @param ExtendedCacheItemPoolInterface $driver + * @throws PhpfastcacheInvalidArgumentException + * @return static + */ + public function setDriver(ExtendedCacheItemPoolInterface $driver) + { + if ($driver instanceof ZendSHMDriver) { + $this->driver = $driver; + + return $this; + } + + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/DriverStatistic.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/DriverStatistic.php new file mode 100644 index 0000000..d6934a0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/DriverStatistic.php @@ -0,0 +1,133 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Entities; + +/** + * Class DriverStatistic + * @package phpFastCache\Entities + */ +class DriverStatistic +{ + /** + * @var string + */ + protected $info = ''; + + /** + * @var int + */ + protected $size = 0; + + /** + * @var string + */ + protected $data = ''; + + /** + * @var mixed + */ + protected $rawData; + + /** + * @return string Return info or false if no information available + */ + public function getInfo(): string + { + return $this->info; + } + + /** + * @return int Return size in octet or false if no information available + */ + public function getSize(): int + { + return $this->size; + } + + /** + * @return mixed + */ + public function getData() + { + return $this->data; + } + + /** + * @param string $info + * @return $this + */ + public function setInfo(string $info): self + { + $this->info = $info; + + return $this; + } + + + /** + * @param int $size + * @return $this + */ + public function setSize(int $size) + { + $this->size = $size; + + return $this; + } + + /** + * @param mixed $data + * @return $this + */ + public function setData($data): self + { + $this->data = ($data ?: ''); + + return $this; + } + + /** + * @return mixed + */ + public function getRawData() + { + return $this->rawData; + } + + /** + * @param mixed $raw + * @return $this + */ + public function setRawData($raw): self + { + $this->rawData = $raw; + + return $this; + } + + /** + * @return array + */ + public function getPublicDesc(): array + { + return [ + 'Info' => 'Cache Information', + 'Size' => 'Cache Size', + 'Data' => 'Cache items keys', + 'RawData' => 'Cache raw data', + ]; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/ItemBatch.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/ItemBatch.php new file mode 100644 index 0000000..9ef2e68 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Entities/ItemBatch.php @@ -0,0 +1,60 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Entities; + +/** + * Class ItemBatch + * @package phpFastCache\Entities + */ +class ItemBatch +{ + /** + * @var string + */ + protected $itemKey; + + /** + * @var \DateTimeInterface + */ + protected $itemDate; + + /** + * ItemBatch constructor. + * @param string $itemKey + * @param \DateTimeInterface $itemDate + */ + public function __construct(string $itemKey, \DateTimeInterface $itemDate) + { + $this->itemKey = $itemKey; + $this->itemDate = $itemDate; + } + + /** + * @return string + */ + public function getItemKey(): string + { + return $this->itemKey; + } + + /** + * @return \DateTimeInterface + */ + public function getItemDate(): \DateTimeInterface + { + return $this->itemDate; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Event/EventInterface.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Event/EventInterface.php new file mode 100644 index 0000000..2e3e6a8 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Event/EventInterface.php @@ -0,0 +1,48 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Event; + +use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; + +interface EventInterface +{ + /** + * @return self + */ + public static function getInstance(): self; + + /** + * @param string $eventName + * @param array ...$args + */ + public function dispatch(string $eventName, ...$args); + + /** + * @param string $name + * @param array $arguments + * @throws PhpfastcacheInvalidArgumentException + * @throws \BadMethodCallException + */ + public function __call(string $name, array $arguments); + + /** + * @param string $eventName + * @param string $callbackName + * @return bool + */ + public function unbindEventCallback(string $eventName, string $callbackName): bool; +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/EventManager.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/EventManager.php new file mode 100644 index 0000000..bf7a0d9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/EventManager.php @@ -0,0 +1,124 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache; + +use Phpfastcache\Event\EventInterface; +use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; + +/** + * Class CacheManager + * @package phpFastCache + * + * == ItemPool Events == + * @method Void onCacheGetItem() onCacheGetItem(Callable $callable) + * @method Void onCacheDeleteItem() onCacheDeleteItem(Callable $callable) + * @method Void onCacheSaveItem() onCacheSaveItem(Callable $callable) + * @method Void onCacheSaveDeferredItem() onCacheSaveDeferredItem(Callable $callable) + * @method Void onCacheCommitItem() onCacheCommitItem(Callable $callable) + * @method Void onCacheClearItem() onCacheClearItem(Callable $callable) + * @method Void onCacheWriteFileOnDisk() onCacheWriteFileOnDisk(Callable $callable) + * @method Void onCacheGetItemInSlamBatch() onCacheGetItemInSlamBatch(Callable $callable) + * + * == Item Events == + * @method Void onCacheItemSet() onCacheItemSet(Callable $callable) + * @method Void onCacheItemExpireAt() onCacheItemExpireAt(Callable $callable) + * @method Void onCacheItemExpireAfter() onCacheItemExpireAfter(Callable $callable) + * + * + */ +class EventManager implements EventInterface +{ + /** + * @var $this + */ + protected static $instance; + + /** + * @var array + */ + protected $events = []; + + /** + * @return EventInterface + */ + public static function getInstance(): EventInterface + { + return (self::$instance ?: self::$instance = new self); + } + + /** + * EventManager constructor. + */ + final protected function __construct() + { + // The constructor should not be instantiated externally + } + + /** + * @param string $eventName + * @param array ...$args + */ + public function dispatch(string $eventName, ...$args) + { + /** + * Replace array_key_exists by isset + * due to performance issue on huge + * loop dispatching operations + */ + if (isset($this->events[$eventName])) { + foreach ($this->events[$eventName] as $event) { + \call_user_func_array($event, $args); + } + } + } + + /** + * @param string $name + * @param array $arguments + * @throws PhpfastcacheInvalidArgumentException + * @throws \BadMethodCallException + */ + public function __call(string $name, array $arguments) + { + if (\strpos($name, 'on') === 0) { + $name = \substr($name, 2); + if (\is_callable($arguments[0])) { + if (isset($arguments[1]) && \is_string($arguments[0])) { + $this->events[$name][$arguments[1]] = $arguments[0]; + } else { + $this->events[$name][] = $arguments[0]; + } + } else { + throw new PhpfastcacheInvalidArgumentException(\sprintf('Expected Callable, got "%s"', \gettype($arguments[0]))); + } + } else { + throw new \BadMethodCallException('An event must start with "on" such as "onCacheGetItem"'); + } + } + + /** + * @param string $eventName + * @param string $callbackName + * @return bool + */ + public function unbindEventCallback(string $eventName, string $callbackName): bool + { + $return = isset($this->events[$eventName][$callbackName]); + unset($this->events[$eventName][$callbackName]); + + return $return; + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php new file mode 100644 index 0000000..b8109d2 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheCoreException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheCoreException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php new file mode 100644 index 0000000..5d9ba48 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheRootException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheDeprecatedException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php new file mode 100644 index 0000000..ab63431 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheDriverCheckException + * @package phpFastCache\Exceptions + */ +class PhpfastcacheDriverCheckException extends PhpfastcacheDriverException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php new file mode 100644 index 0000000..c571a44 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheDriverCheckException + * @package phpFastCache\Exceptions + */ +class PhpfastcacheDriverConnectException extends PhpfastcacheDriverException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php new file mode 100644 index 0000000..fa46d69 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheDriverException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheDriverException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php new file mode 100644 index 0000000..9680f92 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheDriverNotFoundException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheDriverNotFoundException extends PhpfastcacheDriverException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php new file mode 100644 index 0000000..c33ec0b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php @@ -0,0 +1,27 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +use Psr\Cache\CacheException; + +/** + * Interface PhpfastcacheExceptionInterface + * @package Phpfastcache\Exceptions + */ +interface PhpfastcacheExceptionInterface extends CacheException, \Throwable +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php new file mode 100644 index 0000000..8151eb3 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php @@ -0,0 +1,38 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheIOException + * @package Phpfastcache\Exceptions + * @since v6 + */ +class PhpfastcacheIOException extends PhpfastcacheCoreException +{ + /** + * @inheritdoc + */ + public function __construct($message = "", $code = 0, $previous = null) + { + $lastError = error_get_last(); + if ($lastError) { + $message .= "\n"; + $message .= "Additional information provided by error_get_last():\n"; + $message .= "{$lastError['message']} in {$lastError['file']} line {$lastError['line']}"; + } + parent::__construct($message, $code, $previous); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php new file mode 100644 index 0000000..5484cd5 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheInstanceNotFoundException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheInstanceNotFoundException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php new file mode 100644 index 0000000..a474275 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php @@ -0,0 +1,27 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +use Psr\Cache\InvalidArgumentException; + +/** + * Class PhpfastcacheCoreException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheInvalidArgumentException extends PhpfastcacheRootException implements InvalidArgumentException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentTypeException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentTypeException.php new file mode 100644 index 0000000..2906786 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentTypeException.php @@ -0,0 +1,34 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheInvalidArgumentTypeException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheInvalidArgumentTypeException extends PhpfastcacheInvalidArgumentException +{ + /** + * @link https://php.net/manual/en/exception.construct.php + * @param string $expectedType + * @param mixed $unexpectedData + */ + public function __construct($expectedType, $unexpectedData) + { + $type = \gettype($unexpectedData); + parent::__construct("Expecting '{$expectedType}', got '" . ($type === 'object' ? $type . '(' . \get_class($type) . ')' : $type) . "'"); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php new file mode 100644 index 0000000..1911fbb --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheInvalidConfigurationException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheInvalidConfigurationException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php new file mode 100644 index 0000000..221f329 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheLogicException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheLogicException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php new file mode 100644 index 0000000..0419296 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheRootException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheRootException extends \Exception implements PhpfastcacheExceptionInterface +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php new file mode 100644 index 0000000..8519da0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php @@ -0,0 +1,27 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +use Psr\SimpleCache\CacheException; + +/** + * Class PhpfastcacheRootException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheSimpleCacheException extends \Exception implements CacheException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php new file mode 100644 index 0000000..2138ca9 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php @@ -0,0 +1,25 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Exceptions; + +/** + * Class PhpfastcacheUnsupportedOperationException + * @package Phpfastcache\Exceptions + */ +class PhpfastcacheUnsupportedOperationException extends PhpfastcacheRootException +{ + +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/ActOnAll.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/ActOnAll.php new file mode 100644 index 0000000..298597a --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/ActOnAll.php @@ -0,0 +1,488 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Helper; + +use Phpfastcache\{ + CacheManager, Event\EventInterface +}; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Entities\DriverStatistic; +use Psr\Cache\CacheItemInterface; + +/** + * Class ActOnAll + * @package phpFastCache\Helper + * @todo Review the setters part due to a confusion with cross-driver items + */ +class ActOnAll +{ + /** + * @var ExtendedCacheItemPoolInterface[] + */ + protected $instances = []; + + /** + * ActOnAll constructor. + */ + public function __construct() + { + $this->instances =& CacheManager::getInternalInstances(); + } + + /** + * @return \Closure + */ + protected function getGenericCallback(): \Closure + { + return function ($method, $args) { + $return = []; + foreach ($this->instances as $instance) { + $reflectionMethod = new \ReflectionMethod(\get_class($instance), $method); + $return[$instance->getDriverName()] = $reflectionMethod->invokeArgs($instance, $args); + } + return $return; + }; + } + + + /** + * @param string $key + * @return array + */ + public function hasItem($key): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function clear(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $key + * @return array + */ + public function deleteItem($key): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $keys + * @return array + */ + public function deleteItems(array $keys): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function save(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function saveDeferred(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array ...$items + * @return array + */ + public function saveMultiple(...$items): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function commit(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function getConfig(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $optionName + * @return array + */ + public function getConfigOption(string $optionName): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function getDriverName(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $key + * @return array + */ + public function getItem($key): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $keys + * @return array + */ + public function getItems(array $keys = []): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $keys + * @param int $option + * @param int $depth + * @return array + */ + public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function setItem(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return string[] + */ + public function getHelp(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return DriverStatistic[] + */ + public function getStats(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @return array + */ + public function getItemsByTag($tagName): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @return array + */ + public function getItemsByTags(array $tagNames): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param int $option + * @param int $depth + * @return array + */ + public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @return array + */ + public function deleteItemsByTag($tagName): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @return array + */ + public function deleteItemsByTags(array $tagNames): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @param int $step + * @return array + */ + public function incrementItemsByTag($tagName, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param int $step + * @return array + */ + public function incrementItemsByTags(array $tagNames, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @param int $step + * @return array + */ + public function decrementItemsByTag($tagName, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param int $step + * @return array + */ + public function decrementItemsByTags(array $tagNames, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @param array|string $data + * @return array + */ + public function appendItemsByTag($tagName, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param array|string $data + * @return array + */ + public function appendItemsByTags(array $tagNames, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param string $tagName + * @param array|string $data + * @return array + */ + public function prependItemsByTag($tagName, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param array|string $data + * @return array + */ + public function prependItemsByTags(array $tagNames, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @return array + */ + public function getItemsByTagsAll(array $tagNames): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @return array + */ + public function deleteItemsByTagsAll(array $tagNames): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param int $step + * @return array + */ + public function incrementItemsByTagsAll(array $tagNames, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param int $step + * @return array + */ + public function decrementItemsByTagsAll(array $tagNames, $step = 1): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param array|string $data + * @return array + */ + public function appendItemsByTagsAll(array $tagNames, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param array $tagNames + * @param array|string $data + * @return array + */ + public function prependItemsByTagsAll(array $tagNames, $data): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function detachItem(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function detachAllItems(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function attachItem(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param \Psr\Cache\CacheItemInterface $item + * @return array + */ + public function isAttached(CacheItemInterface $item): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @param EventInterface $em + * @return array + */ + public function setEventManager(EventInterface $em): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } + + /** + * @return array + */ + public function getDefaultConfig(): array + { + $callback = $this->getGenericCallback(); + return $callback(__FUNCTION__, \func_get_args()); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/CacheConditionalHelper.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/CacheConditionalHelper.php new file mode 100644 index 0000000..08c4160 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/CacheConditionalHelper.php @@ -0,0 +1,60 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Helper; + +use Psr\Cache\CacheItemPoolInterface; + +/** + * Class CacheConditional + * @package phpFastCache\Helper + */ +class CacheConditionalHelper +{ + /** + * @var CacheItemPoolInterface + */ + protected $cacheInstance; + + /** + * CachePromise constructor. + * @param CacheItemPoolInterface $cacheInstance + */ + public function __construct(CacheItemPoolInterface $cacheInstance) + { + $this->cacheInstance = $cacheInstance; + } + + /** + * @param string $cacheKey + * @param callable $callback + * @param int|\DateInterval $expiresAfter + * @return mixed + */ + public function get(string $cacheKey, callable $callback, $expiresAfter = null) + { + $cacheItem = $this->cacheInstance->getItem($cacheKey); + + if (!$cacheItem->isHit()) { + $cacheItem->set($callback()); + if ($expiresAfter) { + $cacheItem->expiresAfter($expiresAfter); + } + $this->cacheInstance->save($cacheItem); + } + + return $cacheItem->get(); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/Psr16Adapter.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/Psr16Adapter.php new file mode 100644 index 0000000..c69a0a0 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/Psr16Adapter.php @@ -0,0 +1,211 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Helper; + +use Phpfastcache\CacheManager; +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; +use Phpfastcache\Exceptions\{ + PhpfastcacheDriverCheckException, PhpfastcacheInvalidArgumentException, PhpfastcacheLogicException, PhpfastcacheRootException, PhpfastcacheSimpleCacheException +}; +use Psr\SimpleCache\CacheInterface; + +/** + * Class Psr16Adapter + * @package phpFastCache\Helper + */ +class Psr16Adapter implements CacheInterface +{ + /** + * @var ExtendedCacheItemPoolInterface + */ + protected $internalCacheInstance; + + /** + * Psr16Adapter constructor. + * @param string|ExtendedCacheItemPoolInterface $driver + * @param array|\Phpfastcache\Config\ConfigurationOption|null $config + * @throws PhpfastcacheDriverCheckException + * @throws PhpfastcacheLogicException + */ + public function __construct($driver, $config = null) + { + if ($driver instanceof ExtendedCacheItemPoolInterface) { + if ($config !== null) { + throw new PhpfastcacheLogicException("You can't pass a config parameter along with an non-string '\$driver' parameter."); + } + $this->internalCacheInstance = $driver; + } else { + $this->internalCacheInstance = CacheManager::getInstance($driver, $config); + } + } + + /** + * @param string $key + * @param null $default + * @return mixed|null + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function get($key, $default = null) + { + try { + $cacheItem = $this->internalCacheInstance->getItem($key); + if (!$cacheItem->isExpired() && $cacheItem->get() !== null) { + return $cacheItem->get(); + } + + return $default; + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string $key + * @param mixed $value + * @param null $ttl + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function set($key, $value, $ttl = null): bool + { + try { + $cacheItem = $this->internalCacheInstance + ->getItem($key) + ->set($value); + if (\is_int($ttl) && $ttl <= 0) { + $cacheItem->expiresAt((new \DateTime('@0'))); + } elseif (\is_int($ttl) || $ttl instanceof \DateInterval) { + $cacheItem->expiresAfter($ttl); + } + return $this->internalCacheInstance->save($cacheItem); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string $key + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function delete($key): bool + { + try { + return $this->internalCacheInstance->deleteItem($key); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function clear(): bool + { + try { + return $this->internalCacheInstance->clear(); + } catch (PhpfastcacheRootException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string[] $keys + * @param null $default + * @return \iterable + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function getMultiple($keys, $default = null) + { + try { + return array_map(function (ExtendedCacheItemInterface $item) { + return $item->get(); + }, $this->internalCacheInstance->getItems($keys)); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string[] $values + * @param null|int|\DateInterval $ttl + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function setMultiple($values, $ttl = null): bool + { + try { + foreach ($values as $key => $value) { + $cacheItem = $this->internalCacheInstance->getItem($key)->set($value); + + if (\is_int($ttl) && $ttl <= 0) { + $cacheItem->expiresAt((new \DateTime('@0'))); + } elseif (\is_int($ttl) || $ttl instanceof \DateInterval) { + $cacheItem->expiresAfter($ttl); + } + $this->internalCacheInstance->saveDeferred($cacheItem); + unset($cacheItem); + } + return $this->internalCacheInstance->commit(); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string[] $keys + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function deleteMultiple($keys): bool + { + try { + return $this->internalCacheInstance->deleteItems($keys); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * @param string $key + * @return bool + * @throws \Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException + */ + public function has($key): bool + { + try { + $cacheItem = $this->internalCacheInstance->getItem($key); + return $cacheItem->isHit() && !$cacheItem->isExpired(); + } catch (PhpfastcacheInvalidArgumentException $e) { + throw new PhpfastcacheSimpleCacheException($e->getMessage(), null, $e); + } + } + + /** + * Extra methods that are not part of + * psr16 specifications + */ + + /** + * @return \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface + */ + public function getInternalCacheInstance(): ExtendedCacheItemPoolInterface + { + return $this->internalCacheInstance; + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/TestHelper.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/TestHelper.php new file mode 100644 index 0000000..e1f07d2 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Helper/TestHelper.php @@ -0,0 +1,357 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Helper; + +use Phpfastcache\Api; +use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; + +/** + * Class TestHelper + * @package phpFastCache\Helper + */ +class TestHelper +{ + /** + * @var string + */ + protected $testName; + + /** + * @var int + */ + protected $exitCode = 0; + + /** + * @var int + */ + protected $timestamp; + + /** + * TestHelper constructor. + * + * @param string $testName + * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + */ + public function __construct(string $testName) + { + $this->timestamp = microtime(true); + $this->testName = $testName; + + /** + * Catch all uncaught exception + * to our own exception handler + */ + set_exception_handler([$this, 'exceptionHandler']); + set_error_handler([$this, 'errorHandler']); + + $this->printHeaders(); + } + + /** + * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException + * @throws \Phpfastcache\Exceptions\PhpfastcacheLogicException + */ + public function printHeaders() + { + if (!$this->isCli() && !\headers_sent()) { + \header('Content-Type: text/plain, true'); + } + + $this->printText('[PhpFastCache CORE v' . Api::getPhpFastCacheVersion() . Api::getPhpFastCacheGitHeadHash() . ']', true); + $this->printText('[PhpFastCache API v' . Api::getVersion() . ']', true); + $this->printText('[PHP v' . PHP_VERSION . ']', true); + $this->printText("[Begin Test: '{$this->testName}']"); + $this->printText('---'); + + } + + /** + * @return int + */ + public function getExitCode(): int + { + return $this->exitCode; + } + + /** + * @return $this + */ + public function resetExitCode(): self + { + $this->exitCode = 0; + + return $this; + } + + /** + * @param string $string + * @return $this + */ + public function printSkipText(string $string): self + { + $this->printText($string, false, 'SKIP'); + + return $this; + } + + /** + * @param string $string + * @return $this + */ + public function printPassText(string $string): self + { + $this->printText($string, false, 'PASS'); + + + return $this; + } + + /** + * @param string printFailText + * @return $this + */ + public function printInfoText(string $string): self + { + $this->printText($string, false, 'INFO'); + + + return $this; + } + + /** + * @param string $string + * @return $this + */ + public function printDebugText(string $string): self + { + $this->printText($string, false, 'DEBUG'); + + return $this; + } + + /** + * @param string $string + * @return $this + */ + public function printNoteText(string $string): self + { + $this->printText($string, false, 'NOTE'); + + return $this; + } + + /** + * @param string $string + * @return $this + */ + public function printFailText(string $string): self + { + $this->printText($string, false, 'FAIL'); + $this->exitCode = 1; + + return $this; + } + + /** + * @param int $count + * @return $this + */ + public function printNewLine(int $count = 1): self + { + print \str_repeat(PHP_EOL, $count); + return $this; + } + + /** + * @param string $string + * @param bool $strtoupper + * @param string $prefix + * @return $this + */ + public function printText(string $string, bool $strtoupper = false, string $prefix = ''): self + { + if ($prefix) { + $string = "[{$prefix}] {$string}"; + } + if (!$strtoupper) { + print \trim($string) . PHP_EOL; + } else { + print \strtoupper(\trim($string) . PHP_EOL); + } + + return $this; + } + + /** + * @param string $cmd + */ + public function runAsyncProcess(string $cmd) + { + if (\substr(\php_uname(), 0, 7) === 'Windows') { + \pclose(\popen('start /B ' . $cmd, 'r')); + } else { + \exec($cmd . ' > /dev/null &'); + } + } + + /** + * @param string $file + * @param string $ext + */ + public function runSubProcess(string $file, string $ext = '.php') + { + $this->runAsyncProcess(($this->isHHVM() ? 'hhvm ' : 'php ') . \getcwd() . \DIRECTORY_SEPARATOR . 'subprocess' . \DIRECTORY_SEPARATOR . $file . '.subprocess' . $ext); + } + + /** + * @return void + */ + public function terminateTest() + { + $execTime = \round(\microtime(true) - $this->timestamp, 3); + + $this->printText('Test duration: ' . $execTime . 's'); + exit($this->exitCode); + } + + /** + * @return bool + */ + public function isHHVM(): bool + { + return \defined('HHVM_VERSION'); + } + + /** + * @param $obj + * @param $prop + * @return mixed + * @throws \ReflectionException + */ + public function accessInaccessibleMember($obj, $prop) + { + $reflection = new \ReflectionClass($obj); + $property = $reflection->getProperty($prop); + $property->setAccessible(true); + return $property->getValue($obj); + } + + /** + * @param \Throwable $exception + */ + public function exceptionHandler(\Throwable $exception) + { + if ($exception instanceof PhpfastcacheDriverCheckException) { + $this->printSkipText('A driver could not be initialized due to missing requirement: ' . $exception->getMessage()); + $this->exitCode = 0; + } else { + $this->printFailText(\sprintf( + 'Uncaught exception "%s" in "%s" line %d with message: "%s"', + \get_class($exception), + $exception->getFile(), + $exception->getLine(), + $exception->getMessage() + )); + } + $this->terminateTest(); + } + + /** + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + */ + public function errorHandler(int $errno, string $errstr, string $errfile, int $errline) + { + $errorType = ''; + + switch ($errno) { + case \E_PARSE: + case \E_ERROR: + case \E_CORE_ERROR: + case \E_COMPILE_ERROR: + case \E_USER_ERROR: + $errorType = '[FATAL ERROR]'; + break; + case \E_WARNING: + case \E_USER_WARNING: + case \E_COMPILE_WARNING: + case \E_RECOVERABLE_ERROR: + $errorType = '[WARNING]'; + break; + case \E_NOTICE: + case \E_USER_NOTICE: + $errorType = '[NOTICE]'; + break; + case \E_STRICT: + $errorType = '[STRICT]'; + break; + case \E_DEPRECATED: + case \E_USER_DEPRECATED: + $errorType = '[DEPRECATED]'; + break; + default: + break; + } + + if ($errorType === '[FATAL ERROR]') { + $this->printFailText(\sprintf( + "A critical error has been caught: \"%s\" in %s line %d", + "$errorType $errstr", + $errfile, + $errline + )); + } else { + $this->printDebugText(\sprintf( + "A non-critical error has been caught: \"%s\" in %s line %d", + "$errorType $errstr", + $errfile, + $errline + )); + } + } + + /** + * @see https://stackoverflow.com/questions/933367/php-how-to-best-determine-if-the-current-invocation-is-from-cli-or-web-server + * @return bool + */ + public function isCli(): bool + { + if (\defined('STDIN')) { + return true; + } + + if (\php_sapi_name() === 'cli') { + return true; + } + + if (\array_key_exists('SHELL', $_ENV)) { + return true; + } + + if (empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && \count($_SERVER['argv']) > 0) { + return true; + } + + if (!\array_key_exists('REQUEST_METHOD', $_SERVER)) { + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php new file mode 100644 index 0000000..bea0f95 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php @@ -0,0 +1,85 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Proxy; + +use Phpfastcache\CacheManager; +use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Entities\DriverStatistic; +use Psr\Cache\CacheItemInterface; + +/** + * Class phpFastCache + * + * Handle methods using annotations for IDE + * because they're handled by __call() + * Check out ExtendedCacheItemInterface to see all + * the drivers methods magically implemented + * + * @method ExtendedCacheItemInterface getItem($key) Retrieve an item and returns an empty item if not found + * @method ExtendedCacheItemInterface[] getItems(array $keys) Retrieve an item and returns an empty item if not found + * @method bool hasItem() hasItem($key) Tests if an item exists + * @method bool deleteItem(string $key) Delete an item + * @method bool deleteItems(array $keys) Delete some items + * @method bool save(CacheItemInterface $item) Save an item + * @method bool saveDeferred(CacheItemInterface $item) Sets a cache item to be persisted later + * @method bool commit() Persists any deferred cache items + * @method bool clear() Allow you to completely empty the cache and restart from the beginning + * @method DriverStatistic stats() Returns a DriverStatistic object + * @method ExtendedCacheItemInterface getItemsByTag($tagName) Return items by a tag + * @method ExtendedCacheItemInterface[] getItemsByTags(array $tagNames) Return items by some tags + * @method bool deleteItemsByTag($tagName) Delete items by a tag + * @method bool deleteItemsByTags(array $tagNames) // Delete items by some tags + * @method void incrementItemsByTag($tagName, $step = 1) // Increment items by a tag + * @method void incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags + * @method void decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag + * @method void decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags + * @method void appendItemsByTag($tagName, $data) // Append items by a tag + * @method void appendItemsByTags(array $tagNames, $data) // Append items by a tags + * @method void prependItemsByTag($tagName, $data) // Prepend items by a tag + * @method void prependItemsByTags(array $tagNames, $data) // Prepend items by a tags + */ +abstract class PhpfastcacheAbstractProxy +{ + /** + * @var \Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface + */ + protected $instance; + + /** + * PhpfastcacheAbstractProxy constructor. + * @param string $driver + * @param array|\Phpfastcache\Config\ConfigurationOption $config + */ + public function __construct(string $driver = CacheManager::AUTOMATIC_DRIVER_CLASS, $config = null) + { + $this->instance = CacheManager::getInstance($driver, $config); + } + + /** + * @param string $name + * @param array $args + * @return mixed + * @throws \BadMethodCallException + */ + public function __call(string $name, array $args) + { + if (\method_exists($this->instance, $name)) { + return \call_user_func_array([$this->instance, $name], $args); + } + + throw new \BadMethodCallException(\sprintf('Method %s does not exists', $name)); + } +} diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ArrayObject.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ArrayObject.php new file mode 100644 index 0000000..116bf4e --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ArrayObject.php @@ -0,0 +1,161 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ + +declare(strict_types=1); + +namespace Phpfastcache\Util; + +/** + * Class ArrayObject + * @package phpFastCache\Util + */ +class ArrayObject implements \ArrayAccess, \Iterator, \Countable +{ + + /** + * @var array + */ + private $array = []; + + /** + * @var int + */ + private $position = 0; + + /** + * @param $args + * ArrayObject constructor. + */ + public function __construct(...$args) + { + $this->array = (\count($args) === 1 && \is_array($args[0]) ? $args[0] : $args); + } + + /** + * @return mixed + */ + public function current() + { + return $this->array[$this->position]; + } + + /** + * + */ + public function next() + { + ++$this->position; + } + + /** + * @return int + */ + public function key(): int + { + return $this->position; + } + + /** + * @return bool + */ + public function valid(): bool + { + return $this->offsetExists($this->position); + } + + /** + * + */ + public function rewind() + { + $this->position = 0; + } + + /** + * @return int + */ + public function count(): int + { + return \count($this->array); + } + + /** + * @param mixed $offset + * @return bool + */ + public function offsetExists($offset): bool + { + return \array_key_exists($offset, $this->array); + } + + /** + * @param mixed $offset + * @return mixed|null + */ + public function offsetGet($offset) + { + return $this->array[$offset] ?? null; + } + + /** + * @param mixed $offset + * @param mixed $value + */ + public function offsetSet($offset, $value) + { + // NOTE: THIS IS THE FIX FOR THE ISSUE "Indirect modification of overloaded element of SplFixedArray has no effect" + // NOTE: WHEN APPENDING AN ARRAY (E.G. myArr[] = 5) THE KEY IS NULL, SO WE TEST FOR THIS CONDITION BELOW, AND VOILA + + if ($offset === null) { + $this->array[] = $value; + } else { + $this->array[$offset] = $value; + } + } + + /** + * @param mixed $offset + */ + public function offsetUnset($offset) + { + unset($this->array[$offset]); + } + + /** + * @return array|mixed + */ + public function toArray() + { + return $this->array; + } + + /** + * @return array|mixed + */ + protected function &getArray() + { + return $this->array; + } + + /** + * @param array $array + * @return self + */ + public function mergeArray($array): self + { + $this->array = \array_merge($this->array, $array); + + return $this; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php new file mode 100644 index 0000000..7dbd13b --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php @@ -0,0 +1,150 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Util; + +/** + * Trait ClassNamespaceResolverTrait + * @package phpFastCache\Core + */ +trait ClassNamespaceResolverTrait +{ + /** + * @var string + */ + protected $namespace; + + /** + * @return string + */ + protected function getClassNamespace(): string + { + if (!$this->namespace) { + $this->namespace = \substr(static::class, 0, \strrpos(static::class, '\\')); + } + + return $this->namespace; + } + + /** + * Iterate over all files in the given directory searching for classes. + * + * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they + * deprecated the whole component as of SF4. Our thanks to them. + * + * @param \Iterator|string|array $dir The directory to search in or an iterator + * + * @return array A class map array + */ + protected static function createClassMap($dir): array + { + if (\is_string($dir)) { + $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir)); + } + $map = []; + + if (\is_array($dir) || $dir instanceof \Traversable) { + foreach ($dir as $file) { + if (!$file->isFile()) { + continue; + } + $path = $file->getRealPath() ?: $file->getPathname(); + if ('php' !== pathinfo($path, \PATHINFO_EXTENSION)) { + continue; + } + $classes = self::findClasses($path); + if (\PHP_VERSION_ID >= 70000) { + // PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098 + \gc_mem_caches(); + } + foreach ($classes as $class) { + $map[$class] = $path; + } + } + } + + return $map; + } + + /** + * Extract the classes in the given file. + * + * NOTICE: This method has been borrowed from Symfony ClassLoader 3.4 since they + * deprecated the whole component as of SF4. Our thanks to them. + * + * @param string $path The file to check + * + * @return array The found classes + */ + protected static function findClasses(string $path): array + { + $contents = \file_get_contents($path); + $tokens = \token_get_all($contents); + $classes = []; + $namespace = ''; + for ($i = 0; isset($tokens[$i]); ++$i) { + $token = $tokens[$i]; + if (!isset($token[1])) { + continue; + } + $class = ''; + switch ($token[0]) { + case \T_NAMESPACE: + $namespace = ''; + // If there is a namespace, extract it + while (isset($tokens[++$i][1])) { + if (\in_array($tokens[$i][0], [\T_STRING, \T_NS_SEPARATOR])) { + $namespace .= $tokens[$i][1]; + } + } + $namespace .= '\\'; + break; + case \T_CLASS: + case \T_INTERFACE: + case \T_TRAIT: + // Skip usage of ::class constant + $isClassConstant = false; + for ($j = $i - 1; $j > 0; --$j) { + if (!isset($tokens[$j][1])) { + break; + } + if (\T_DOUBLE_COLON === $tokens[$j][0]) { + $isClassConstant = true; + break; + } elseif (!\in_array($tokens[$j][0], [\T_WHITESPACE, \T_DOC_COMMENT, \T_COMMENT], false)) { + break; + } + } + if ($isClassConstant) { + break; + } + // Find the classname + while (isset($tokens[++$i][1])) { + $t = $tokens[$i]; + if (\T_STRING === $t[0]) { + $class .= $t[1]; + } elseif ('' !== $class && \T_WHITESPACE === $t[0]) { + break; + } + } + $classes[] = \ltrim($namespace . $class, '\\'); + break; + default: + break; + } + } + return $classes; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php new file mode 100644 index 0000000..0c3b419 --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/Directory.php @@ -0,0 +1,150 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Util; + +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use SplFileInfo; + +/** + * Class Directory + * @package phpFastCache\Util + */ +class Directory +{ + /** + * Get the directory size + * @param string $directory + * @param bool $includeDirAllocSize + * @return integer + */ + public static function dirSize(string $directory, bool $includeDirAllocSize = false): int + { + $size = 0; + foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) { + /** + * @var \SplFileInfo $file + */ + if ($file->isFile()) { + $size += filesize($file->getRealPath()); + } else { + if ($includeDirAllocSize) { + $size += $file->getSize(); + } + } + } + + return $size; + } + + /** + * @param string $path + * @return int + */ + public static function getFileCount(string $path): int + { + $count = 0; + $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST); + foreach ($objects as $object) { + /** + * @var \SplFileInfo $object + */ + if ($object->isFile()) { + $count++; + } + } + + return $count; + } + + /** + * Recursively delete a directory and all of it's contents - e.g.the equivalent of `rm -r` on the command-line. + * Consistent with `rmdir()` and `unlink()`, an E_WARNING level error will be generated on failure. + * + * @param string $source absolute path to directory or file to delete. + * @param bool $removeOnlyChildren set to true will only remove content inside directory. + * + * @return bool true on success; false on failure + */ + public static function rrmdir(string $source, bool $removeOnlyChildren = false): bool + { + if (empty($source) || \file_exists($source) === false) { + return false; + } + + if (\is_file($source) || \is_link($source)) { + \clearstatcache(true, $source); + return \unlink($source); + } + + $files = new RecursiveIteratorIterator + ( + new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::CHILD_FIRST + ); + + foreach ($files as $fileinfo) { + /** + * @var SplFileInfo $fileinfo + */ + if ($fileinfo->isDir()) { + if (self::rrmdir($fileinfo->getRealPath()) === false) { + return false; + } + } else { + if (\unlink($fileinfo->getRealPath()) === false) { + return false; + } + } + } + + if ($removeOnlyChildren === false) { + return \rmdir($source); + } + + return true; + } + + /** + * Alias of realpath() but work + * on non-existing files + * + * @param string $path + * @return string + */ + public static function getAbsolutePath(string $path): string + { + $parts = \preg_split('~[/\\\\]+~', $path, 0, \PREG_SPLIT_NO_EMPTY); + $absolutes = []; + foreach ($parts as $part) { + if ('.' === $part) { + continue; + } + if ('..' === $part) { + \array_pop($absolutes); + } else { + $absolutes[] = $part; + } + } + + /** + * Allows to dereference char + */ + $__FILE__ = \preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. + $prefix = $__FILE__[0] === \DIRECTORY_SEPARATOR ? \DIRECTORY_SEPARATOR : ''; + return $prefix . \implode(\DIRECTORY_SEPARATOR, $absolutes); + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php new file mode 100644 index 0000000..693cbab --- /dev/null +++ b/system/caches/Phpfastcache/phpfastcache/phpfastcache/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php @@ -0,0 +1,56 @@ + https://www.phpfastcache.com + * @author Georges.L (Geolim4) + * + */ +declare(strict_types=1); + +namespace Phpfastcache\Util; + +/** + * Trait MemcacheDriverCollisionDetectorTrait + * @package phpFastCache\Core + */ +trait MemcacheDriverCollisionDetectorTrait +{ + /** + * @var string + */ + protected static $driverUsed; + + /** + * @param $driverName + * @return bool + */ + public static function checkCollision($driverName): bool + { + $CONSTANT_NAME = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED'; + + if ($driverName && \is_string($driverName)) { + if (!\defined($CONSTANT_NAME)) { + \define($CONSTANT_NAME, $driverName); + + return true; + } else { + if (\constant($CONSTANT_NAME) !== $driverName) { + \trigger_error('Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours', + \E_USER_WARNING); + + return false; + } + } + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/system/caches/Phpfastcache/psr/cache/CHANGELOG.md b/system/caches/Phpfastcache/psr/cache/CHANGELOG.md new file mode 100644 index 0000000..58ddab0 --- /dev/null +++ b/system/caches/Phpfastcache/psr/cache/CHANGELOG.md @@ -0,0 +1,16 @@ +# Changelog + +All notable changes to this project will be documented in this file, in reverse chronological order by release. + +## 1.0.1 - 2016-08-06 + +### Fixed + +- Make spacing consistent in phpdoc annotations php-fig/cache#9 - chalasr +- Fix grammar in phpdoc annotations php-fig/cache#10 - chalasr +- Be more specific in docblocks that `getItems()` and `deleteItems()` take an array of strings (`string[]`) compared to just `array` php-fig/cache#8 - GrahamCampbell +- For `expiresAt()` and `expiresAfter()` in CacheItemInterface fix docblock to specify null as a valid parameters as well as an implementation of DateTimeInterface php-fig/cache#7 - GrahamCampbell + +## 1.0.0 - 2015-12-11 + +Initial stable release; reflects accepted PSR-6 specification diff --git a/system/caches/Phpfastcache/psr/cache/LICENSE.txt b/system/caches/Phpfastcache/psr/cache/LICENSE.txt new file mode 100644 index 0000000..b1c2c97 --- /dev/null +++ b/system/caches/Phpfastcache/psr/cache/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2015 PHP Framework Interoperability Group + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/system/caches/Phpfastcache/psr/cache/README.md b/system/caches/Phpfastcache/psr/cache/README.md new file mode 100644 index 0000000..c8706ce --- /dev/null +++ b/system/caches/Phpfastcache/psr/cache/README.md @@ -0,0 +1,9 @@ +PSR Cache +========= + +This repository holds all interfaces defined by +[PSR-6](http://www.php-fig.org/psr/psr-6/). + +Note that this is not a Cache implementation of its own. It is merely an +interface that describes a Cache implementation. See the specification for more +details. diff --git a/system/caches/Phpfastcache/psr/cache/composer.json b/system/caches/Phpfastcache/psr/cache/composer.json new file mode 100644 index 0000000..e828fec --- /dev/null +++ b/system/caches/Phpfastcache/psr/cache/composer.json @@ -0,0 +1,25 @@ +{ + "name": "psr/cache", + "description": "Common interface for caching libraries", + "keywords": ["psr", "psr-6", "cache"], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/system/caches/Phpfastcache/psr/cache/src/CacheException.php b/system/caches/Phpfastcache/psr/cache/src/CacheException.php new file mode 100644 index 0000000..e27f22f --- /dev/null +++ b/system/caches/Phpfastcache/psr/cache/src/CacheException.php @@ -0,0 +1,10 @@ + Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in +> all copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +> THE SOFTWARE. diff --git a/system/caches/Phpfastcache/psr/simple-cache/README.md b/system/caches/Phpfastcache/psr/simple-cache/README.md new file mode 100644 index 0000000..43641d1 --- /dev/null +++ b/system/caches/Phpfastcache/psr/simple-cache/README.md @@ -0,0 +1,8 @@ +PHP FIG Simple Cache PSR +======================== + +This repository holds all interfaces related to PSR-16. + +Note that this is not a cache implementation of its own. It is merely an interface that describes a cache implementation. See [the specification](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-16-simple-cache.md) for more details. + +You can find implementations of the specification by looking for packages providing the [psr/simple-cache-implementation](https://packagist.org/providers/psr/simple-cache-implementation) virtual package. diff --git a/system/caches/Phpfastcache/psr/simple-cache/composer.json b/system/caches/Phpfastcache/psr/simple-cache/composer.json new file mode 100644 index 0000000..2978fa5 --- /dev/null +++ b/system/caches/Phpfastcache/psr/simple-cache/composer.json @@ -0,0 +1,25 @@ +{ + "name": "psr/simple-cache", + "description": "Common interfaces for simple caching", + "keywords": ["psr", "psr-16", "cache", "simple-cache", "caching"], + "license": "MIT", + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-4": { + "Psr\\SimpleCache\\": "src/" + } + }, + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + } +} diff --git a/system/caches/Phpfastcache/psr/simple-cache/src/CacheException.php b/system/caches/Phpfastcache/psr/simple-cache/src/CacheException.php new file mode 100644 index 0000000..eba5381 --- /dev/null +++ b/system/caches/Phpfastcache/psr/simple-cache/src/CacheException.php @@ -0,0 +1,10 @@ + value pairs. Cache keys that do not exist or are stale will have $default as value. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $keys is neither an array nor a Traversable, + * or if any of the $keys are not a legal value. + */ + public function getMultiple($keys, $default = null); + + /** + * Persists a set of key => value pairs in the cache, with an optional TTL. + * + * @param iterable $values A list of key => value pairs for a multiple-set operation. + * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and + * the driver supports TTL then the library may set a default value + * for it or let the driver take care of that. + * + * @return bool True on success and false on failure. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $values is neither an array nor a Traversable, + * or if any of the $values are not a legal value. + */ + public function setMultiple($values, $ttl = null); + + /** + * Deletes multiple cache items in a single operation. + * + * @param iterable $keys A list of string-based keys to be deleted. + * + * @return bool True if the items were successfully removed. False if there was an error. + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if $keys is neither an array nor a Traversable, + * or if any of the $keys are not a legal value. + */ + public function deleteMultiple($keys); + + /** + * Determines whether an item is present in the cache. + * + * NOTE: It is recommended that has() is only to be used for cache warming type purposes + * and not to be used within your live applications operations for get/set, as this method + * is subject to a race condition where your has() will return true and immediately after, + * another script can remove it making the state of your app out of date. + * + * @param string $key The cache item key. + * + * @return bool + * + * @throws \Psr\SimpleCache\InvalidArgumentException + * MUST be thrown if the $key string is not a legal value. + */ + public function has($key); +} diff --git a/system/caches/Phpfastcache/psr/simple-cache/src/InvalidArgumentException.php b/system/caches/Phpfastcache/psr/simple-cache/src/InvalidArgumentException.php new file mode 100644 index 0000000..6a9524a --- /dev/null +++ b/system/caches/Phpfastcache/psr/simple-cache/src/InvalidArgumentException.php @@ -0,0 +1,13 @@ +dirCache)) { + mkdir($this->dirCache, 0755, true); + } + $this->expire = (defined('CACHE_EXPIRE')) ? CACHE_EXPIRE : 3600; + + (defined('CACHE_SETTINGS') && is_array(CACHE_SETTINGS)) ? CacheManager::setDefaultConfig(new ConfigurationOption(CACHE_SETTINGS)) : CacheManager::setDefaultConfig(new ConfigurationOption(array('path' => $this->dirCache))); + + $instancias = ((CacheManager::getInstances())); + + if(count($instancias) < 1) + $this->phpfastcache = (defined('CACHE_DRIVER')) ? CacheManager::getInstance(CACHE_DRIVER) : CacheManager::getInstance('files'); + else + $this->phpfastcache = CacheManager::getInstanceById(array_keys($instancias)[0]); + + + //$this->phpfastcache->clear(); + + } + + public function verify($key) + { + + $CachedString = $this->phpfastcache->getItem($key); + + return $CachedString->isHit(); + } + + public function check($key) + { + return $this->verify($key); + } + + public function get($key) + { + + $CachedString = $this->phpfastcache->getItem($key); + + return $CachedString->get(); + + } + + public function set($key, $value, $expire = true) + { + $this->delete($key); + + $CachedString = $this->phpfastcache->getItem($key); + + //$exp = ($expire == true) ? (time() + $this->expire) : 0; + + $CachedString->set($value)->expiresAfter($this->expire);//in seconds, also accepts Datetime + + $save = $this->phpfastcache->save($CachedString); + + + return $save; // Save the cache item just like you do with doctrine and entities + + } + + public function delete($key) + { + + $this->phpfastcache->deleteItem($key); + clearstatcache(); + + } + + public function deleteAll(){ + + return $this->phpfastcache->clear(); + + } + + public function clear() { + return $this->deleteAll(); + } + + public function stats() { + //var_dump($this->phpfastcache->getStats()); + + $obj = new stdClass(); + + $obj->size = $this->phpfastcache->getStats()->getSize(); + $obj->info = $this->phpfastcache->getStats()->getInfo(); + $obj->rawData = $this->phpfastcache->getStats()->getRawData(); + $obj->data = $this->phpfastcache->getStats()->getData(); + + return $obj; + } + +} \ No newline at end of file diff --git a/system/caches/caches.php b/system/caches/caches.php new file mode 100644 index 0000000..4ee2469 --- /dev/null +++ b/system/caches/caches.php @@ -0,0 +1,175 @@ +dirCache)) { + mkdir($this->dirCache, 0755, true); + } + $this->expire = (defined('CACHE_EXPIRE')) ? CACHE_EXPIRE : 3600; + /*$files = glob($this->dirCache . '*.cache'); + + if ($files) { + foreach ($files as $file) { + //$time = substr(strrchr($file, '.'), 1); + $time = substr(strrchr(strstr($file, '.', true), '/'), 1); + //var_dump(substr(strrchr(strstr($file, '.', true), '/'), 1)); + + if ($time < time() and $time !== '0') { + if (file_exists($file)) { + unlink($file); + clearstatcache(); + } + } + } + }*/ + } + + public function verify($key) { + $files = $this->valid($key); + + if ($files) { + + return true; + + } else { + + return false; + } + } + + public function check($key) { + return $this->verify($key); + } + + public function get($key) { + + $file = $this->valid($key); + + if ($file) { + $cache = file_get_contents($file); + + return $this->decode($cache); + } + } + + public function set($key, $value, $expire = true) { + $this->delete($key); + + //$exp = ($expire == true) ? (time() + $this->expire) : 0; + + $file = $this->dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'; + + return file_put_contents($file, $this->encode($value)); + + } + + public function delete($key) { + $files = glob($this->dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); + + if ($files) { + foreach ($files as $file) { + if (file_exists($file)) { + unlink($file); + clearstatcache(); + } + } + } + } + + private function encode($value){ + + if(function_exists('igbinary_serialize')){ + return igbinary_serialize($value); + } else { + return serialize($value); + } + + } + + private function decode($value){ + + if(function_exists('igbinary_serialize')){ + return igbinary_unserialize($value); + } else { + return unserialize($value); + } + } + + private function valid($key) { + $file = ($this->dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); + + if (file_exists($file)) { + var_dump($file); + + //$time = substr(strrchr(strstr($files[0], '.', true), '/'), 1); + $time = filemtime($file) + $this->expire; + //var_dump(substr(strrchr(strstr($file, '.', true), '/'), 1)); + + + if ($time < time() and $time !== '0') { + + var_dump($file); + unlink($file); + clearstatcache(); + return false; + + } else { + + return $file; + + } + } else { + return false; + } + } + + public function deleteAll() { + $files = glob($this->dirCache . '*.cache'); + + if ($files) { + foreach ($files as $file) { + //$time = substr(strrchr($file, '.'), 1); + $time = substr(strrchr(strstr($file, '.', true), '/'), 1); + //var_dump(substr(strrchr(strstr($file, '.', true), '/'), 1)); + + if (file_exists($file)) { + unlink($file); + clearstatcache(); + } + } + } + + return true; + } + + public function clear() { + return $this->deleteAll(); + } + + public function stats() { + + $obj = new stdClass(); + + $obj->size = $this->GetDirectorySize($this->dirCache); + $obj->info = NULL; + $obj->rawData = NULL; + $obj->data = NULL; + + return $obj; + } + + private function GetDirectorySize($path){ + $bytestotal = 0; + $path = realpath($path); + if($path!==false){ + foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){ + $bytestotal += $object->getSize(); + } + } + return $bytestotal; + + } +} \ No newline at end of file diff --git a/system/engine/caches.php b/system/engine/caches.php index 42c0ff4..1b7a279 100644 --- a/system/engine/caches.php +++ b/system/engine/caches.php @@ -1,80 +1,3 @@ dirCache)) { - mkdir($this->dirCache, 0755, true); - } - $this->expire = (defined('CACHE_EXPIRE')) ? CACHE_EXPIRE : 3600; - $files = glob($this->dirCache . '*.cache'); - - if ($files) { - foreach ($files as $file) { - //$time = substr(strrchr($file, '.'), 1); - $time = substr(strrchr(strstr($file, '.', true), '/'), 1); - //var_dump(substr(strrchr(strstr($file, '.', true), '/'), 1)); - - if ($time < time() and $time !== '0') { - if (file_exists($file)) { - unlink($file); - clearstatcache(); - } - } - } - } - } - - public function verify($key) { - $files = glob($this->dirCache . '*.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); - - if ($files) { - - return true; - - } else { - - return false; - } - } - - public function check($key) { - return $this->verify($key); - } - - public function get($key) { - $files = glob($this->dirCache . '*.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); - - if ($files) { - $cache = file_get_contents($files[0]); - - return unserialize($cache); - } - } - - public function set($key, $value, $expire = true) { - $this->delete($key); - - $exp = ($expire == true) ? (time() + $this->expire) : 0; - - $file = $this->dirCache . $exp . '.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'; - - return file_put_contents($file, serialize($value)); - - } - - public function delete($key) { - $files = glob($this->dirCache . '*.' . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); - - if ($files) { - foreach ($files as $file) { - if (file_exists($file)) { - unlink($file); - clearstatcache(); - } - } - } - } -} \ No newline at end of file +require_once DIR_SYSTEM."caches/autoload.php"; \ No newline at end of file diff --git a/system/engine/controller.php b/system/engine/controller.php index f580424..a5f8de2 100644 --- a/system/engine/controller.php +++ b/system/engine/controller.php @@ -67,19 +67,23 @@ abstract class Controller { $thema = ($this->config->get("config_template") != NULL) ? $this->config->get("config_template") : "default"; foreach($this->templateTypes as $extensionTemplate) { - if(isset($pegRout[2])){ - if (file_exists(DIR_TEMPLATE . $thema.'/'.$pegRout[0].'/'.$pegRout[1].'_'.$pegRout[2].'.'.$extensionTemplate) != false) { - $this->template = $thema.'/'.$pegRout[0].'/'.$pegRout[1].'_'.$pegRout[2].'.'.$extensionTemplate; - break; - } - } else { - if (file_exists(DIR_TEMPLATE . $thema.'/'.$pegRout[0].'/'.$pegRout[1].'.'.$extensionTemplate) != false) { - $this->template = $thema.'/'.$pegRout[0].'/'.$pegRout[1].'.'.$extensionTemplate; - break; - } + + $structure = $thema.'/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure_D = 'default/'.$pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + $structure_W = $pegRout[0].'/'.$pegRout[1].((isset($pegRout[2])) ? '_'.$pegRout[2] : '').'.'.$extensionTemplate; + + if (file_exists(DIR_TEMPLATE .$structure) != false) { + $this->template = $structure; + break; + } elseif (file_exists(DIR_TEMPLATE .$structure_D)){ + $this->template = $structure_D; + break; + } elseif(file_exists(DIR_TEMPLATE .$structure_W)) { + $this->template = $structure_W; + break; } - } + } } if (file_exists(DIR_TEMPLATE . $this->template)) { @@ -237,5 +241,4 @@ abstract class Controller { return $this->response->setOutput($this->render()); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/system/system.php b/system/system.php index f127013..47cca90 100644 --- a/system/system.php +++ b/system/system.php @@ -140,7 +140,7 @@ if(!empty($configs)){ if(USE_DB_CONFIG === true) { - $query = (defined('CUSTOM_DB_CONFIG')) ? $db->query(CUSTOM_DB_CONFIG) : $db->query("SELECT * FROM settings ORDER BY store_id DESC, setting_id ASC"); + $query = (defined('CUSTOM_DB_CONFIG')) ? $db->query(CUSTOM_DB_CONFIG) : $db->query("SELECT * FROM settings ORDER BY setting_id ASC"); foreach ($query->rows as $setting) { if (!$setting['serialized']) {