schmittjoh / JMSSerializerBundle

Easily serialize, and deserialize data of any complexity (supports XML, JSON, YAML)
http://jmsyst.com/bundles/JMSSerializerBundle
MIT License
1.8k stars 312 forks source link

The service "jms_serializer.metadata.traceable_cache" has a dependency on a non-existent service "jms_serializer.metadata.cache". #899

Closed ts-navghane closed 2 years ago

ts-navghane commented 2 years ago
Q A
Bug report? no
Feature request? no
BC Break report? yes
RFC? no

In "jms/serializer-bundle" - 4.0.2, https://github.com/schmittjoh/JMSSerializerBundle/blob/4.0.2/DependencyInjection/JMSSerializerExtension.php#L99-L101 the cache service is removed from the container if the cache config value is none, but jms_serializer.metadata.traceable_cache has dependency on jms_serializer.metadata.cache. https://github.com/schmittjoh/JMSSerializerBundle/blob/4.0.2/Resources/config/debug.xml#L31-L36.

Thus it gives error The service "jms_serializer.metadata.traceable_cache" has a dependency on a non-existent service "jms_serializer.metadata.cache". when we warmup the cache or simply do bin/console.

Steps required to reproduce the problem

  1. Put jms_serializer[metadata][config] => 'none'
  2. Run bin/console in Symfony 4.4

Expected Result

Actual Result

Versions

PHP - 7.4.30 Symfony - 4.4.0 jms/serializer-bundle - 4.0.2

ghost commented 2 years ago

Yeah, I had the same problem. Had to set cache: file to push forward.

ts-navghane commented 2 years ago

I did a workaround this:

Created a custom JMSNoneCache class and mentioned it as a service with key jms.none.cache:

<?php

use Metadata\Cache\CacheInterface;
use Metadata\Cache\ClearableCacheInterface;
use Metadata\ClassMetadata;

class JMSNoneCache implements CacheInterface, ClearableCacheInterface
{
    public function load(string $class): ?ClassMetadata
    {
        return null;
    }

    public function put(ClassMetadata $metadata): void
    {
        return;
    }

    public function evict(string $class): void
    {
        return;
    }

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

Used jms_serializer[metadata][config] => 'jms.none.cache'. This works for now.

goetas commented 2 years ago

Since https://github.com/schmittjoh/JMSSerializerBundle/pull/900 is merged, is this solved now?

ghost commented 2 years ago

I will let you know when go back to the branch where I'm upgrading JMS.

ghost commented 2 years ago

@goetas It works. Thank you a lot.