Skip to content

Commit

Permalink
Merge pull request shlinkio#99 from acelaya-forks/feature/dropped-doc…
Browse files Browse the repository at this point in the history
…trine-cache

Removed integration with doctrine/cache
  • Loading branch information
acelaya authored Jan 23, 2022
2 parents 0894176 + 7770868 commit 4539a9d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 74 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
## [4.4.0] - 2022-01-23
### Added
* Created logic to build filtering and validation fields for "order by".

Expand All @@ -16,7 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* *Nothing*

### Removed
* *Nothing*
* [#98](https://github.com/shlinkio/shlink-common/issues/98) Removed integration with doctrine/cache by manually creating the doctrine config object.

### Fixed
* *Nothing*
Expand Down
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ You can allow caching to be done on a redis instance, redis cluster or redis sen
* `servers`: A list of redis servers. If one is provided, it will be treated as a single instance, and otherwise, a cluster will be assumed.
* `sentinel_service`: Lets you enable sentinel mode. When provided, the servers will be treated as sentinel instances.

### Doctrine cache support

As other doctrine components still expect a `doctrine/cache` adapter to be provided, this package still depends on `doctrine/cache:^2.0` which just exposes the interfaces and a PSR compatibility layer.

Also, a `Doctrine\Common\Cache\Cache` service is registered, which is basically an object wrapping the PSR/Symfony cache object registered above.

## Middlewares

This module provides a set of useful middlewares, all registered as services in the container:
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"ext-fileinfo": "*",
"akrabat/ip-address-middleware": "^2.0",
"cakephp/chronos": "^2.2",
"doctrine/cache": "^2.0",
"doctrine/orm": "^2.9",
"endroid/qr-code": "^4.2",
"fig/http-message-util": "^1.1",
Expand Down
2 changes: 0 additions & 2 deletions config/cache.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Shlinkio\Shlink\Common;

use Doctrine\Common\Cache\Cache as DoctrineCache;
use Predis\Client as PredisClient;
use Predis\ClientInterface as PredisClientInterface;
use Psr\Cache\CacheItemPoolInterface as PsrCache;
Expand All @@ -14,7 +13,6 @@
'dependencies' => [
'factories' => [
PsrCache::class => Cache\CacheFactory::class,
DoctrineCache::class => Cache\DoctrineCacheFactory::class,
PredisClientInterface::class => Cache\RedisFactory::class,
],
'aliases' => [
Expand Down
18 changes: 0 additions & 18 deletions src/Cache/DoctrineCacheFactory.php

This file was deleted.

22 changes: 18 additions & 4 deletions src/Doctrine/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Shlinkio\Shlink\Common\Doctrine;

use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Setup;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Container\ContainerInterface;
use Shlinkio\Shlink\Common\Doctrine\Mapping\EnhancedPHPDriver;

Expand All @@ -17,7 +17,7 @@ public function __invoke(ContainerInterface $container): EntityManager
{
$globalConfig = $container->get('config');
$isDevMode = (bool) ($globalConfig['debug'] ?? false);
$cache = $container->get(Cache::class);
$cache = $container->get(CacheItemPoolInterface::class);
$emConfig = $globalConfig['entity_manager'] ?? [];
$connectionConfig = $emConfig['connection'] ?? [];
$ormConfig = $emConfig['orm'] ?? [];
Expand All @@ -26,7 +26,7 @@ public function __invoke(ContainerInterface $container): EntityManager

$this->registerTypes($ormConfig);

$config = Setup::createConfiguration($isDevMode, $ormConfig['proxies_dir'] ?? null, $cache);
$config = $this->createConfiguration($isDevMode, $ormConfig['proxies_dir'] ?? '', $cache);
$config->setMetadataDriverImpl(
new EnhancedPHPDriver($ormConfig['entities_mappings'] ?? [], $emConfig, $funcStyle),
);
Expand All @@ -53,6 +53,20 @@ private function registerTypes(array $ormConfig): void
}
}

private function createConfiguration(bool $isDev, string $proxyDir, CacheItemPoolInterface $cache): Configuration
{
$config = new Configuration();

$config->setMetadataCache($cache);
$config->setQueryCache($cache);
$config->setResultCache($cache);
$config->setProxyDir($proxyDir);
$config->setProxyNamespace('DoctrineProxies');
$config->setAutoGenerateProxyClasses($isDev);

return $config;
}

private function registerListeners(array $ormConfig, EntityManager $em, ContainerInterface $container): void
{
$listeners = $ormConfig['listeners'] ?? [];
Expand Down
38 changes: 0 additions & 38 deletions test/Cache/DoctrineCacheFactoryTest.php

This file was deleted.

5 changes: 2 additions & 3 deletions test/Doctrine/EntityManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

namespace ShlinkioTest\Shlink\Common\Doctrine;

use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver as SQLiteDriver;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Events;
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
use Laminas\ServiceManager\ServiceManager;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface;
use ReflectionObject;
use Shlinkio\Shlink\Common\Doctrine\EntityManagerFactory;
use Shlinkio\Shlink\Common\Doctrine\Type\ChronosDateTimeType;
Expand Down Expand Up @@ -64,7 +63,7 @@ public function serviceIsCreated(
'foo_listener' => new stdClass(),
'bar_listener' => new stdClass(),
'baz_listener' => new stdClass(),
Cache::class => DoctrineProvider::wrap(new ArrayAdapter()),
CacheItemPoolInterface::class => new ArrayAdapter(),
]]);

self::assertFalse(Type::hasType(ChronosDateTimeType::CHRONOS_DATETIME));
Expand Down

0 comments on commit 4539a9d

Please sign in to comment.