Created
November 10, 2011 00:22
-
-
Save Ocramius/1353661 to your computer and use it in GitHub Desktop.
Exploring Zend\Di caching
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 My\Di\Cache; | |
use Zend\Di\Di as ZendDi; | |
class CompiledDi extends ZendDi { | |
public function get($name, $params = array()) { | |
if($params) { | |
return parent::get($name, $params); | |
} | |
//just a sample protected var used here. Don't know how it is called in Zend\Di\Di | |
if(isset($this->_instances[$name])) { | |
return $this->_instances[$name]; | |
} | |
switch($name) { | |
case 'zfmongodbodm-cachedreader': | |
return new \Doctrine\Common\Annotations\CachedReader( | |
$this->get('zfmongodbodm-indexedreader'), | |
$this->get('zfmongodbodm-annotationcache') | |
); | |
break; | |
case 'zfmongodbodm-annotationcache': | |
return new Doctrine\Common\Cache\ArrayCache('some_namespace'); | |
break; | |
case 'zfmongodbodm-indexedreader': | |
return new \Doctrine\Common\Annotations\IndexedReader( | |
$this->get('zfmongodbodm-annotationreader') | |
); | |
break; | |
case 'zfmongodbodm-annotationreader': | |
return new \Doctrine\Common\Annotations\AnnotationReader(); | |
break; | |
default: | |
return parent::get($name); | |
break; | |
} | |
} | |
} |
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 | |
//This is the current instance definition: | |
return array( | |
'instance' => array( | |
'alias' => array( | |
'zfmongodbodm-cachedreader' => 'Doctrine\Common\Annotations\CachedReader', | |
'zfmongodbodm-annotationcache' => 'Doctrine\Common\Cache\ArrayCache', | |
'zfmongodbodm-indexedreader' => 'Doctrine\Common\Annotations\IndexedReader', | |
'zfmongodbodm-annotationreader' => 'Doctrine\Common\Annotations\AnnotationReader', | |
), | |
//parameters configuration | |
'zfmongodbodm-cachedreader' => array( | |
'parameters' => array( | |
'reader' => 'zfmongodbodm-indexedreader', | |
'cache' => 'zfmongodbodm-annotationcache', | |
), | |
), | |
'zfmongodbodm-annotationcache' => array( | |
'parameters' => array( | |
'namespace' => 'zfmongodbodm_annotation', | |
), | |
), | |
'zfmongodbodm-indexedreader' => array( | |
'parameters' => array( | |
'reader' => 'zfmongodbodm-annotationreader', | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment