Zend Resource Autoloaders not working for namespaces

前端 未结 3 1924
南旧
南旧 2021-01-13 21:09

I have this autloading struggle with the Zend Framework. Basically there is a folder named LunaZend in library folder. LunaZend has some classes which can be used in Zend Fr

3条回答
  •  一个人的身影
    2021-01-13 21:40

    Yeah, well, this question seems to pop-up once in a while until a got the hang of namespaces (native ones) in ZF. Here's my take on this. This is for all you out there who just want to proper load some third party that's using namespaces. It's dead simple.

    I'm using ZF 1.11.11 (as per documentation, all ZF versions 1.10+ work).

    First of all, as of 1.10, ZF supports native PHP namespaces autoloading, provided they conform to the PSR-0 standard.

    I wanted to add the Symfony2 EventManager component in a ZF1 project.
    First off all, like with the class names, the namespace must match with the path in library. So, the namespace Symfony\Component\EventDispatcher\EventDispatcher maps to path/to/lib/Symfony/Component/EventDispatcher/EventDispatcher.php (where path/to/lib/ is APPLICATION_PATH . '/library'; you get the idea). Must I mention that the library folder must be in include_path? No, I guess I don't.

    Now with the-not-so-tricky-part:

    registerNamespace('Symfony'); // this is why is dead simple
    
            /* Don't believe me? Try it:
    
            Zend_Registry::set('events', new Symfony\Component\EventDispatcher\EventDispatcher());
    
            */
        }
    }
    

    How about using namespace imports in controllers?

    So, as long as you're on ZF 1.10+, there's no need for a custom autoloader. This reply was made after I peeked at this.

    LE: or add this to application.ini:
    autoloaderNamespaces[] = Symfony

提交回复
热议问题