-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from pennyphp/feature/di-factory
Create container factory
- Loading branch information
Showing
8 changed files
with
72 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace GianArb\Penny\Container; | ||
|
||
use DI; | ||
|
||
class PHPDiFactory | ||
{ | ||
/** | ||
* Container compilation. | ||
* | ||
* @param mixed $config Configuration file/array. | ||
* | ||
* @link http://php-di.org/doc/php-definitions.html | ||
* | ||
* @return ContainerInterface | ||
*/ | ||
public static function buildContainer($config = []) | ||
{ | ||
$builder = new DI\ContainerBuilder(); | ||
$builder->useAnnotations(true); | ||
$builder->addDefinitions( | ||
[ | ||
'event_manager' => DI\object('Zend\EventManager\EventManager'), | ||
'dispatcher' => DI\object('GianArb\Penny\Dispatcher') | ||
->constructor(DI\get('router')), | ||
] | ||
); | ||
$builder->addDefinitions($config); | ||
$container = $builder->build(); | ||
$container->set('di', $container); | ||
|
||
return $container; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
'router' => \FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) { | ||
$r->addRoute('GET', '/', ['TestApp\Controller\Index', 'index']); | ||
}) | ||
]; |