Skip to content

Commit

Permalink
Merge pull request #110 from Slamdunk/support-persistence-3
Browse files Browse the repository at this point in the history
Add support for `doctrine/cache:v2`
  • Loading branch information
Slamdunk authored Oct 30, 2023
2 parents 2905a5f + 9db19b7 commit e53f82c
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 323 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jobs:
- 'latest'
- 'lowest'

name: PHP ${{ matrix.php-version }}

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
"homepage": "https://github.com/Roave/psr-container-doctrine",
"require": {
"php": "~8.1.0 || ~8.2.0",
"doctrine/annotations": "^1.14.2 || ^2.0",
"doctrine/cache": "^1.13.0",
"doctrine/annotations": "^1.14.3 || ^2.0.1",
"doctrine/cache": "^2.2",
"doctrine/common": "^3.4.3",
"doctrine/dbal": "^3.7.1",
"doctrine/event-manager": "^1.2.0 || ^2.0",
"doctrine/migrations": "^3.6.0",
"doctrine/orm": "^2.16.2",
"doctrine/persistence": "^2.5.6 || ^3.1",
"psr/cache": "^1.0.1 || ^2.0.0 || ^3.0.0",
"psr/container": "^1.0 || ^2.0"
"doctrine/persistence": "^2.5.7 || ^3.2",
"psr/cache": "^2.0.0 || ^3.0.0",
"psr/container": "^1.1.2 || ^2.0.2"
},
"require-dev": {
"doctrine/coding-standard": "^12.0.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.

3 changes: 2 additions & 1 deletion example/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"require": {
"php": "~8.1.0 || ~8.2.0",
"illuminate/container": "^10.29",
"laminas/laminas-servicemanager": "^3.22.1"
"laminas/laminas-servicemanager": "^3.22.1",
"symfony/cache": "^6.3"
},
"config": {
"platform": {
Expand Down
77 changes: 13 additions & 64 deletions example/full-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

declare(strict_types=1);

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 as DbalDriver;
use Doctrine\DBAL\Driver\Middleware;
use Doctrine\DBAL\Driver\SQLite3\Driver;
Expand All @@ -29,13 +17,15 @@
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;
use Roave\PsrContainerDoctrine\Migrations\ConfigurationLoaderFactory;
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 @@ -104,64 +94,15 @@
],
],
'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,
'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',
'class' => FilesystemAdapter::class,
],
// '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 @@ -223,6 +164,14 @@ public function wrap(DbalDriver $driver): DbalDriver
}
};
},

FilesystemAdapter::class => static function (): FilesystemAdapter {
return new FilesystemAdapter(
'psr-container-doctrine',
3600,
__DIR__ . '/data/cache/DoctrineCache',
);
},
],
],
];
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
64 changes: 64 additions & 0 deletions src/Cache/NullCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Roave\PsrContainerDoctrine\Cache;

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

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

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

public function hasItem(string $key): bool
{
return false;
}

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

public function deleteItem(string $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;
}
}
47 changes: 47 additions & 0 deletions src/Cache/NullCacheItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Roave\PsrContainerDoctrine\Cache;

use DateInterval;
use DateTimeInterface;
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;
}

public function expiresAt(DateTimeInterface|null $expiration): static
{
return $this;
}

public function expiresAfter(int|DateInterval|null $time): static
{
return $this;
}
}
Loading

0 comments on commit e53f82c

Please sign in to comment.