Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created November 10, 2011 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ocramius/1353661 to your computer and use it in GitHub Desktop.
Save Ocramius/1353661 to your computer and use it in GitHub Desktop.
Exploring Zend\Di caching
<?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;
}
}
}
<?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