easily addressed by using the Fallback AutoLoader, thing I would like
to avoid.
Many external libraries like Doctrine have a main file with the same
name of the class, following this structure
/Doctrine.php -> class Doctrine
/Doctrine/Access.php -> class Doctrine_Access
/Doctrine/Adapter.php -> class Doctrine_Adapter
...and so on.
originally, even Zend Framework followed this, quite common, design.
Now, after I setup the autoloader correctly, I'm getting the following
error: Fatal error: Class 'Doctrine' not found in
/Users/jules/Sviluppo/fresh-cms/library/Doctrine/Manager.php on line
95
As you may notice the autoloader manages to load any class of the
Doctrine library but the main one.
Here's my Bootstrap.php file:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initGenericAutoloader()
{
$loader = Zend_Loader_Autoloader::getInstance();
return $loader;
}
protected function _initDoctrine()
{
$config = $this->getOption('doctrine');
$doctrine = Doctrine_Manager::getInstance();
$doctrine->openConnection($config['connection']);
Zend_Registry::set('doctrine_config', $config);
return $doctrine;
}
}
I can easily fix it through one of the following workarounds, but I
dislike both:
- add a require_once 'Doctrine.php' statemente in the _initDoctrine() method
- adding the Doctrine namespace to the autoloader like that:
Zend_Loader_Autoloader::getInstance()->registerNamespace('Doctrine');
which is bad either because it's too loosy but makes it pick the
Doctrine.php file; the namespacing parameter should be 'Doctrine/' to
make it stick to the desired framework as by the ZF documentation.
- using the FallBackAutoLoader which I'd like to avoid.
This is a recurring issue, since several framework and libraries have
the same folder structure of Doctrine, is there a good practice to let
the default autoloader manage them correctly?
Thanks,
Jules Piccotti
没有评论:
发表评论