| Server IP : 213.186.33.4 / Your IP : 216.73.216.193 Web Server : Apache System : Linux webm006.cluster103.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : awebpaca ( 35430) PHP Version : 8.5.0 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/a/w/e/awebpaca/piwik/vendor/matomo/cache/src/Backend/ |
Upload File : |
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*
*/
namespace Matomo\Cache\Backend;
use Matomo\Cache\Backend;
class Factory
{
public function buildArrayCache()
{
return new ArrayCache();
}
public function buildFileCache($options)
{
return new File($options['directory']);
}
public function buildNullCache()
{
return new NullCache();
}
public function buildChainedCache($options)
{
$backends = array();
foreach ($options['backends'] as $backendToBuild) {
$backendOptions = array();
if (array_key_exists($backendToBuild, $options)) {
$backendOptions = $options[$backendToBuild];
}
$backends[] = $this->buildBackend($backendToBuild, $backendOptions);
}
return new Chained($backends);
}
public function buildRedisCache($options)
{
if (empty($options['unix_socket']) && (empty($options['host']) || empty($options['port']))) {
throw new \InvalidArgumentException('RedisCache is not configured. Please provide at least a host and a port');
}
$timeout = 0.0;
if (array_key_exists('timeout', $options)) {
$timeout = $options['timeout'];
}
$redis = new \Redis();
if (empty($options['unix_socket'])) {
$redis->connect($options['host'], $options['port'], $timeout);
} else {
$redis->connect($options['unix_socket'], null, $timeout);
}
if (!empty($options['password'])) {
$redis->auth($options['password']);
}
if (array_key_exists('database', $options)) {
$redis->select((int) $options['database']);
}
$redisCache = new Redis();
$redisCache->setRedis($redis);
return $redisCache;
}
/**
* Build a specific backend instance.
*
* @param string $type The type of backend you want to create. Eg 'array', 'file', 'chained', 'null', 'redis'.
* @param array $options An array of options for the backend you want to create.
* @return Backend
* @throws Factory\BackendNotFoundException In case the given type was not found.
*/
public function buildBackend($type, array $options)
{
switch ($type) {
case 'array':
return $this->buildArrayCache();
case 'file':
return $this->buildFileCache($options);
case 'chained':
return $this->buildChainedCache($options);
case 'null':
return $this->buildNullCache();
case 'redis':
return $this->buildRedisCache($options);
default:
throw new Factory\BackendNotFoundException("Cache backend $type not valid");
}
}
}