Created
February 24, 2012 03:12
-
-
Save EvanDotPro/1896972 to your computer and use it in GitHub Desktop.
Static DI locator replace for ZendSkeletonApplication for benchmarking purposes.
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
<?php | |
namespace Application\Di; | |
use Zend\Di\Locator; | |
class Di implements Locator | |
{ | |
protected $classes = array(); | |
public function get($name, array $params = array()) | |
{ | |
if ($instance = $this->getInstance($name)) { | |
return $instance; | |
} | |
switch ($name) { | |
case 'Zend\Mvc\Router\RouteStack': | |
return \Zend\Mvc\Router\Http\TreeRouteStack::factory()->addRoutes(array( | |
'default' => array( | |
'type' => 'Zend\Mvc\Router\Http\Segment', | |
'options' => array( | |
'route' => '/[:controller[/:action]]', | |
'constraints' => array( | |
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', | |
'action' => '[a-zA-Z][a-zA-Z0-9_-]*', | |
), | |
'defaults' => array( | |
'controller' => 'Application\Controller\IndexController', | |
'action' => 'index', | |
), | |
), | |
), | |
'home' => array( | |
'type' => 'Zend\Mvc\Router\Http\Literal', | |
'options' => array( | |
'route' => '/', | |
'defaults' => array( | |
'controller' => 'Application\Controller\IndexController', | |
'action' => 'index', | |
), | |
), | |
), | |
)); | |
break; | |
case 'Zend\Mvc\View\RouteNotFoundStrategy': | |
$return = new $name; | |
$return->setNotFoundTemplate('error/404'); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\Mvc\View\ExceptionStrategy': | |
$return = new $name; | |
$return->setDisplayExceptions(true); | |
$return->setErrorTemplate('error/404'); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Application\Controller\IndexController': | |
$return = new $name; | |
$return->setBroker($this->get('Zend\Mvc\Controller\PluginBroker')); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\Mvc\Controller\PluginBroker': | |
$return = new $name; | |
$return->setClassLoader($this->get('Zend\Mvc\Controller\PluginLoader')); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\Mvc\View\DefaultRenderingStrategy': | |
$return = new $name($this->get('Zend\View\View')); | |
$return->setBaseTemplate('layout/layout'); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\View\Strategy\PhpRendererStrategy': | |
return $this->setInstance($name, new $name($this->get('Zend\View\Renderer\PhpRenderer'))); | |
break; | |
case 'Zend\View\Renderer\PhpRenderer': | |
$return = new $name; | |
$return->setResolver($this->get('Zend\View\Resolver\AggregateResolver')); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\View\Resolver\AggregateResolver': | |
$return = new $name; | |
$return->attach($this->get('Zend\View\Resolver\TemplatePathStack')); | |
return $this->setInstance($name, $return); | |
break; | |
case 'Zend\View\Resolver\TemplatePathStack': | |
$return = new $name; | |
$return->setPaths(array( | |
'application' => __DIR__ . '/../../../view' | |
)); | |
return $this->setInstance($name, $return); | |
break; | |
default: | |
return $this->setInstance($name, new $name); | |
break; | |
} | |
} | |
protected function setInstance($name, $instance) | |
{ | |
$this->instances[$name] = $instance; | |
return $instance; | |
} | |
protected function getInstance($name) | |
{ | |
return isset($this->instances[$name]) ? $this->instances[$name] : false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment