|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +use Cache\Adapter\PHPArray\ArrayCachePool; |
| 4 | +use Doctrine\Common\Annotations\AnnotationReader; |
| 5 | +use Doctrine\DBAL\DriverManager; |
| 6 | +use Doctrine\DBAL\Types\DateTimeImmutableType; |
| 7 | +use Doctrine\DBAL\Types\Type; |
| 8 | +use Doctrine\ORM\Configuration; |
| 9 | +use Doctrine\ORM\EntityManager; |
| 10 | +use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
| 11 | +use Doctrine\ORM\Mapping\Driver\AttributeDriver; |
| 12 | +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; |
| 13 | + |
| 14 | +$config = new Configuration(); |
| 15 | +$config->setProxyDir(__DIR__); |
| 16 | +$config->setProxyNamespace('App\GeneratedProxy'); |
| 17 | +$config->setMetadataCache(new ArrayCachePool()); |
| 18 | + |
| 19 | +$metadataDriver = new MappingDriverChain(); |
| 20 | +$metadataDriver->addDriver(new AnnotationDriver( |
| 21 | + new AnnotationReader(), |
| 22 | + [__DIR__ . '/data'] |
| 23 | +), 'PHPStan\\Rules\\Doctrine\\ORM\\'); |
| 24 | + |
| 25 | +if (PHP_VERSION_ID >= 80100) { |
| 26 | + $metadataDriver->addDriver( |
| 27 | + new AttributeDriver([__DIR__ . '/data-attributes']), |
| 28 | + 'PHPStan\\Rules\\Doctrine\\ORMAttributes\\' |
| 29 | + ); |
| 30 | +} |
| 31 | + |
| 32 | +$config->setMetadataDriverImpl($metadataDriver); |
| 33 | + |
| 34 | +Type::overrideType( |
| 35 | + 'date', |
| 36 | + DateTimeImmutableType::class |
| 37 | +); |
| 38 | + |
| 39 | +return new EntityManager( |
| 40 | + DriverManager::getConnection([ |
| 41 | + 'driver' => 'pdo_sqlite', |
| 42 | + 'memory' => true, |
| 43 | + ]), |
| 44 | + $config |
| 45 | +); |
0 commit comments