Created
April 29, 2012 18:51
-
-
Save prolic/2552626 to your computer and use it in GitHub Desktop.
Generated locator
This file contains hidden or 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; | |
use Zend\Di\Di; | |
class Context extends Di | |
{ | |
public function newInstance($name, array $params = array(), $isShared = true) | |
{ | |
if ($params) { | |
return parent::newInstance($name, $params, $isShared); | |
} | |
switch ($name) { | |
case 'Zend\EventManager\EventManager': | |
return $this->getZendEventManagerEventManager(false); | |
default: | |
return parent::newInstance($name, $params); | |
} | |
} | |
public function get($name, array $params = array()) | |
{ | |
array_push($this->instanceContext, array('GET', $name, null)); | |
$im = $this->instanceManager; | |
if ($params) { | |
$fastHash = $im->hasSharedInstanceWithParameters($name, $params, true); | |
if ($fastHash) { | |
array_pop($this->instanceContext); | |
return $im->getSharedInstanceWithParameters(null, array(), $fastHash); | |
} | |
} else { | |
if ($im->hasSharedInstance($name, $params)) { | |
array_pop($this->instanceContext); | |
return $im->getSharedInstance($name, $params); | |
} | |
} | |
if ($params) { | |
$instance = $this->newInstance($name, $params); | |
array_pop($this->instanceContext); | |
return $instance; | |
} | |
switch ($name) { | |
case 'Zend\EventManager\EventManager': | |
return $this->getZendEventManagerEventManager(); | |
default: | |
return parent::get($name, $params); | |
} | |
} | |
public function getZendEventManagerEventManager($shared = true) | |
{ | |
$object = new \Zend\EventManager\EventManager(); | |
$object->setSharedCollections($this->get('Zend\EventManager\SharedEventManager')); | |
if ($shared) { | |
$this->instanceManager->addSharedInstance($object, 'Zend\EventManager\EventManager'); | |
} | |
return $object; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment