Reputation: 9040
I have a method within my bootstrap that sets up the caches for the application:
protected function _initSetCaches()
{
$this->bootstrap(array('Db','CacheManager'));
Zend_Db_Table_Abstract::setDefaultMetadataCache(Master::cache('database'));
Zend_Translate::setCache(Master::cache());
Zend_Date::setOptions(array('cache' => Master::cache()));
Zend_Paginator::setCache(Master::cache());
Zend_Locale::setCache(Master::cache());
Zend_Locale_Data::setCache(Master::cache());
}
As you can see, I set the various caches from calling a Master class containing a cache method. Within the cache method, I fetch the bootstrap object (self::bootstrap())
and then grab the cache type from the cachemanager resource. Here is the cache method within my Master class:
public static function cache($type='core')
{
$registryKey = 'master_cache_' . $type;
if(!self::registry($registryKey)){
$manager = self::bootstrap()->getPluginResource('cachemanager')->getCacheManager();
if(!$manager->hasCache($type)){
self::throwException(sprintf("%s is not an available cache",$type));
}
$cache = $manager->getCache($type);
self::register($registryKey,$cache);
}
return self::registry($registryKey);
}
As you can see, this method fetches the cachemanager from the bootstrap (self::bootstrap()
). My issue is the following... If I implement my bootstrap method as follows (registering the bootstrap by fetching it through the application object (self::app()
):
public static function bootstrap()
{
if(!self::registry('master_bootstrap')){
self::register('master_bootstrap', self::app()->getBootstrap());
}
return self::registry('master_bootstrap');
}
then everything works fine. However, this is a different implementation that what I originally had, which consequently, throws a circular dependancy exception. Here is my original implementation:
public static function bootstrap()
{
return self::app()->getBootstrap();
}
Im confused as to why when I register the bootstrap within the global registry I can use the cache method, however, if I just return the bootstrap object directly, it results in a circular dependency issue. Shouldnt the implementation in which I register the bootstrap object in the global registry still cause a circular dependency?
Upvotes: 2
Views: 219