Skip to content

Commit

Permalink
Merge pull request #1029 from alcaeus/drop-cache-bundle
Browse files Browse the repository at this point in the history
[2.0] Drop support for DoctrineCacheBundle
  • Loading branch information
alcaeus authored Oct 14, 2019
2 parents 601d807 + 9875921 commit 357a477
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 365 deletions.
37 changes: 1 addition & 36 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use const E_USER_DEPRECATED;
use function array_key_exists;
use function in_array;
use function is_array;
use function sprintf;
use function trigger_error;

/**
* This class contains the configuration information for the bundle
Expand Down Expand Up @@ -701,42 +698,10 @@ private function getOrmCacheDriverNode($name)
return ['type' => $v];
})
->end()
->beforeNormalization()
->ifTrue(static function ($v) : bool {
return is_array($v) && array_key_exists('cache_provider', $v);
})
->then(static function ($v) : array {
return ['type' => 'provider'] + $v;
})
->end()
->children()
->scalarNode('type')
->defaultNull()
->beforeNormalization()
->ifNotInArray([null, 'pool', 'service'])
->then(static function ($v) use ($name) {
@trigger_error(
sprintf(
'Using the "%s" type for cache "%s" is deprecated since DoctrineBundle 1.12 and will be dropped in 2.0. Please use the "service" or "pool" types exclusively.',
$v,
$name
),
E_USER_DEPRECATED
);

return $v;
})
->end()
->end()
->scalarNode('type')->defaultNull()->end()
->scalarNode('id')->end()
->scalarNode('pool')->end()
->scalarNode('host')->setDeprecated()->end()
->scalarNode('port')->setDeprecated()->end()
->scalarNode('database')->setDeprecated()->end()
->scalarNode('instance_class')->setDeprecated()->end()
->scalarNode('class')->setDeprecated()->end()
->scalarNode('namespace')->defaultNull()->setDeprecated()->end()
->scalarNode('cache_provider')->defaultNull()->setDeprecated()->end()
->end();

return $node;
Expand Down
39 changes: 12 additions & 27 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Doctrine\Bundle\DoctrineBundle\Dbal\RegexSchemaAssetFilter;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\CacheProviderLoader;
use Doctrine\Bundle\DoctrineCacheBundle\DependencyInjection\SymfonyBridgeAdapter;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\ORM\Version;
use LogicException;
Expand Down Expand Up @@ -40,14 +38,6 @@ class DoctrineExtension extends AbstractDoctrineExtension
/** @var string */
private $defaultConnection;

/** @var SymfonyBridgeAdapter */
private $adapter;

public function __construct(SymfonyBridgeAdapter $adapter = null)
{
$this->adapter = $adapter ?: new SymfonyBridgeAdapter(new CacheProviderLoader(), 'doctrine.orm', 'orm');
}

/**
* {@inheritDoc}
*/
Expand All @@ -56,8 +46,6 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$this->adapter->loadServicesConfiguration($container);

