-
Notifications
You must be signed in to change notification settings - Fork 30
PPI v2 Extension DI Container
dragoonis edited this page Feb 17, 2012
·
3 revisions
From the Bootstrap wiki document you can clearly set classes and use $this->getService('dependency.name').
However, in this case we need dependencies that are local to the Extension itself.
One concept is to have an Extension.php file in each /ext/ folder. This is notably similar to ZF2's Module.php class.
I believe there could be a simple di.php such as Ext/<ExtName>/Config/di.php.
It could contain an array such as:
<?php
// $dep['dep.name'] = "\Path\To\Dependency";
$dep['user.auth'] = "\Ext\Users\Auth\User";
$dep['user.entity'] = "\Ext\Users\Entity\User";
// Respectively from the controller you'd be able to do
$authClass = $this->getService('user.auth');
$auth = new $authClass();
if($auth->verify($username, $password)) {
$entity = $this->getService('user.entity');
$user = new $entity($someUserData);
}