Skip to content

Commit

Permalink
PSR1/2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Aug 3, 2013
1 parent 4418f97 commit ca5a09e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
31 changes: 18 additions & 13 deletions src/DI/ZendFramework2/InjectedAbstractActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
namespace DI\ZendFramework2;

use DI\Container;
use DI\Annotation\Inject;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Stdlib\ResponseInterface as Response;

abstract class InjectedAbstractActionController extends AbstractActionController
{
protected $container;
/**
* @var \DI\Container
*/
protected $container;

public function __construct(Container $container = null)
{
$this->container = $container;
}
public function __construct(Container $container = null)
{
$this->container = $container;
}

public function dispatch(Request $request, Response $response = null)
{
if ($this->container == null)
$this->container = $this->serviceLocator->get('DI\\Container');
public function dispatch(Request $request, Response $response = null)
{
if ($this->container == null) {
$this->container = $this->serviceLocator->get('DI\\Container');
}

$this->container->injectOn($this);
return parent::dispatch($request, $response);
}
// Inject dependencies
$this->container->injectOn($this);

return parent::dispatch($request, $response);
}
}
31 changes: 18 additions & 13 deletions src/DI/ZendFramework2/InjectedAbstractRestfulController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
namespace DI\ZendFramework2;

use DI\Container;
use DI\Annotation\Inject;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Stdlib\ResponseInterface as Response;

abstract class InjectedAbstractRestfulController extends AbstractRestfulController
{
protected $container;
/**
* @var \DI\Container
*/
protected $container;

public function __construct(Container $container = null)
{
$this->container = $container;
}
public function __construct(Container $container = null)
{
$this->container = $container;
}

public function dispatch(Request $request, Response $response = null)
{
if ($this->container == null)
$this->container = $this->serviceLocator->get('DI\\Container');
public function dispatch(Request $request, Response $response = null)
{
if ($this->container == null) {
$this->container = $this->serviceLocator->get('DI\\Container');
}

$this->container->injectOn($this);
return parent::dispatch($request, $response);
}
// Inject dependencies
$this->container->injectOn($this);

return parent::dispatch($request, $response);
}
}

0 comments on commit ca5a09e

Please sign in to comment.