Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A more clean constructor #54

Merged
merged 3 commits into from
Sep 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,31 @@ class App
/**
* Application initialization.
*
* @param mixed $router Routing system.
* @param mixed $router Routing system.
* @param ContainerInterface $container Dependency Injection container.
*/
public function __construct($router = null, ContainerInterface $container = null)
{
$this->container = $container;
$this->container = $container ?: $this->buildContainer(Loader::load());
$container = &$this->container;

$this->response = new Response();

$this->request = ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);

if ($this->container == null) {
$config = Loader::load();
$container = $this->buildContainer($config);
}
$this->request = ServerRequestFactory::fromGlobals();

if ($router == null && $container->has('router') == false) {
throw new Exception('Define router config');
} elseif ($container->has('router') == false) {
}

if ($container->has('router') == false) {
$container->set('router', $router);
}

$container->set('event_manager', DI\object('Zend\EventManager\EventManager'));
$container->set('dispatcher', DI\object('GianArb\Penny\Dispatcher')
->constructor($container->get('router')));
$container->set(
'dispatcher',
DI\object('GianArb\Penny\Dispatcher')->constructor($container->get('router'))
);
$container->set('di', $container);
$this->container = $container;
}

/**
Expand Down