sonata-project / SonataMediaBundle

Symfony SonataMediaBundle
https://docs.sonata-project.org/projects/SonataMediaBundle
MIT License
449 stars 496 forks source link

The "sonata.media.manager.media" 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 dependency injection instead. #1364

Closed khalil1608 closed 6 years ago

khalil1608 commented 6 years ago

Hello,

I'm trying to get the sonata media manager with the symfony container in a Fixture Class $this->container->get('sonata.media.manager.media') I have the error

The "sonata.media.manager.media" 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 dependency injection instead.

When I try to get it in the __construct with:

private $mediaManager;

    public function __construct(ContainerInterface $container, MediaManager $mediaManager)
    {
        $this->container = $container;
        $this->mediaManager = $mediaManager;
    }

I have the error :

 Cannot autowire service "App\DataFixtures\BrandFixtures": argument "$mediaManager" of method "__construct()" references class "Sonata\MediaBundle\Entity\MediaManager" but no such service exis  
  ts. It cannot be auto-registered because it is from a different root namespace.      

Any Idea ?

Thank you

Environment

Ubuntu 16.04 Docker With Debian 8 Php 7.1.3-fpm

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.30.0 3.30.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.9.0  3.9.0  Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.8.0  3.8.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.1  2.3.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.3.0  3.3.0  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.3.0  2.3.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.8.0  1.8.0  Lightweight Exporter library
sonata-project/media-bundle              3.10.0 3.10.0 Symfony SonataMediaBundle
sonata-project/notification-bundle       3.3.0  3.3.0  Symfony SonataNotificationBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/asset                v3.4.2  v4.0.2  Symfony Asset Component      
symfony/browser-kit          v3.4.2  v4.0.2  Symfony BrowserKit Component
symfony/cache                v4.0.2  v4.0.2  Symfony Cache component with PSR-6, PSR-16, and tags
symfony/class-loader         v3.4.2  v3.4.2  Symfony ClassLoader Component
symfony/config               v4.0.2  v4.0.2  Symfony Config Component
symfony/console              v3.4.2  v4.0.2  Symfony Console Component
symfony/css-selector         v3.4.2  v4.0.2  Symfony CssSelector Component
symfony/debug                v4.0.2  v4.0.2  Symfony Debug Component
symfony/dependency-injection v4.0.2  v4.0.2  Symfony DependencyInjection Component
symfony/doctrine-bridge      v4.0.2  v4.0.2  Symfony Doctrine Bridge
symfony/dom-crawler          v3.4.2  v4.0.2  Symfony DomCrawler Component
symfony/dotenv               v3.4.2  v4.0.2  Registers environment variables from a .env file
symfony/event-dispatcher     v4.0.2  v4.0.2  Symfony EventDispatcher Component
symfony/expression-language  v4.0.2  v4.0.2  Symfony ExpressionLanguage Component
symfony/filesystem           v4.0.2  v4.0.2  Symfony Filesystem Component
symfony/finder               v4.0.2  v4.0.2  Symfony Finder Component
symfony/flex                 v1.0.53 v1.0.53
symfony/form                 v4.0.2  v4.0.2  Symfony Form Component
symfony/framework-bundle     v3.4.2  v4.0.2  Symfony FrameworkBundle
symfony/http-foundation      v4.0.2  v4.0.2  Symfony HttpFoundation Component
symfony/http-kernel          v4.0.2  v4.0.2  Symfony HttpKernel Component
symfony/inflector            v4.0.2  v4.0.2  Symfony Inflector Component
symfony/intl                 v4.0.2  v4.0.2  A PHP replacement layer for the C intl extension that includes additional data from the ICU library.
symfony/maker-bundle         v1.0.2  v1.0.2 
symfony/options-resolver     v4.0.2  v4.0.2  Symfony OptionsResolver Component
symfony/orm-pack             v1.0.5  v1.0.5  A pack for the Doctrine ORM
symfony/phpunit-bridge       v3.4.2  v4.0.2  Symfony PHPUnit Bridge
symfony/polyfill-intl-icu    v1.6.0  v1.6.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring    v1.6.0  v1.6.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-util        v1.6.0  v1.6.0  Symfony utilities for portability of PHP codes
symfony/process              v3.4.2  v4.0.2  Symfony Process Component
symfony/property-access      v4.0.2  v4.0.2  Symfony PropertyAccess Component
symfony/routing              v4.0.2  v4.0.2  Symfony Routing Component
symfony/security             v3.4.2  v4.0.2  Symfony Security Component
symfony/security-acl         v3.0.0  v3.0.0  Symfony Security Component - ACL (Access Control List)
symfony/security-bundle      v4.0.2  v4.0.2  Symfony SecurityBundle
symfony/swiftmailer-bundle   v3.1.6  v3.1.6  Symfony SwiftmailerBundle
symfony/templating           v4.0.2  v4.0.2  Symfony Templating Component
symfony/thanks               v1.0.0  v1.0.0 
symfony/translation          v4.0.2  v4.0.2  Symfony Translation Component
symfony/twig-bridge          v4.0.2  v4.0.2  Symfony Twig Bridge
symfony/twig-bundle          v4.0.2  v4.0.2  Symfony TwigBundle
symfony/validator            v4.0.2  v4.0.2  Symfony Validator Component
symfony/var-dumper           v3.4.2  v4.0.2  Symfony mechanism for exploring and dumping PHP variables
symfony/yaml                 v3.4.2  v4.0.2  Symfony Yaml Component

PHP version

$ php -v
PHP 7.1.12 (cli) (built: Dec 19 2017 20:31:53) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
core23 commented 6 years ago

Looks like we're not fully sf 4 compatible. Feel free to fix this @khalil1608

core23 commented 6 years ago

Have you tried the latest 3.x@dev release?

infinityC commented 4 years ago

The problem is that MediaManager (sonata service.media.manager.media) can't connect automatically so you have to do it manually.

First check this service in your terminal and find information about this service by typing:

php bin/console debug:container sonata.media.manager.media

Result

Service ID sonata.media.manager.media Class Sonata\MediaBundle\Entity\MediaManager

Now go to services.yaml and create an alias:

Sonata\MediaBundle\Entity\MediaManager: '@sonata.media.manager.media'

Now you can use MediaManager

use Sonata\MediaBundle\Entity\MediaManager; 

...

private $mediaManager; 

public function __construct(MediaManager $mediaManager) 
{ 
  $this->mediaManager = $mediaManager; 
}