-
-
Notifications
You must be signed in to change notification settings - Fork 268
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
Switch default cache config to make use of laminas-cache, when doctrine/cache ^2.0 is installed #796
Switch default cache config to make use of laminas-cache, when doctrine/cache ^2.0 is installed #796
Changes from 3 commits
ff7463b
7dc1855
914ee43
2c915c6
7d2fd55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69"> | ||
<file src="src/ConfigProvider.php"> | ||
<UndefinedClass occurrences="11"> | ||
<code>DoctrineCache\ApcCache</code> | ||
<code>DoctrineCache\ApcuCache</code> | ||
<code>DoctrineCache\ArrayCache</code> | ||
<code>DoctrineCache\FilesystemCache</code> | ||
<code>DoctrineCache\MemcacheCache</code> | ||
<code>DoctrineCache\MemcachedCache</code> | ||
<code>DoctrineCache\PredisCache</code> | ||
<code>DoctrineCache\RedisCache</code> | ||
<code>DoctrineCache\WinCacheCache</code> | ||
<code>DoctrineCache\XcacheCache</code> | ||
<code>DoctrineCache\ZendDataCache</code> | ||
</UndefinedClass> | ||
</file> | ||
<file src="src/Service/CacheFactory.php"> | ||
<UndefinedClass occurrences="3"> | ||
<code>Cache\FilesystemCache</code> | ||
<code>Cache\MemcacheCache</code> | ||
<code>Cache\PredisCache</code> | ||
</UndefinedClass> | ||
</file> | ||
</files> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,12 @@ | |
|
||
namespace DoctrineModule; | ||
|
||
use Doctrine\Common\Cache; | ||
use Composer\InstalledVersions; | ||
use Composer\Semver\VersionParser; | ||
use Doctrine\Common\Cache as DoctrineCache; | ||
use DoctrineModule\Cache\LaminasStorageCache; | ||
use Laminas\Authentication\Storage\Session as LaminasSessionStorage; | ||
use Laminas\Cache\Storage\Adapter\Memory; | ||
|
||
/** | ||
* Config provider for DoctrineORMModule config | ||
|
@@ -18,6 +22,7 @@ final class ConfigProvider | |
public function __invoke(): array | ||
{ | ||
return [ | ||
'caches' => $this->getCachesConfig(), | ||
'doctrine' => $this->getDoctrineConfig(), | ||
'doctrine_factories' => $this->getDoctrineFactoryConfig(), | ||
'dependencies' => $this->getDependencyConfig(), | ||
|
@@ -47,57 +52,7 @@ public function getDependencyConfig(): array | |
public function getDoctrineConfig(): array | ||
{ | ||
return [ | ||
'cache' => [ | ||
'apc' => [ | ||
'class' => Cache\ApcCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'apcu' => [ | ||
'class' => Cache\ApcuCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'array' => [ | ||
'class' => Cache\ArrayCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'filesystem' => [ | ||
'class' => Cache\FilesystemCache::class, | ||
'directory' => 'data/DoctrineModule/cache', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'memcache' => [ | ||
'class' => Cache\MemcacheCache::class, | ||
'instance' => 'my_memcache_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'memcached' => [ | ||
'class' => Cache\MemcachedCache::class, | ||
'instance' => 'my_memcached_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'predis' => [ | ||
'class' => Cache\PredisCache::class, | ||
'instance' => 'my_predis_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'redis' => [ | ||
'class' => Cache\RedisCache::class, | ||
'instance' => 'my_redis_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'wincache' => [ | ||
'class' => Cache\WinCacheCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'xcache' => [ | ||
'class' => Cache\XcacheCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'zenddata' => [ | ||
'class' => Cache\ZendDataCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
], | ||
'cache' => $this->getDoctrineCacheConfig(), | ||
|
||
//These authentication settings are a hack to tide things over until version 1.0 | ||
//Normall doctrineModule should have no mention of odm or orm | ||
|
@@ -129,9 +84,9 @@ public function getDoctrineConfig(): array | |
public function getDoctrineFactoryConfig(): array | ||
{ | ||
return [ | ||
'cache' => Service\CacheFactory::class, | ||
'eventmanager' => Service\EventManagerFactory::class, | ||
'driver' => Service\DriverFactory::class, | ||
'cache' => Service\CacheFactory::class, | ||
'eventmanager' => Service\EventManagerFactory::class, | ||
'driver' => Service\DriverFactory::class, | ||
'authenticationadapter' => Service\Authentication\AdapterFactory::class, | ||
'authenticationstorage' => Service\Authentication\StorageFactory::class, | ||
'authenticationservice' => Service\Authentication\AuthenticationServiceFactory::class, | ||
|
@@ -144,15 +99,142 @@ public function getDoctrineFactoryConfig(): array | |
public function getValidatorConfig(): array | ||
{ | ||
return [ | ||
'aliases' => [ | ||
'aliases' => [ | ||
'DoctrineNoObjectExists' => Validator\NoObjectExists::class, | ||
'DoctrineObjectExists' => Validator\ObjectExists::class, | ||
'DoctrineUniqueObject' => Validator\UniqueObject::class, | ||
'DoctrineObjectExists' => Validator\ObjectExists::class, | ||
'DoctrineUniqueObject' => Validator\UniqueObject::class, | ||
], | ||
'factories' => [ | ||
Validator\NoObjectExists::class => Validator\Service\NoObjectExistsFactory::class, | ||
Validator\ObjectExists::class => Validator\Service\ObjectExistsFactory::class, | ||
Validator\UniqueObject::class => Validator\Service\UniqueObjectFactory::class, | ||
Validator\ObjectExists::class => Validator\Service\ObjectExistsFactory::class, | ||
Validator\UniqueObject::class => Validator\Service\UniqueObjectFactory::class, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getCachesConfig(): array | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This moving out made it a bit hard to figure out what's going on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but we need this extraction for usage in |
||
{ | ||
return [ | ||
'doctrinemodule.cache.apcu' => [ | ||
'adapter' => 'apcu', | ||
'options' => ['namespace' => 'DoctrineModule'], | ||
], | ||
'doctrinemodule.cache.array' => [ | ||
'adapter' => Memory::class, | ||
'options' => ['namespace' => 'DoctrineModule'], | ||
], | ||
'doctrinemodule.cache.filesystem' => [ | ||
'adapter' => 'filesystem', | ||
'options' => [ | ||
'namespace' => 'DoctrineModule', | ||
'cache_dir' => 'data/DoctrineModule/cache', | ||
], | ||
], | ||
'doctrinemodule.cache.memcached' => [ | ||
'adapter' => 'memcached', | ||
'options' => [ | ||
'namespace' => 'DoctrineModule', | ||
'servers' => [], | ||
], | ||
], | ||
'doctrinemodule.cache.redis' => [ | ||
'adapter' => 'redis', | ||
'options' => [ | ||
'namespace' => 'DoctrineModule', | ||
'server' => [ | ||
'host' => 'localhost', | ||
'post' => 6379, | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Use doctrine/cache config, when doctrine/cache:^1.0 is installed, and use laminas/laminas-cache, | ||
* when doctrine/cache:^2.0 is installed, as the latter does not include any cache adapters anymore | ||
* | ||
* @return mixed[] | ||
*/ | ||
private function getDoctrineCacheConfig(): array | ||
{ | ||
if (InstalledVersions::satisfies(new VersionParser(), 'doctrine/cache', '^1.0')) { | ||
return [ | ||
'apc' => [ | ||
'class' => DoctrineCache\ApcCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'apcu' => [ | ||
'class' => DoctrineCache\ApcuCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'array' => [ | ||
'class' => DoctrineCache\ArrayCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'filesystem' => [ | ||
'class' => DoctrineCache\FilesystemCache::class, | ||
'directory' => 'data/DoctrineModule/cache', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'memcache' => [ | ||
'class' => DoctrineCache\MemcacheCache::class, | ||
'instance' => 'my_memcache_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'memcached' => [ | ||
'class' => DoctrineCache\MemcachedCache::class, | ||
'instance' => 'my_memcached_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'predis' => [ | ||
'class' => DoctrineCache\PredisCache::class, | ||
'instance' => 'my_predis_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'redis' => [ | ||
'class' => DoctrineCache\RedisCache::class, | ||
'instance' => 'my_redis_alias', | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'wincache' => [ | ||
'class' => DoctrineCache\WinCacheCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'xcache' => [ | ||
'class' => DoctrineCache\XcacheCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
'zenddata' => [ | ||
'class' => DoctrineCache\ZendDataCache::class, | ||
'namespace' => 'DoctrineModule', | ||
], | ||
]; | ||
} | ||
|
||
return [ | ||
'apcu' => [ | ||
'class' => LaminasStorageCache::class, | ||
'instance' => 'doctrinemodule.cache.apcu', | ||
], | ||
'array' => [ | ||
'class' => LaminasStorageCache::class, | ||
'instance' => 'doctrinemodule.cache.array', | ||
], | ||
'filesystem' => [ | ||
'class' => LaminasStorageCache::class, | ||
'instance' => 'doctrinemodule.cache.filesystem', | ||
], | ||
'memcached' => [ | ||
'class' => LaminasStorageCache::class, | ||
'instance' => 'doctrinemodule.cache.memcached', | ||
], | ||
'redis' => [ | ||
'class' => LaminasStorageCache::class, | ||
'instance' => 'doctrinemodule.cache.redis', | ||
], | ||
]; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type should probably be
array<non-empty-string, array{adapter: non-empty-string, options?: mixed[]}>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more specific types for all configurations with 2c915c6