Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6136159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:34:08+00:00 2026-05-23T17:34:08+00:00

I am currently building an MVC application in PHP (not using any frameworks). I

  • 0

I am currently building an MVC application in PHP (not using any frameworks). I am using yadif (https://github.com/beberlei/yadif) for dependency injection.

I would like to build a login module. It should be able to use adapters, for example one might be able to set that logins are authenticated using the MySql database or some LDAP directory. This setting would be done in the admin area and is stored in a database.

I imagine that I would have an abstract adapter:

<?php 
abstract AbstractLoginAdapter{
    abstract function login($username, $pass){}
}

I would then just implement adapters like so:

<?php
MySQLLoginAdapter extends AbstractLoginAdapter{

    public function login($username, $pass){
        //do stuff
    }
}

That’s all nice and well, but how do I create an instance of the adapter? Usually, dependencies would be injected using yadif via the constructor:

<?php
class loginController{

    private $_adapter;

    public function __construct(AbstractLoginAdapter $adapter){
          $this->_adapter = $adapter;
    }
}

However, since I don’t know which concrete adapter will be injected, I can’t set that in a configuration before hand. Yadif allows me to create a configuration which I then need to pass to the container:

$builder = new Yadif_Builder();
$builder->bind("loginController")
    ->to("loginController")
    ->args($SelectedLoginAdapter);

Since the application uses a front controller, a DI container is created there. It then creates a routing object etc.

  • In light of this, should I pass a reference of that container down to the loginController object, and then use that container to instantiate my adapter?

  • Or should I instantiate a new container within my loginController object and then just load in an instance of the adapter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:34:08+00:00Added an answer on May 23, 2026 at 5:34 pm

    I would do the first: pass a reference down to your controller. You’ll want to use a single Dependency Injector Container (DIC) in your application. You don’t want to create a new DIC whenever you need access to it. That would lead to duplication of objects stored in the DIC.

    I know this is how Symfony 2 does it. All controllers (and many other classes) implement the ContainerAware interface. That interface has a single method setContainer() that is used to pass down a reference to the DIC.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently building a PHP application using the MVC pattern. I have implemented
I am currently building an application using ASP.NET MVC. The data entry pages are
I am currently building an ASP.Net-MVC Application using log4net for logging, but the logger
I am currently building my first MVC 3 application, using EF Code First, SQL
I'm currently building a Spring MVC application. I was looking to use JSP pages
I'm building a MVC web application (using the Spring MVC framework), and I'm a
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
My team is currently in the process of building an ASP.NET MVC application, and
I am using Spring MVC for an application I am building. Everything is working
My team is currently building a new SaaS application for our company ( Amilia.com

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.