2

Just throwing this out here because I couldn't find a lot of info on this error and it took me about 2 hours to find it. face palm

In container.php -> DBService defined as:

    DBServiceInterface::class => function (ContainerInterface $c) {
        return new DBService(
            $c->get('settings.database'), 
            $c->get(SessionInterface::class), 
            $c->get(ValidatorInterface::class)
    );
    },

Type: DI\Definition\Exception\InvalidDefinition Message: Entry "PVS\HomeController" cannot be resolved: Entry "PVS\DBService\DBService" cannot be resolved: Parameter $settings of __construct() has no value defined or guessable Full definition: Object ( class = PVS\DBService\DBService lazy = false __construct( $settings = #UNDEFINED# $session = get(PVS\Helpers\Storage\Contracts\SessionInterface) $validator = get(PVS\Validation\Contracts\ValidatorInterface) ) ) Full definition: Object ( class = PVS\HomeController lazy = false __construct( $container = get(Psr\Container\ContainerInterface) $view = get(Slim\Views\Twig) $router = get(Slim\Router) $flash = get(Slim\Flash\Messages) $session = get(PVS\Helpers\Storage\Contracts\SessionInterface) $db = get(PVS\DBService\DBService) ) ) File:

So I started looking for problems in my container or in DBService.php itself. The problem was actually in the controller on the first line of the error message.

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Aaron Bar
  • 611
  • 1
  • 7
  • 20

2 Answers2

1

Constructor of HomeController was defined as:

public function __construct (ContainerInterface $container, 
    Twig $view, 
    Router $router, 
    Messages $flash, 
    SessionInterface $session, 
    DBService $db) {  <--- Problem here

I changed it to:

    public function __construct (ContainerInterface $container, 
    Twig $view, 
    Router $router, 
    Messages $flash, 
    SessionInterface $session, 
    DBServiceInterface $db) { <--- 

Notice that I am now calling the Interface instead of the concrete implementation and it matches the DI container posted above.

Aaron Bar
  • 611
  • 1
  • 7
  • 20
  • 2
    Is this the solution? If yes, then you should accept it. If no, then you should update your question with this instead. – M. Eriksson Apr 13 '18 at 05:11
1

I had the same exception and in short my problem was that a class inherited the constructor of its parent and the parent __constructor wasn't public but protected.

Maybe that can spare someone else hours of research.

Samuel Gfeller
  • 840
  • 9
  • 19