if (! empty($config['dbal'])) {
$this->dbalLoad($config['dbal'], $container);
}
Expand Down Expand Up @@ -739,34 +727,31 @@ protected function loadCacheDriver($cacheName, $objectManagerName, array $cacheD
$serviceId = null;
$aliasId = $this->getObjectManagerElementName(sprintf('%s_%s', $objectManagerName, $cacheName));

if ($cacheDriver['type'] === null) {
$cacheDriver = [
'type' => 'pool',
'pool' => $this->getPoolNameForCacheDriver($cacheName),
];
}

switch ($cacheDriver['type']) {
switch ($cacheDriver['type'] ?? 'pool') {
case 'service':
$serviceId = $cacheDriver['id'];
break;

case 'pool':
$serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool']);
$serviceId = $this->createPoolCacheDefinition($container, $cacheDriver['pool'] ?? $this->getPoolNameForCacheDriver($cacheName));
break;

case 'provider':
$serviceId = sprintf('doctrine_cache.providers.%s', $cacheDriver['cache_provider']);
break;
}

if ($serviceId !== null) {
$container->setAlias($aliasId, new Alias($serviceId, false));

return $aliasId;
default:
throw new \InvalidArgumentException(sprintf(
'Unknown cache of type "%s" configured for cache "%s" in entity manager "%s".',
$cacheDriver['type'],
$cacheName,
$objectManagerName
));
}

return $this->adapter->loadCacheDriver($cacheName, $objectManagerName, $cacheDriver, $container);
$container->setAlias($aliasId, new Alias($serviceId, false));

return $aliasId;
}

/**
Expand Down
25 changes: 8 additions & 17 deletions Resources/config/schema/doctrine-1.0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,17 @@
</xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="cache_driver">
<!-- This is not consistent with the Symfony config. These string elements should be attributes.
TODO: change it for 2.0
-->
<xsd:all>
<xsd:element name="class" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="host" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="port" type="xsd:string" minOccurs="0" maxOccurs="1" />
<xsd:element name="database" type="xsd:integer" minOccurs="0" maxOccurs="1" />
<xsd:element name="instance-class" type="xsd:string" minOccurs="0" maxOccurs="1" />
</xsd:all>
<xsd:simpleType name="cache_driver_type">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="pool"/>
<xsd:enumeration value="service"/>
</xsd:restriction>
</xsd:simpleType>

<xsd:attribute name="type" type="xsd:string" />
<xsd:complexType name="cache_driver">
<xsd:attribute name="type" type="cache_driver_type" default="pool" />
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="pool" type="xsd:string" />
<xsd:attribute name="namespace" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="entity_listeners">
Expand Down Expand Up @@ -224,10 +219,6 @@
<xsd:attribute name="quote-strategy" type="xsd:string" />
<xsd:attribute name="entity-listener-resolver" type="xsd:string" />
<xsd:attribute name="repository-factory" type="xsd:string" />
<!-- deprecated attributes, use the child element instead -->
<xsd:attribute name="result-cache-driver" type="xsd:string" />
<xsd:attribute name="metadata-cache-driver" type="xsd:string" />
<xsd:attribute name="query-cache-driver" type="xsd:string" />
</xsd:attributeGroup>

<xsd:complexType name="filter" mixed="true">
Expand Down
118 changes: 28 additions & 90 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,35 +275,17 @@ Configuration Reference
# A collection of different named entity managers (e.g. some_em, another_em)
some_em:
query_cache_driver:
type: array
id: ~
pool: ~
host: ~
port: ~
instance_class: ~
class: ~
namespace: ~
cache_provider: ~
type: ~
id: ~
pool: ~
metadata_cache_driver:
type: array
id: ~
pool: ~
host: ~
port: ~
instance_class: ~
class: ~
namespace: ~
cache_provider: ~
type: ~
id: ~
pool: ~
result_cache_driver:
type: array
id: ~
pool: ~
host: ~
port: ~
instance_class: ~
class: ~
namespace: ~
cache_provider: ~
type: ~
id: ~
pool: ~
entity_listeners:
entities:
Expand All @@ -328,15 +310,9 @@ Configuration Reference
repository_factory: ~
second_level_cache:
region_cache_driver:
type: array
pool: ~
id: ~
host: ~
port: ~
instance_class: ~
class: ~
namespace: ~
cache_provider: ~
type: ~
id: ~
pool: ~
region_lock_lifetime: 60
log_enabled: true
region_lifetime: 0
Expand All @@ -347,15 +323,9 @@ Configuration Reference
# Prototype
name:
cache_driver:
type: array
id: ~
pool: ~
host: ~
port: ~
instance_class: ~
class: ~
namespace: ~
cache_provider: ~
type: ~
id: ~
pool: ~
lock_path: '%kernel.cache_dir%/doctrine/orm/slc/filelock'
lock_lifetime: 60
type: default
Expand Down Expand Up @@ -629,39 +599,21 @@ Configuration Reference
>
<doctrine:query-cache-driver
type="array"
type="pool"
id=""
pool=""
host=""
port=""
instance-class=""
class=""
namespace="null"
cache-provider="null"
/>
<doctrine:metadata-cache-driver
type="memcache"
type="pool"
id=""
pool=""
host="localhost"
port="11211"
instance-class="Memcache"
class="Doctrine\Common\Cache\MemcacheCache"
namespace="null"
cache-provider="null"
/>
<doctrine:result-cache-driver
type="array"
type="pool"
id=""
pool=""
host=""
port=""
instance-class=""
class=""
namespace="null"
cache-provider="null"
/>
<doctrine:entity-listeners>
Expand Down Expand Up @@ -693,15 +645,9 @@ Configuration Reference
>
<doctrine:region-cache-driver
type="array"
type="pool"
id=""
pool=""
host=""
port=""
instance-class=""
class=""
namespace="null"
cache-provider="null"
/>
<!-- example -->
Expand All @@ -715,15 +661,9 @@ Configuration Reference
>
<doctrine:cache-driver
type="array"
type="pool"
id=""
pool=""
host=""
port=""
instance-class=""
class=""
namespace="null"
cache-provider="null"
/>
</doctrine:region>
Expand Down Expand Up @@ -803,9 +743,9 @@ the ORM resolves to:
proxy_namespace: Proxies
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
default_entity_manager: default
metadata_cache_driver: array
query_cache_driver: array
result_cache_driver: array
metadata_cache_driver: ~
query_cache_driver: ~
result_cache_driver: ~
There are lots of other configuration options that you can use to overwrite
certain classes, but those are for very advanced use-cases only.
Expand Down Expand Up @@ -839,11 +779,9 @@ The environment variables that doctrine is going to change in the Oracle DB sess
Caching Drivers
~~~~~~~~~~~~~~~

For the caching drivers you can specify the values ``array``, ``apc``, ``apcu``,
``memcache``, ``memcached``, ``redis``, ``wincache``, ``zenddata`` and
``xcache``. You can use a Symfony Cache pool by using the ``pool`` type and
creating a cache bool through the FrameworkBundle configuration. The ``service``
type lets you define the ``ID`` of your own caching service.
You can use a Symfony Cache pool by using the ``pool`` type and creating a cache
pool through the FrameworkBundle configuration. The ``service`` type lets you
define the ``ID`` of your own caching service.

The following example shows an overview of the caching configurations:

Expand All @@ -852,8 +790,8 @@ The following example shows an overview of the caching configurations:
doctrine:
orm:
auto_mapping: true
# each caching driver type defines its own config options
metadata_cache_driver: apc
# With no cache set, this defaults to a sane 'pool' configuration
metadata_cache_driver: ~
# the 'pool' type requires to define the 'pool' option and configure a cache pool using the FrameworkBundle
result_cache_driver:
type: pool
Expand Down
2 changes: 0 additions & 2 deletions Tests/Command/ImportMappingDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public function registerBundles() : iterable
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) {
// @todo Setting the kernel.name parameter can be removed once the dependency on DoctrineCacheBundle has been dropped
$container->setParameter('kernel.name', 'foo');
$container->loadFromExtension('framework', ['secret' => 'F00']);

$container->loadFromExtension('doctrine', [
Expand Down
Loading

0 comments on commit 357a477

Please sign in to comment.