mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 21:56:25 +02:00
Initial commit of Cache namespace
This commit is contained in:
19
flextype/cache/AcpuAdapter.php
vendored
Normal file
19
flextype/cache/AcpuAdapter.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Doctrine\Cache\Common\AcpuCache;
|
||||
|
||||
class AcpuAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
return new AcpuCache();
|
||||
}
|
||||
}
|
19
flextype/cache/ArrayAdapter.php
vendored
Normal file
19
flextype/cache/ArrayAdapter.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\ArrayCache;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ArrayAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
return new ArrayCache();
|
||||
}
|
||||
}
|
23
flextype/cache/CacheAdapterInterface.php
vendored
Normal file
23
flextype/cache/CacheAdapterInterface.php
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
interface CacheAdapterInterface
|
||||
{
|
||||
/**
|
||||
* Injects the dependency container
|
||||
*
|
||||
* @param \Psr\Container\ContainerInterface $container
|
||||
* @return void
|
||||
*/
|
||||
function __construct(ContainerInterface $container);
|
||||
|
||||
/**
|
||||
* Returns the cache driver object
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getDriver(): object;
|
||||
}
|
26
flextype/cache/FilesystemAdapter.php
vendored
Normal file
26
flextype/cache/FilesystemAdapter.php
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\FilesystemCache;
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class FilesystemAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
$cache_directory = PATH['cache'] . '/doctrine/';
|
||||
|
||||
if (! Filesystem::has($cache_directory)) {
|
||||
Filesystem::createDir($cache_directory);
|
||||
}
|
||||
|
||||
return new FilesystemCache($cache_directory);
|
||||
}
|
||||
}
|
29
flextype/cache/MemcachedAdapter.php
vendored
Normal file
29
flextype/cache/MemcachedAdapter.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\MemcachedCache;
|
||||
use Memecached;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class MemcachedAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
$memcached = new Memecached();
|
||||
$memcached->addServer(
|
||||
$this->flextype['registry']->get('settings.cache.memcached.server', 'localhost'),
|
||||
$this->flextype['registry']->get('settings.cache.memcache.port', 11211)
|
||||
);
|
||||
|
||||
$driver = new MemcachedCache();
|
||||
$driver->setMemcached($memcached);
|
||||
|
||||
return $driver;
|
||||
}
|
||||
}
|
42
flextype/cache/RedisAdapter.php
vendored
Normal file
42
flextype/cache/RedisAdapter.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Redis;
|
||||
use RedisException;
|
||||
use Doctrine\Common\Cache\RedisCache;
|
||||
|
||||
class RedisAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
$redis = new Redis();
|
||||
$socket = $this->flextype['registry']->get('settings.cache.redis.socket', false);
|
||||
$password = $this->flextype['registry']->get('settings.cache.redis.password', false);
|
||||
|
||||
if ($socket) {
|
||||
$redis->connect($socket);
|
||||
} else {
|
||||
$redis->connect(
|
||||
$this->flextype['registry']->get('settings.cache.redis.server', 'localhost'),
|
||||
$this->flextype['registry']->get('settings.cache.redis.port', 6379)
|
||||
);
|
||||
}
|
||||
|
||||
// Authenticate with password if set
|
||||
if ($password && ! $redis->auth($password)) {
|
||||
throw new RedisException('Redis authentication failed');
|
||||
}
|
||||
|
||||
$driver = new RedisCache();
|
||||
$driver->setRedis($redis);
|
||||
|
||||
return $driver;
|
||||
}
|
||||
}
|
29
flextype/cache/SQLite3Adapter.php
vendored
Normal file
29
flextype/cache/SQLite3Adapter.php
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use SQLite3;
|
||||
use Doctrine\Common\Cache\SQLite3Cache;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class SQLite3Adapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
$cache_directory = PATH['cache'] . '/doctrine/';
|
||||
|
||||
if (! Filesystem::has($cache_directory)) {
|
||||
Filesystem::createDir($cache_directory);
|
||||
}
|
||||
|
||||
$db = new SQLite3($cache_directory . $this->flextype['registry']->get('settings.cache.sqlite3.database', 'flextype') . '.db');
|
||||
|
||||
return new SQLite3Cache($db, $this->flextype['registry']->get('settings.cache.sqlite3.table', 'flextype'));
|
||||
}
|
||||
}
|
19
flextype/cache/WinCacheAdapter.php
vendored
Normal file
19
flextype/cache/WinCacheAdapter.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\WinCacheCache;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class WinCacheAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
return new WinCacheCache();
|
||||
}
|
||||
}
|
19
flextype/cache/ZendDataCacheAdapter.php
vendored
Normal file
19
flextype/cache/ZendDataCacheAdapter.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Flextype\Cache;
|
||||
|
||||
use Doctrine\Common\Cache\ZendDataCache;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ZendDataCacheAdapter implements CacheAdapterInterface
|
||||
{
|
||||
function __construct(ContainerInterface $flextype)
|
||||
{
|
||||
$this->flextype = $flextype;
|
||||
}
|
||||
|
||||
public function getDriver(): object
|
||||
{
|
||||
return new ZendDataCache();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user