for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Factory class for Cerberus.
*
* @author Leandro Silva <[email protected]>
* @license https://github.com/mt-olympus/cerberus/blob/master/LICENSE MIT Licence
*/
namespace Cerberus;
use Interop\Container\ContainerInterface;
use Zend\Cache\StorageFactory;
class Factory
{
* Invoke method.
* @param \Interop\Container\ContainerInterface $container
* @return \Cerberus\Cerberus
public function __invoke(ContainerInterface $container)
$config = $container->get('config');
if (!isset($config['cerberus'])) {
$storageConfig = [
'adapter' => [
'name' => 'filesystem',
'options' => [
'cache_dir' => 'data/cache',
'namespace' => 'cerberus',
],
'plugins' => [
// Don't throw exceptions on cache errors
'exception_handler' => [
'throw_exceptions' => false,
'Serializer',
];
$maxFailure = 5;
$timeout = 60;
} else {
$storageConfig = $config['cerberus']['storage'];
$maxFailure = (int) $config['cerberus']['max_failure'];
$timeout = (int) $config['cerberus']['timeout'];
}
$storage = StorageFactory::factory($storageConfig);
return new Cerberus($storage, $maxFailure, $timeout);