I have a question regarding OOP with Dependecy Injection.
For example, have constants coming from the framework you are using. i.e, ABSPATH
in WordPress
How badly will it break the Dependency Injection principle if I do not add the value of that constant as a dependency in constructor
function of the class, and just use it directly inside method?
Say, strictly DI speaking, you need to do something like:
class Foo {
private $abspath;
public function __construct(string $abspath) {
$this->abspath = $abspath
}
public function get_assets_dir() {
return $this->abspath . '/assets/';
}
}
$foo = new Foo(ABSPATH);
$foo->get_assets_dir();
but instead something like?
class Foo {
public function __construct() {
//nothing here.
}
public function get_assets_dir() {
return ABSPATH . '/assets/';
}
}
Do I really still have to do it if it will always be defined since it sits on top of a framework that defines it by default?