8000 [Cache] Autowiring type-hint for namespaced caches · Issue #60583 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[Cache] Autowiring type-hint for namespaced caches #60583
Closed
@IndraGunawan

Description

@IndraGunawan

Symfony version(s) affected

7.3.0

Description

Symfony 7.3 has a great improvement on cache component https://symfony.com/blog/new-in-symfony-7-3-namespaced-caches

additional assert($this->cache instanceof NamespacedPoolInterface); required before calling the $this->cache->withSubNamespace('sub-ns'); even all caches adapters implement NamespacedPoolInterface, otherwise phpstan will complain about call to undefined method

How to reproduce

had tried to use intersection types

public function __construct(
        private CacheInterface&NamespacedPoolInterface $appCache
    )

but get this error

In DefinitionErrorExceptionPass.php line 48:
                                                                                                                                                                                                                      
  [Symfony\Component\DependencyInjection\Exception\RuntimeException]                                                                                                                                                  
  Cannot autowire service "App\Command\TestCommand": argument "$appCache" of method "__construct()" has type "Symfony\Contracts\Cache\CacheInterface&Symfony\Contracts\Cache\NamespacedPoolInterface" but this class  
   was not found.

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0