Issues (9)

src/Business/Adapter/Concrete/PdoFactory.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Cache\Business\Adapter\Concrete;
15
16
use Micro\Component\DependencyInjection\Container;
17
use Micro\Plugin\Cache\Business\Adapter\ConcreteAdapterFactoryInterface;
18
use Micro\Plugin\Cache\Configuration\Adapter\CachePoolConfigurationInterface;
19
use Micro\Plugin\Doctrine\DoctrineFacadeInterface;
20
use Psr\Cache\CacheItemPoolInterface;
21
use Symfony\Component\Cache\Adapter\PdoAdapter;
22
use Symfony\Component\Cache\Exception\CacheException;
23
24
readonly class PdoFactory implements ConcreteAdapterFactoryInterface
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_READONLY on line 24 at column 0
Loading history...
25
{
26 4
    public function __construct(private Container $container)
27
    {
28 4
    }
29
30 1
    public function create(CachePoolConfigurationInterface $configuration): CacheItemPoolInterface
31
    {
32 1
        if (!\extension_loaded('pdo')) {
33
            throw new CacheException('Extension `pdo` should be installed.');
34
        }
35
36 1
        $manager = $this->container->get(DoctrineFacadeInterface::class)->getManager($configuration->getConnectionName());
37 1
        $connection = $manager->getConnection()->getNativeConnection();
38
39 1
        if (!($connection instanceof \PDO)) {
40
            throw new CacheException(sprintf('Entity manager connection should be instance of `%s`', \PDO::class));
41
        }
42
43 1
        return new PdoAdapter(
44 1
            $connection,
45 1
            $configuration->getNamespace(),
46 1
            $configuration->getDefaultLifetime(),
47 1
        );
48
    }
49
50 2
    public function type(): string
51
    {
52 2
        return 'doctrine';
53
    }
54
}
55