Skip to main content

All Questions

0votes
1answer
217views

Which types of objects that are instantiated inside controller's methods should be injected into the controller instead?

Consider code below MyController //MyAction //MyHandler { public function processRequest() { // ... $myObject = new MyObjectClass(); $myObject->methodCall(); ...
Dennis's user avatar
  • 8,257
2votes
2answers
932views

How to use Dependency-injection Containers correctly when they hide dependencies from outer classes?

From Zend Docs there is this example of how to use Zend\Di, which is a dependency injection container of Zend Framework: // inside a bootstrap somewhere $di = new Zend\Di\Di(); // inside each ...
Dennis's user avatar
  • 8,257
3votes
0answers
898views

Dependency injection - Nested objects

# Introduction I am working on a CMS application in PHP with about 200 classes. The CMS, in general, does the same thing every CMS does: generate sites. I am learning a lot about OOP and design ...
PIDZB's user avatar
5votes
2answers
2kviews

PHP OOP dependency injection - when is it o.k. to use the "new" statement

I was told to avoid "new" statements in classes or functions but rather create the objects from classes in the root of the program (maybe with the use of a DI-container) and then inject the objects ...
Benedikt's user avatar
4votes
1answer
450views

Do I have to stop using Dependency Injection to keep object debug printouts small?

Say I have a large object - think EntityManager of an ORM such as Doctrine, or a custom DAO object, or what have you. Object, output of which is required to be used inside a class, but the object ...
Dennis's user avatar
  • 8,257
6votes
1answer
4kviews

PHP: Injecting the same database connection into multiple objects

Suppose that there are two classes that define objects of vastly different function such that in the datastore, the information they require is divided into two separate databases. For example, the ...
concat's user avatar
3votes
1answer
1kviews

Hidden dependencies - why not?

Hidden dependencies: function __construct($dep_registry){ $this->db = $dep_registry->get('db'); $this->request = $dep_registry->get('request'); ... } Not so hidden: function ...
Elfy's user avatar
  • 131
-1votes
1answer
512views

Multiple method calls in the constructor and dependency injection

I was asked to refactor some almost ureadable spaghetti code into object-oriented architecture. I have some doubts regarding a class that I designed. Here is the class' skeleton: require_once 'inc/...
luqo33's user avatar
1vote
0answers
74views

Is this pattern of optional dependency injection sound? [duplicate]

A lot of the time when working on legacy code bases, I find it hard to move manually created dependencies to the constructor parameters, because of a variety of reasons. Sometimes it's because the ...
maxiscool's user avatar
3votes
1answer
116views

Creating variables in methods/functions

In how far do we create variables in our methods or functions? Do we only create one when we're using the result of the variable more then one time like this? function someFunction(SomeClass $...
Bas's user avatar
  • 175
2votes
1answer
469views

How to properly handle conditional dependencies in a factory?

Let's say you have a string $action run-time, that specifies which type of $object needs to be created: $dbobject, $memcacheobject, $fileobject, $xmlobject, etc. Assume also, that creation of an ...
sky's user avatar
  • 21
1vote
1answer
668views

Unused dependencies and constructor injection

I have a class that has 3 dependencies. WritabbleDBConnection, ReadOnlyDBConnection and a QueryFilter utility object. I want to do constructor Injection so my class would look something like this. ...
Patrick Forget's user avatar
2votes
2answers
451views

Is there a better way to design these classes?

I have two business classes: TimesheetDay and TimeSlot. One TimesheetDay can have one or more TimeSlots. The TimesheetDay and TimeSlot classes will be dependent on an object that implements a ...
Lewis Bassett's user avatar
8votes
3answers
2kviews

Keeping an MVC model loosely coupled from the DB?

I like to keep my code testable and have decided to go with the Dependency-Injection strategy for my current MVC framework, which definitely has proven to be a great way to ensure loosely coupled code,...
Industrial's user avatar

close