sonata-project / SonataCacheBundle

[Abandoned] This bundle provides caching services
https://github.com/sonata-project/SonataCacheBundle
MIT License
69 stars 69 forks source link

sonata.cache.manager public #250

Closed 0x6368 closed 5 years ago

0x6368 commented 5 years ago

Environment

dev and prod

Sonata packages

$ composer show --latest 'sonata-project/*'

sonata-project/admin-bundle              3.41.0 3.45.1 The missing Symfony Admin Generator
sonata-project/block-bundle              3.12.1 3.14.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/cache-bundle              3.0.1  3.0.1  This bundle provides caching services
sonata-project/core-bundle               3.12.0 3.15.1 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.4.0  2.4.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.1.2  1.1.5  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.6.3  3.8.1  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.9.1  2.0.1  Lightweight Exporter library
sonata-project/user-bundle               4.2.3  4.2.3  Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'

symfony/apache-pack          v1.0.1  v1.0.1  A pack for Apache support in Symfony
symfony/asset                v4.2.1  v4.2.2  Symfony Asset Component
symfony/browser-kit          v4.2.1  v4.2.2  Symfony BrowserKit Component
symfony/cache                v4.2.1  v4.2.2  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/config               v4.2.2  v4.2.2  Symfony Config Component
symfony/console              v4.2.1  v4.2.2  Symfony Console Component
symfony/contracts            v1.0.2  v1.0.2  A set of abstractions extracted out of the Symfony components
symfony/css-selector         v4.2.1  v4.2.2  Symfony CssSelector Component
symfony/debug                v4.2.2  v4.2.2  Symfony Debug Component
symfony/debug-bundle         v4.2.1  v4.2.2  Symfony DebugBundle
symfony/dependency-injection v4.2.2  v4.2.2  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.2.1  v4.2.2  Symfony Doctrine Bridge
symfony/dom-crawler          v4.2.1  v4.2.2  Symfony DomCrawler Component
symfony/dotenv               v4.2.1  v4.2.2  Registers environment variables from a .env file
symfony/event-dispatcher     v4.2.2  v4.2.2  Symfony EventDispatcher Component
symfony/expression-language  v4.2.1  v4.2.2  Symfony ExpressionLanguage Component
symfony/filesystem           v4.2.2  v4.2.2  Symfony Filesystem Component
symfony/finder               v4.2.1  v4.2.2  Symfony Finder Component
symfony/flex                 v1.1.8  v1.1.8  Composer plugin for Symfony
symfony/form                 v4.2.1  v4.2.2  Symfony Form Component
symfony/framework-bundle     v4.2.1  v4.2.2  Symfony FrameworkBundle
symfony/http-foundation      v4.2.2  v4.2.2  Symfony HttpFoundation Component
symfony/http-kernel          v4.2.2  v4.2.2  Symfony HttpKernel Component
symfony/inflector            v4.2.1  v4.2.2  Symfony Inflector Component
symfony/intl                 v4.2.1  v4.2.2  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/options-resolver     v4.2.1  v4.2.2  Symfony OptionsResolver Component
symfony/phpunit-bridge       v4.2.1  v4.2.2  Symfony PHPUnit Bridge
symfony/polyfill-ctype       v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu    v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72       v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/process              v4.2.2  v4.2.2  Symfony Process Component
symfony/property-access      v4.2.1  v4.2.2  Symfony PropertyAccess Component
symfony/property-info        v4.2.1  v4.2.2  Symfony Property Info Component
symfony/routing              v4.2.2  v4.2.2  Symfony Routing Component
symfony/security-acl         v3.0.1  v3.0.1  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.2.1  v4.2.2  Symfony SecurityBundle
symfony/security-core        v4.2.1  v4.2.2  Symfony Security Component - Core Library
symfony/security-csrf        v4.2.1  v4.2.2  Symfony Security Component - CSRF Library
symfony/security-guard       v4.2.1  v4.2.2  Symfony Security Component - Guard
symfony/security-http        v4.2.1  v4.2.2  Symfony Security Component - HTTP Integration
symfony/serializer           v4.2.1  v4.2.2  Symfony Serializer Component
symfony/stopwatch            v4.2.1  v4.2.2  Symfony Stopwatch Component
symfony/swiftmailer-bundle   v3.2.4  v3.2.5  Symfony SwiftmailerBundle
symfony/templating           v4.2.1  v4.2.2  Symfony Templating Component
symfony/translation          v4.2.1  v4.2.2  Symfony Translation Component
symfony/twig-bridge          v4.2.1  v4.2.2  Symfony Twig Bridge
symfony/twig-bundle          v4.2.1  v4.2.2  Symfony TwigBundle
symfony/validator            v4.2.1  v4.2.2  Symfony Validator Component
symfony/var-dumper           v4.2.1  v4.2.2  Symfony mechanism for exploring and dumping PHP variables
symfony/var-exporter         v4.2.1  v4.2.2  A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code
symfony/web-profiler-bundle  v4.2.1  v4.2.2  Symfony WebProfilerBundle
symfony/web-server-bundle    v4.2.1  v4.2.2  Symfony WebServerBundle
symfony/yaml                 v4.2.1  v4.2.2  Symfony Yaml Component```

PHP version

$ php -v

PHP 7.2.12 (cli) (built: Nov 29 2018 01:59:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies

Subject

The sonata.cache.manager service is private, so I cannot flush the cache with php bin/console sonata:cache:flush-all

Steps to reproduce

php bin/console sonata:cache:flush-all

Expected results

The cache being cleared.

Actual results

The "sonata.cache.manager" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependenc  
  y injection instead.  
0x6368 commented 5 years ago

I am still having issues with the command. When I run it, it seems like the BaseCacheCommand constructor gets called four times. The first two times, CacheManagerInterface is set, but the second two times it is null. Because of this, the BaseCacheCommand tries to https://github.com/sonata-project/SonataCacheBundle/blob/13dbbb6b428a4062914ff8a37f14af2a7aa66742/src/Command/BaseCacheCommand.php#L46, which crashes with the error

The "Sonata\Cache\CacheManagerInterface" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use depend  
  ency injection instead.
core23 commented 5 years ago

Can you try to provide a PR with a fix?