Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with inheritance #194

Closed
Starlyvil opened this issue Jul 19, 2021 · 2 comments
Closed

How to deal with inheritance #194

Starlyvil opened this issue Jul 19, 2021 · 2 comments

Comments

@Starlyvil
Copy link

I have a controller class below, that requires 4 arguments, all objects. The controller class is to be inherited, how do i call the parent::__contructor() with dice. I'm kinda lost.

Controller.php

class Controller
{
    function __construct(Loader $loader, Request $request, Session $session, Validator $validator){
        global $config;
        
        $this->appConfig    = $config;
        $this->loader       = $loader;
        $this->xhr          = $request;
        $this->session      = $session;
        $this->validator    = $validator;
    }
   /* Other stuffs members here*/
}

Without DIC with DICE, the Campaign derived class would look like the below

Campaign.php

<?php
use Dice\Dice;
use vilshub\http\Request;
use vilshub\validator\Validator;

class Campaign extends Controller
{
    function __construct(){
        parent::__construct(new Loader, new Request, new Session, new Validator));
    }
  //...
}

But with DICE, how can this be achieved?

@TRPB
Copy link
Member

TRPB commented Jul 19, 2021

This is done exactly the same way it's done without a dependency injection container:

class Campaign extends Controller
{
    function __construct(Loader $loader, Request $request, Session $session, Validator $validator){
        parent::__construct($loader, $request, $session, $validator);
    }
  //...
}```

@Starlyvil
Copy link
Author

Ok I get it now, Thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants