Slim3 and league container - problems adding a service provider - Closed

Hi everyone, your guidance will be appreciated. I’m using slim3 with the league/container,

getting error “A service provider must be a fully qualified class name or instance of (\League\Container\ServiceProvider\ServiceProviderInterface)”.

namespace App\Menu\Providers;
use App\Models\Menu;

class MenuDspProvider implements MenuDspProviderInterface
  {
    public function getAllMenu() {
        return Menu::all();
    }
}

// File : container.php
//=================

$container = new League\Container\Container;

// Autowiring enabled
$container->delegate(new League\Container\ReflectionContainer);

// Core providers
$container->addServiceProvider(new App\Providers\ConfigServiceProvider);
$container->addServiceProvider(new App\Providers\SlimServiceProvider);

// Additionnal providers
foreach ($container->get('config')->get('providers') as $provider) {
    $container->addServiceProvider($provider);
}

file: MenuDspServiceProvider
//========================

namespace App\Providers;

use App\Menu\Providers\MenuDspProvider;
use League\Container\ServiceProvider\AbstractServiceProvider;
//use League\Container\ServiceProvider\BootableServiceProviderInterface;
use App\Views\View as Twig;

class MenuDspServiceProvider extends AbstractServiceProvider {

    protected $provides = [
        MenuDspProvider::class
    ];

    public function register() {

        $container = $this->getContainer();

        $container->share(MenuDspProvider::class, function () use ($container) {
            return new MenuDspProvider(
                    new MenuDspProvider
            );
        });
    }
}


Maybe just a typo.

See here: MenurDspProviderInterface (Menu… and not Menur…)

Hi Odan, thanks forgot to fix the typo in the code before it was posted on discourse.

Typo fixed on post, still having the same issue.

The ServiceProviderAggregate::add($provider) failes because one of the given provider does not implement the ServiceProviderInterface.

Make sure that the provider classes:

App\Providers\ConfigServiceProvider
App\Providers\SlimServiceProvider

… implement the ServiceProviderInterface

class ConfigServiceProviderimplements implements ServiceProviderInterface { ... }
class SlimServiceProvider implements ServiceProviderInterface { ... }

Hi,

Thanks for your feedback.
Found the problem, it was with the addServiceprovider, had to add the full qualified name. The ConfigServiceProvider implements a BootableServiceProviderInterface