-- debussy007 <[email protected]> wrote
(on Sunday, 12 July 2009, 04:23 PM -0700):
> I have read your article
> http://devzone.zend.com/article/4525-Developing-a-Comprehensive-Autoloader
>
> It seems that you also have name of classes that doesn't fully
> correspond to the real path to those classes, e.g.
> models/Guestbook.php and the classname is Foo_Model_Guestbook
These utilize the resource autoloader (Zend_Loader_Autoloader_Resource /
Zend_Application_Module_Autoloader) in order to map the name to a
filesystem location. As such, they are still namespaced, and follow
specific rules for mapping the name to the location. This is the second
of the two solutions I provided to you.
> However in your migration chapter you only mention to use (in the
> "preferred" point) something like :
> $autoloader = Zend_Loader_Autoloader::getInstance();
> $autoloader->registerNamespace('Foo_');
> $autoloader->registerNamespace(array('Foo_', 'Bar_'));
This is for libraries on your include path, and corresponds to the first
solution I provided to you.
> And you do not use protected function _initAppAutoloader() as you
> suggested to me.
The migration chapter was written for those using
Zend_Loader::registerAutoload(), as that corresponds to the specific
use case Zend_Loader_Autoloader solves. Prior to 1.8, we had no
equivalent for resource autoloading, so a migration chapter made no
sense -- it's new functionality.
Please, try the code I provided to you -- it will work, and it will work
from this point forward.
> Matthew Weier O'Phinney-3 wrote:
> >
> > -- debussy007 <[email protected]> wrote
> > (on Sunday, 12 July 2009, 08:40 AM -0700):
> >> I understand the namespace to avoid collisions between different
> >> libraries,
> >> but I didn't understand your second point about extending classes. With
> >> or
> >> without namespaces I may extend a class to get a more specific behavior.
> >
> > Right, but if you do it in your own namespace, you can then version that
> > class, use it in all your projects... and then keep it up-to-date with
> > API changes on the original.
> >
> >> I have an error updating it to 1.8 because of the new namespaces added
> >> :-(
> >>
> >> Warning: include(My\Constants.php) [function.include]: failed to open
> >> stream: No such file or directory in
> >> C:\Data\websites\cms\library\Zend\Loader.php on line 83
> >>
> >> $autoloader = Zend_Loader_Autoloader::getInstance();
> >> $autoloader->registerNamespace(array('My_', 'MyZend_'));
> >>
> >> I have a class My_Constants and it's path is
> >> application/constants/Constants.php
> >> In the include path I added './application/constants/'
> >
> > Then the issue is that there isn't a 1:1 relationship between the class
> > name and the filename, and you have two options:
> >
> > * If you want it on the include_path, have it in My/Constants.php
> > somewhere on that include_path.
> >
> > * If it's application-specific (which, based on your filesystem
> > positioning, appears to be the case), create or modify your resource
> > autoloader. If we go with the latter, try adding the following
> > method to your application bootstrap:
> >
> > protected function _initAppAutoloader()
> > {
> > $al = new Zend_Application_Module_Autoloader(array(
> > 'namespace' => 'My',
> > 'basePath' => dirname(__FILE__),
> > ));
> > $al->addResourceType('constant', 'constants', 'Constant');
> > }
> >
> > Then, I'd rename your file to application/constants/App.php,
> > with the class 'My_Constant_App', and you should be set.
> >
> >> Matthew Weier O'Phinney-3 wrote:
> >> >
> >> > -- debussy007 <[email protected]> wrote
> >> > (on Sunday, 12 July 2009, 02:09 AM -0700):
> >> >> I updated the library for one of my projects to 1.8 and I need some
> >> >> advice
> >> >> on renaming my classes with namespaces ...
> >> >>
> >> >> Should I prefix all my classes (which are not part of a specific
> >> library)
> >> >> by
> >> >> the same namespace ? e.g. My_...
> >> >>
> >> >> My_Constants
> >> >> My_Model_DbTable_Articles
> >> >> My_Plugin_LanguageHandler
> >> >> and so on ?
> >> >
> >> > Typically, yes. :) It's a recommendation of the PHP project itself, as
> >> > well as PEAR and ZF. It helps with avoiding naming collisions, and also
> >> > allows you to extend classes locally to provide alternate behavior.
> >> >
> >> > --
> >> > Matthew Weier O'Phinney
> >> > Project Lead | [email protected]
> >> > Zend Framework | http://framework.zend.com/
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Namespace-help-tp24446973p24449740.html
> >> Sent from the Zend Framework mailing list archive at Nabble.com.
> >>
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead | [email protected]
> > Zend Framework | http://framework.zend.com/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Namespace-help-tp24446973p24453421.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/