I'm not sure about trying to add namespaces to a third-party library. For example, Twig does not use namespaces. And this is not necessary. Consider, for example, the case when you want to use the PDF component from the Zend_Framework 1 library.
In your app / autoload.php file, you would do something like:
$loader->registerPrefixes(array( 'Twig_Extensions_' => $ws . 'Symfony/vendor/twig-extensions/lib', 'Twig_' => $ws . 'Symfony/vendor/twig/lib', 'Zend_' => $ws . 'ZendFramework-1.0.0/library', )); // And since Zend internally uses require/include we need to set an include path ini_set('include_path','.' . PATH_SEPARATOR . $ws . 'ZendFramework-1.0.0/library' );
At this moment, we should be able to create objects of the 3rd part inside the controllers, allowing the startup system to take care of the search and inclusion of classes:
$page = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4); $doc->pages[] = $page; $font1 = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA); $font2 = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_COURIER_BOLD);
You need to use \ to get around the lack of a namespace.
This answer assumes that your 3rd part library conforms to more or less standard class naming conventions. If it has its own auto-download feature, just call autolaod.php. And if you donβt want to use autoload at all, just set the enable path and enable it.
source share