1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-17 18:36:39 +02:00

Registers cache adapter object to container

This commit is contained in:
Payton Bice
2019-12-24 13:26:52 -06:00
parent c6affbf73a
commit dc771a55cf

View File

@@ -43,6 +43,8 @@ use Slim\Views\TwigExtension;
use Thunder\Shortcode\ShortcodeFacade;
use Twig\Extension\DebugExtension;
use function date;
use function ucfirst;
use function extension_loaded;
/**
* Supply a custom callable resolver, which resolves PSR-15 middlewares.
@@ -104,6 +106,28 @@ $flextype['flash'] = static function ($container) {
return new Messages();
};
/**
* Adds the cache adapter to the Flextype container
*/
$flextype['cache_adapter'] = static function ($container) use ($flextype) {
$driver_name = $container['registry']->get('settings.cache.driver');
if (! $driver_name || $driver_name === 'auto') {
if (extension_loaded('apcu')) {
$driver_name = 'apcu';
} elseif (extension_loaded('wincache')) {
$driver_name = 'wincache';
} else {
$driver_name = 'filesystem';
}
}
$class = ucfirst($driver_name);
$adapter = "Flextype\\Cache\\{$class}Adapter";
return new $adapter($flextype);
};
/**
* Add cache service to Flextype container
*/