Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for doctrine cache 2 #72

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "~8.1.0 || ~8.2.0",
"doctrine/annotations": "^1.14.2 || ^2.0",
"doctrine/cache": "^1.13.0",
"doctrine/cache": "^2.0",
"doctrine/common": "^3.4.3",
"doctrine/dbal": "^3.5.3",
"doctrine/event-manager": "^1.2.0 || ^2.0",
Expand Down
20 changes: 7 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 16 additions & 62 deletions example/full-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,23 @@
declare(strict_types=1);

use App\Doctrine\CustomCacheProvider;
use Doctrine\Common\Cache\ApcuCache;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\ChainCache;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\Common\Cache\MemcacheCache;
use Doctrine\Common\Cache\MemcachedCache;
use Doctrine\Common\Cache\PhpFileCache;
use Doctrine\Common\Cache\PredisCache;
use Doctrine\Common\Cache\RedisCache;
use Doctrine\Common\Cache\WinCacheCache;
use Doctrine\Common\Cache\XcacheCache;
use Doctrine\Common\Cache\ZendDataCache;
use Doctrine\DBAL\Driver\PDOMySql\Driver;
use Doctrine\Migrations\Configuration\Migration\ConfigurationLoader;
use Doctrine\Migrations\DependencyFactory;
use Doctrine\Migrations\Tools\Console\Command;
use Psr\Container\ContainerInterface;
use Roave\PsrContainerDoctrine\ConfigurationLoaderFactory;
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
use Roave\PsrContainerDoctrine\Migrations\DependencyFactoryFactory;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

return [
'doctrine' => [
'configuration' => [
'orm_default' => [
'result_cache' => 'array',
'metadata_cache' => 'array',
'metadata_cache' => 'filesystem',
'query_cache' => 'array',
'hydration_cache' => 'array',
'driver' => 'orm_default', // Actually defaults to the configuration config key, not hard-coded
Expand Down Expand Up @@ -100,64 +91,17 @@
],
],
'cache' => [
'apcu' => [
'class' => ApcuCache::class,
'namespace' => 'psr-container-doctrine',
],
'array' => [
'class' => ArrayCache::class,
'namespace' => 'psr-container-doctrine',
'class' => ArrayAdapter::class,
],
'filesystem' => [
'class' => FilesystemCache::class,
'directory' => 'data/cache/DoctrineCache',
'namespace' => 'psr-container-doctrine',
],
'memcache' => [
'class' => MemcacheCache::class,
'instance' => 'my_memcache_alias',
'namespace' => 'psr-container-doctrine',
],
'memcached' => [
'class' => MemcachedCache::class,
'instance' => 'my_memcached_alias',
'namespace' => 'psr-container-doctrine',
],
'phpfile' => [
'class' => PhpFileCache::class,
'class' => FilesystemAdapter::class,
'directory' => 'data/cache/DoctrineCache',
'namespace' => 'psr-container-doctrine',
],
'predis' => [
'class' => PredisCache::class,
'instance' => 'my_predis_alias',
'namespace' => 'psr-container-doctrine',
],
'redis' => [
'class' => RedisCache::class,
'instance' => 'my_redis_alias',
'namespace' => 'psr-container-doctrine',
],
'wincache' => [
'class' => WinCacheCache::class,
'namespace' => 'psr-container-doctrine',
],
'xcache' => [
'class' => XcacheCache::class,
'namespace' => 'psr-container-doctrine',
],
'zenddata' => [
'class' => ZendDataCache::class,
'namespace' => 'psr-container-doctrine',
],
'my_cache_provider' => [
'class' => CustomCacheProvider::class, //The class is looked up in the container
],
'chain' => [
'class' => ChainCache::class,
'providers' => ['array', 'redis'], // you can use any provider listed above
'namespace' => 'psr-container-doctrine', // will be applied to all providers in the chain
],
],
'types' => [],
'migrations' => [
Expand Down Expand Up @@ -193,6 +137,16 @@

DependencyFactory::class => DependencyFactoryFactory::class,
ConfigurationLoader::class => ConfigurationLoaderFactory::class,

FilesystemAdapter::class => static function (ContainerInterface $container): FilesystemAdapter {
$config = $container->get('config');
$params = $config['doctrine']['cache']['filesystem'];

return new FilesystemAdapter(
$params['namespace'],
$params['directory'],
);
},
],
],
];
1 change: 0 additions & 1 deletion example/minimal-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
],
'my_entity' => [
'class' => XmlDriver::class,
'cache' => 'array',
'paths' => __DIR__ . '/doctrine',
],
],
Expand Down
12 changes: 0 additions & 12 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
</InternalClass>
<DeprecatedClass>
<errorLevel type="suppress">
<referencedClass name="Doctrine\Common\Cache\ApcuCache"/>
<referencedClass name="Doctrine\Common\Cache\ArrayCache"/>
<referencedClass name="Doctrine\Common\Cache\Cache"/>
<referencedClass name="Doctrine\Common\Cache\CacheProvider"/>
<referencedClass name="Doctrine\Common\Cache\ChainCache"/>
<referencedClass name="Doctrine\Common\Cache\FilesystemCache"/>
<referencedClass name="Doctrine\Common\Cache\MemcachedCache"/>
<referencedClass name="Doctrine\Common\Cache\PhpFileCache"/>
<referencedClass name="Doctrine\Common\Cache\PredisCache"/>
<referencedClass name="Doctrine\Common\Cache\RedisCache"/>
<referencedClass name="Doctrine\Common\Cache\WinCacheCache"/>
<referencedClass name="Doctrine\Common\Cache\ZendDataCache"/>
<referencedClass name="Doctrine\Common\Annotations\CachedReader"/>
<referencedClass name="Doctrine\ORM\Mapping\Driver\SimplifiedYamlDriver"/>
<referencedClass name="Doctrine\Persistence\Mapping\Driver\AnnotationDriver"/>
Expand Down
73 changes: 73 additions & 0 deletions src/Cache/NullCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace Roave\PsrContainerDoctrine\Cache;

use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;

final class NullCache implements CacheItemPoolInterface
{
/**
* {@inheritdoc}
*/
public function getItem($key): CacheItemInterface
{
return new NullCacheItem($key);
}

/**
* {@inheritdoc}
*/
public function getItems(array $keys = []): iterable
{
foreach ($keys as $key) {
yield $key => $this->getItem($key);
}
}

/**
* {@inheritdoc}
*/
public function hasItem($key): bool
{
return false;
}

public function clear(): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function deleteItem($key): bool
{
return true;
}

/**
* {@inheritdoc}
*/
public function deleteItems(array $keys): bool
{
return true;
}

public function save(CacheItemInterface $item): bool
{
return true;
}

public function saveDeferred(CacheItemInterface $item): bool
{
return true;
}

public function commit(): bool
{
return true;
}
}
51 changes: 51 additions & 0 deletions src/Cache/NullCacheItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Roave\PsrContainerDoctrine\Cache;

use Psr\Cache\CacheItemInterface;

final class NullCacheItem implements CacheItemInterface
{
public function __construct(
private readonly string $key,
) {
}

public function getKey(): string
{
return $this->key;
}

public function get(): mixed
{
return null;
}

public function isHit(): bool
{
return false;
}

public function set(mixed $value): static
{
return $this;
}

/**
* {@inheritdoc}
*/
public function expiresAt($expiration): static
{
return $this;
}

/**
* {@inheritdoc}
*/
public function expiresAfter($time): static
{
return $this;
}
}
Loading