|
Administrator
|
Hey, all --
I'm starting to write a proposal for ZF2 autoloading strategies. For those that missed my blog post, I've done some research and benchmarking of some different approaches: http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html The basic gist is: * Class map autoloaders are a nice way to get a performance boost from autoloading * The include_path is a horrible thing to rely on I've created a few autoloaders in my "autoloading" branch on GitHub: * ClassMapAutoloader http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/ClassMapAutoloader.php * Psr0Autoloader http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/Psr0Autoloader.php and also a class for generating class maps, and some utilities that consume it to create class map files: * ClassFileLocater http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/File/ClassFileLocater.php * zfal.php (creates files returning a classmap) http://github.com/weierophinney/zf2/blob/autoloading/bin/zfal.php * zfals.php (creates files that create a class map and register it with spl_autoload) http://github.com/weierophinney/zf2/blob/autoloading/bin/zfals.php While I like the simplicity of the latter approach: include 'path/to/_autoload.php'; $class = Some/Component/Classname(); I think that using an explicit class makes configuration a little easier (you can specify a list of paths to class maps you want to merge and serve as a single autoloader). That said, it may make sense to use the approach for shipping individual components, as we would not need to ship the autoloader and/or have a dependency on it in that situation. My proposal for ZF2 regarding autoloading is as follows: * Releases should ship with a class map for ZF2 * Individual component packages would contain a class map * ZF2 should ship with scripts for generating class maps * During development you could use a PSR-0-compliant autoloader, specifying directories of classes falling under specific namespaces * An autoloader factory would be included, to make configuration of multiple autoloaders and their options possible I'll work up some use cases soon, but the primary question I have at this point is: do any of you have recommendations on what to name the autoload class map files? I've been using "_autoload.php" in the directory immediately within the namespace: library/Zend/_autoload.php library/Zend/Controller/_autoload.php etc. This seems straightforward, but I wonder if there are any other opinions on naming, or the general strategy I propose? -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
Am 17.08.2010 17:30, schrieb Matthew Weier O'Phinney:
> I'll work up some use cases soon, but the primary question I have at > this point is: do any of you have recommendations on what to name the > autoload class map files? I've been using "_autoload.php" in the > directory immediately within the namespace: > > library/Zend/_autoload.php > library/Zend/Controller/_autoload.php > etc. > > This seems straightforward, but I wonder if there are any other > opinions on naming, or the general strategy I propose? I wonder why you'd create one map per directory. Wouldn't that result in a lot of includes? I'm asking, why not create one huge class map? -- Ben Scholzen 'DASPRiD' Community Review Team Member | [hidden email] Zend Framework | http://www.dasprids.de PGP key: http://stuff.dasprids.de/pgp/ben-scholzen-pgp-key.asc |
|
On Tue, Aug 17, 2010 at 7:39 PM, Ben Scholzen <[hidden email]> wrote:
> I wonder why you'd create one map per directory. Wouldn't that result in > a lot of includes? I'm asking, why not create one huge class map? If the reason is - and I assume it to be - that you can easily create separate packages, my suggestion would be to create the packages first, and then create one map file per package. To be clear, aside from implementing those map files, I am right in saying that even without those map files it would work (though a little more slowly), correct? Dolf -- Freeaqingme |
|
Administrator
|
In reply to this post by Ben Scholzen 'DASPRiD'
-- Ben Scholzen <[hidden email]> wrote
(on Tuesday, 17 August 2010, 07:39 PM +0200): > Am 17.08.2010 17:30, schrieb Matthew Weier O'Phinney: > > I'll work up some use cases soon, but the primary question I have at > > this point is: do any of you have recommendations on what to name the > > autoload class map files? I've been using "_autoload.php" in the > > directory immediately within the namespace: > > > > library/Zend/_autoload.php > > library/Zend/Controller/_autoload.php > > etc. > > > > This seems straightforward, but I wonder if there are any other > > opinions on naming, or the general strategy I propose? > > I wonder why you'd create one map per directory. Wouldn't that result in > a lot of includes? I'm asking, why not create one huge class map? For general purposes, you'd simply use the one directly below the library/Zend/ directory. Per-component map files would only be shipped with individual components (as that's one goal for ZF2 -- the ability to package and distribute individual components via a PEAR channel). Additionally, while there would be one below the library/Zend/ directory, what about other libraries you have? The tool would be able to create such maps for you -- giving some portability to those libraries. You could then do this: $classmap = new Zend\Loader\ClassMapAutoloader(); $classmap->registerAutoloadMap(LIBDIR . '/Zend') ->registerAutoloadMap(LIBDIR . '/Doctrine') ->registerAutoloadMap(LIBDIR . '/Phly'); $classmap->register(); or, via configuration: loader.ClassMapAutoloader.maps[] = LIBDIR "/Zend" loader.ClassMapAutoloader.maps[] = LIBDIR "/Doctrine" loader.ClassMapAutoloader.maps[] = LIBDIR "/Phly" Hope that helps clarify some of my points. -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
In reply to this post by weierophinney
On Tue, Aug 17, 2010 at 5:30 PM, Matthew Weier O'Phinney <[hidden email]> wrote: * During development you could use a PSR-0-compliant autoloader, I like this trait since the _autoload.php files contain a form of duplication (the list of classes and files). They should probably be generated during the build process of a release/package, and not stored under version control. Overall I think this is a nice and innovating idea. Would this affect also plugin loaders, like view/action helpers and similar ones? -- Giorgio Sironi Piccolo Principe & Web Engineer http://giorgiosironi.blogspot.com http://twitter.com/giorgiosironi |
|
In reply to this post by weierophinney
That's a nice idea!
Outside of the performance boost I never liked it to put every lib to include path. But I don't like the name "Zend/Component/_autoload.php" because autoload sounds like a file including/registering autoload functions but it's only a data file shipped as a php array. A simple "classmap.php" should be more clear and in my opinion should located under a resource directory like the xml files of Zend\Locale. (e.g. Zend\Component\resources\classmap.php) Additionally within your method "Zend\Loader\ClassMapAutoloader::autoload" you use the function array_key_exists but the pathname can't be NULL and an isset has much better performance. Greetings Marc On 17.08.2010 17:30, Matthew Weier O'Phinney wrote: > Hey, all -- > > I'm starting to write a proposal for ZF2 autoloading strategies. For > those that missed my blog post, I've done some research and benchmarking > of some different approaches: > > http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html > > The basic gist is: > > * Class map autoloaders are a nice way to get a performance boost from > autoloading > * The include_path is a horrible thing to rely on > > I've created a few autoloaders in my "autoloading" branch on GitHub: > > * ClassMapAutoloader > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/ClassMapAutoloader.php > * Psr0Autoloader > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/Psr0Autoloader.php > > and also a class for generating class maps, and some utilities that > consume it to create class map files: > > * ClassFileLocater > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/File/ClassFileLocater.php > * zfal.php (creates files returning a classmap) > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfal.php > * zfals.php (creates files that create a class map and register it with > spl_autoload) > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfals.php > > While I like the simplicity of the latter approach: > > include 'path/to/_autoload.php'; > $class = Some/Component/Classname(); > > I think that using an explicit class makes configuration a little > easier (you can specify a list of paths to class maps you want to merge > and serve as a single autoloader). That said, it may make sense to use > the approach for shipping individual components, as we would not need to > ship the autoloader and/or have a dependency on it in that situation. > > My proposal for ZF2 regarding autoloading is as follows: > > * Releases should ship with a class map for ZF2 > * Individual component packages would contain a class map > * ZF2 should ship with scripts for generating class maps > * During development you could use a PSR-0-compliant autoloader, > specifying directories of classes falling under specific namespaces > * An autoloader factory would be included, to make configuration of > multiple autoloaders and their options possible > > I'll work up some use cases soon, but the primary question I have at > this point is: do any of you have recommendations on what to name the > autoload class map files? I've been using "_autoload.php" in the > directory immediately within the namespace: > > library/Zend/_autoload.php > library/Zend/Controller/_autoload.php > etc. > > This seems straightforward, but I wonder if there are any other > opinions on naming, or the general strategy I propose? > |
|
Thinking out loud here, doesn't a name like _autoload.conf.php make
more sense? Sounds more descriptive to me... Dolf -- Freeaqingme |
|
In reply to this post by weierophinney
Am 17.08.2010 20:37, schrieb Matthew Weier O'Phinney:
> For general purposes, you'd simply use the one directly below the > library/Zend/ directory. Per-component map files would only be shipped > with individual components (as that's one goal for ZF2 -- the ability to > package and distribute individual components via a PEAR channel). > > Additionally, while there would be one below the library/Zend/ > directory, what about other libraries you have? The tool would be able > to create such maps for you -- giving some portability to those > libraries. You could then do this: > > $classmap = new Zend\Loader\ClassMapAutoloader(); > $classmap->registerAutoloadMap(LIBDIR . '/Zend') > ->registerAutoloadMap(LIBDIR . '/Doctrine') > ->registerAutoloadMap(LIBDIR . '/Phly'); > $classmap->register(); > > or, via configuration: > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Zend" > loader.ClassMapAutoloader.maps[] = LIBDIR "/Doctrine" > loader.ClassMapAutoloader.maps[] = LIBDIR "/Phly" > > Hope that helps clarify some of my points. Makes sense. Well in that case, I'd name it ".autoload.map.php" (the beginning dot is intended). -- Ben Scholzen 'DASPRiD' Community Review Team Member | [hidden email] Zend Framework | http://www.dasprids.de PGP key: http://stuff.dasprids.de/pgp/ben-scholzen-pgp-key.asc |
|
Making it a dot file makes a lot of sense indeed. +1 for that. On Tue, Aug 17, 2010 at 4:13 PM, Ben Scholzen <[hidden email]> wrote: Am 17.08.2010 20:37, schrieb Matthew Weier O'Phinney: -- Nicolas A. Bérard-Nault ([hidden email]) |
|
This post has NOT been accepted by the mailing list yet.
In reply to this post by weierophinney
> library/Zend/Controller/_autoload.php
I like it in general and would like to see the name be something like: ".autoload.map.php" or ".autoload.classmap.php" or simply ".classmap.php" -- Wil Moore III
--
Wil Moore III Best Practices for Working with Open-Source Developers http://www.faqs.org/docs/artu/ch19s02.html Why is Bottom-posting better than Top-posting: http://www.caliburn.nl/topposting.html DO NOT TOP-POST and DO trim your replies: http://linux.sgms-centre.com/misc/netiquette.php#toppost |
|
In reply to this post by weierophinney
autoloader should never rely on include_path.
I wish the autoloader could be very independent on any other component, even Zend_Exception if possible. In some cases, Zend Framework is adopted as a sub-lib but the autoloader is desired as global autoloader. On Tue, Aug 17, 2010 at 11:30 PM, Matthew Weier O'Phinney <[hidden email]> wrote: > Hey, all -- > > I'm starting to write a proposal for ZF2 autoloading strategies. For > those that missed my blog post, I've done some research and benchmarking > of some different approaches: > > http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html > > The basic gist is: > > * Class map autoloaders are a nice way to get a performance boost from > autoloading > * The include_path is a horrible thing to rely on > > I've created a few autoloaders in my "autoloading" branch on GitHub: > > * ClassMapAutoloader > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/ClassMapAutoloader.php > * Psr0Autoloader > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/Psr0Autoloader.php > > and also a class for generating class maps, and some utilities that > consume it to create class map files: > > * ClassFileLocater > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/File/ClassFileLocater.php > * zfal.php (creates files returning a classmap) > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfal.php > * zfals.php (creates files that create a class map and register it with > spl_autoload) > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfals.php > > While I like the simplicity of the latter approach: > > include 'path/to/_autoload.php'; > $class = Some/Component/Classname(); > > I think that using an explicit class makes configuration a little > easier (you can specify a list of paths to class maps you want to merge > and serve as a single autoloader). That said, it may make sense to use > the approach for shipping individual components, as we would not need to > ship the autoloader and/or have a dependency on it in that situation. > > My proposal for ZF2 regarding autoloading is as follows: > > * Releases should ship with a class map for ZF2 > * Individual component packages would contain a class map > * ZF2 should ship with scripts for generating class maps > * During development you could use a PSR-0-compliant autoloader, > specifying directories of classes falling under specific namespaces > * An autoloader factory would be included, to make configuration of > multiple autoloaders and their options possible > > I'll work up some use cases soon, but the primary question I have at > this point is: do any of you have recommendations on what to name the > autoload class map files? I've been using "_autoload.php" in the > directory immediately within the namespace: > > library/Zend/_autoload.php > library/Zend/Controller/_autoload.php > etc. > > This seems straightforward, but I wonder if there are any other > opinions on naming, or the general strategy I propose? > > -- > Matthew Weier O'Phinney > Project Lead | [hidden email] > Zend Framework | http://framework.zend.com/ > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc > |
|
In reply to this post by Nicolas A. Bérard-Nault
I'm sure this is way above me, but is it intentional that there's both:
ClassMapAutoloader registerAutoloadMap If you have the class ClassMapAutoloader should the register function be more like: registerMapAutoloader() ? Perhaps the verbage is correct because of the intention of the class versus the function? Either way.... it's exciting stuff. 2010/8/17 Nicolas A. Bérard-Nault <[hidden email]>
|
|
In reply to this post by weierophinney
Not sure I like calling it autoload over the more obvious classmap... +1 for the dot naming though! Paddy
|
|
Administrator
|
In reply to this post by Anthony Shireman
-- Anthony Shireman <[hidden email]> wrote
(on Tuesday, 17 August 2010, 06:27 PM -0700): > I'm sure this is way above me, but is it intentional that there's both: > > ClassMapAutoloader > registerAutoloadMap > > If you have the class ClassMapAutoloader should the register function > be more like: registerMapAutoloader() ? No -- because you're actually just registering a class map for use with the autoloader, not an actual autoloader. Perhaps a better name would be "registerClassMap()". > Perhaps the verbage is correct because of the intention of the class > versus the function? > > Either way.... it's exciting stuff. > > > > 2010/8/17 Nicolas A. Bérard-Nault <[hidden email]> > > Making it a dot file makes a lot of sense indeed. +1 for that. > > On Tue, Aug 17, 2010 at 4:13 PM, Ben Scholzen <[hidden email]> wrote: > > Am 17.08.2010 20:37, schrieb Matthew Weier O'Phinney: > > For general purposes, you'd simply use the one directly below the > > library/Zend/ directory. Per-component map files would only be > shipped > > with individual components (as that's one goal for ZF2 -- the ability > to > > package and distribute individual components via a PEAR channel). > > > > Additionally, while there would be one below the library/Zend/ > > directory, what about other libraries you have? The tool would be > able > > to create such maps for you -- giving some portability to those > > libraries. You could then do this: > > > > $classmap = new Zend\Loader\ClassMapAutoloader(); > > $classmap->registerAutoloadMap(LIBDIR . '/Zend') > > ->registerAutoloadMap(LIBDIR . '/Doctrine') > > ->registerAutoloadMap(LIBDIR . '/Phly'); > > $classmap->register(); > > > > or, via configuration: > > > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Zend" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Doctrine" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Phly" > > > > Hope that helps clarify some of my points. > > Makes sense. Well in that case, I'd name it ".autoload.map.php" (the > beginning dot is intended). > > -- > Ben Scholzen 'DASPRiD' > Community Review Team Member | [hidden email] > Zend Framework | http://www.dasprids.de > PGP key: http://stuff.dasprids.de/pgp/ben-scholzen-pgp-key.asc > > > > > -- > Nicolas A. Bérard-Nault ([hidden email]) > > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
Administrator
|
In reply to this post by padraicb
-- Pádraic Brady <[hidden email]> wrote
(on Wednesday, 18 August 2010, 12:39 AM -0700): > Not sure I like calling it autoload over the more obvious classmap... +1 for > the dot naming though! Oh, good point on "classmap" vs. "autoload" -- the latter is more appropriate if we were registering with spl_autoload directly, while the former is more appropriate for the ClassMapAutoloader (as it's simply the class map itself). I'm of mixed thoughts on having it as a dot-file. On the one hand, as metadata, that's an appropriate paradigm. On the other hand, having it hidden means it may introduce a WTF factor for developers trying to figure out where the map is coming from. > On 17 Aug 2010, at 21:25, Nicolas A. Bérard-Nault <[hidden email]> wrote: > > > Making it a dot file makes a lot of sense indeed. +1 for that. > > On Tue, Aug 17, 2010 at 4:13 PM, Ben Scholzen < [hidden email]> wrote: > > Am 17.08.2010 20:37, schrieb Matthew Weier O'Phinney: > > For general purposes, you'd simply use the one directly below the > > library/Zend/ directory. Per-component map files would only be > shipped > > with individual components (as that's one goal for ZF2 -- the ability > to > > package and distribute individual components via a PEAR channel). > > > > Additionally, while there would be one below the library/Zend/ > > directory, what about other libraries you have? The tool would be > able > > to create such maps for you -- giving some portability to those > > libraries. You could then do this: > > > > $classmap = new Zend\Loader\ClassMapAutoloader(); > > $classmap->registerAutoloadMap(LIBDIR . '/Zend') > > ->registerAutoloadMap(LIBDIR . '/Doctrine') > > ->registerAutoloadMap(LIBDIR . '/Phly'); > > $classmap->register(); > > > > or, via configuration: > > > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Zend" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Doctrine" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Phly" > > > > Hope that helps clarify some of my points. > > Makes sense. Well in that case, I'd name it ".autoload.map.php" (the > beginning dot is intended). > > -- > Ben Scholzen 'DASPRiD' > Community Review Team Member | [hidden email] > Zend Framework | http://www.dasprids.de > PGP key: http://stuff.dasprids.de/pgp/ben-scholzen-pgp-key.asc > > > > > -- > Nicolas A. Bérard-Nault ( [hidden email]) > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
Administrator
|
In reply to this post by Marc Bennewitz (private)
-- Marc Bennewitz <[hidden email]> wrote
(on Tuesday, 17 August 2010, 10:07 PM +0200): > That's a nice idea! > > Outside of the performance boost I never liked it to put every lib to > include path. > > But I don't like the name "Zend/Component/_autoload.php" because > autoload sounds like a file including/registering autoload functions but > it's only a data file shipped as a php array. > A simple "classmap.php" should be more clear and in my opinion should > located under a resource directory like the xml files of Zend\Locale. > (e.g. Zend\Component\resources\classmap.php) I like the idea of "classmap.php" very much -- it was suggested by others later in the thread as well. > Additionally within your method > "Zend\Loader\ClassMapAutoloader::autoload" you use the function > array_key_exists but the pathname can't be NULL and an isset has much > better performance. The performance gain from that is actually negligible for the number of uses we're talking about, but the argument that it also protects against null paths is a good one. > On 17.08.2010 17:30, Matthew Weier O'Phinney wrote: > > Hey, all -- > > > > I'm starting to write a proposal for ZF2 autoloading strategies. For > > those that missed my blog post, I've done some research and benchmarking > > of some different approaches: > > > > http://weierophinney.net/matthew/archives/245-Autoloading-Benchmarks.html > > > > The basic gist is: > > > > * Class map autoloaders are a nice way to get a performance boost from > > autoloading > > * The include_path is a horrible thing to rely on > > > > I've created a few autoloaders in my "autoloading" branch on GitHub: > > > > * ClassMapAutoloader > > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/ClassMapAutoloader.php > > * Psr0Autoloader > > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/Loader/Psr0Autoloader.php > > > > and also a class for generating class maps, and some utilities that > > consume it to create class map files: > > > > * ClassFileLocater > > http://github.com/weierophinney/zf2/blob/autoloading/library/Zend/File/ClassFileLocater.php > > * zfal.php (creates files returning a classmap) > > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfal.php > > * zfals.php (creates files that create a class map and register it with > > spl_autoload) > > http://github.com/weierophinney/zf2/blob/autoloading/bin/zfals.php > > > > While I like the simplicity of the latter approach: > > > > include 'path/to/_autoload.php'; > > $class = Some/Component/Classname(); > > > > I think that using an explicit class makes configuration a little > > easier (you can specify a list of paths to class maps you want to merge > > and serve as a single autoloader). That said, it may make sense to use > > the approach for shipping individual components, as we would not need to > > ship the autoloader and/or have a dependency on it in that situation. > > > > My proposal for ZF2 regarding autoloading is as follows: > > > > * Releases should ship with a class map for ZF2 > > * Individual component packages would contain a class map > > * ZF2 should ship with scripts for generating class maps > > * During development you could use a PSR-0-compliant autoloader, > > specifying directories of classes falling under specific namespaces > > * An autoloader factory would be included, to make configuration of > > multiple autoloaders and their options possible > > > > I'll work up some use cases soon, but the primary question I have at > > this point is: do any of you have recommendations on what to name the > > autoload class map files? I've been using "_autoload.php" in the > > directory immediately within the namespace: > > > > library/Zend/_autoload.php > > library/Zend/Controller/_autoload.php > > etc. > > > > This seems straightforward, but I wonder if there are any other > > opinions on naming, or the general strategy I propose? > > > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
Administrator
|
In reply to this post by Giorgio Sironi
-- Giorgio Sironi <[hidden email]> wrote
(on Tuesday, 17 August 2010, 08:49 PM +0200): > On Tue, Aug 17, 2010 at 5:30 PM, Matthew Weier O'Phinney <[hidden email]> > wrote: > > * During development you could use a PSR-0-compliant autoloader, > specifying directories of classes falling under specific namespaces > > > I like this trait since the _autoload.php files contain a form of duplication > (the list of classes and files). They should probably be generated during the > build process of a release/package, and not stored under version control. Agreed. During development, particularly these early milestones, having an explicit classmap in master will be a no-go due to additions, renames, etc. of classes. That said, I think once we get more stable, having the classmap on master may make sense, though it should be re-generated for each release to ensure no classes are omitted. > Overall I think this is a nice and innovating idea. Would this affect also > plugin loaders, like view/action helpers and similar ones? I started working on plugin loading yesterday. The approach I'm working on is actually quite similar: aliasing. Instead of relying on a stack of paths (which, by the way, has been the source of many issues reported against components with plugins, as well as a stumbling block for those learning ZF), we'd use explicit aliasing of short names to fully qualified class names. The advantages are several: * case sensitivity is no longer an issue * it's easy to determine when you're overriding an existing plugin (you have to register it via configuration or in your code) * since it no longer needs to loop over directories and search for existing files, we eliminate all stat calls except for when the class is loaded -- and now the class will be loaded by the autoloader, which means we'll benefit from gains in autoloading. I'm hoping to have a prototype to post by the end of this week (as I go on vacation starting Saturday); I'll have code up in a branch on github likely today, though. -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
In reply to this post by weierophinney
I understand the reluctance, but it's perfectly normal for a Linux environment and shouldn't be that much of a surprise to Linux/*nix users if documented as such. We can forget about the Windows folk since it would never be a hidden file on that system anyway.
Paddy http://blog.astrumfutura.com http://www.survivethedeepend.com Zend Framework Community Review Team From: Matthew Weier O'Phinney <[hidden email]> To: [hidden email] Sent: Wed, August 18, 2010 1:33:25 PM Subject: Re: [zf-contributors] ZF2 Autoloading strategies proposal -- Pádraic Brady <[hidden email]> wrote (on Wednesday, 18 August 2010, 12:39 AM -0700): > Not sure I like calling it autoload over the more obvious classmap... +1 for > the dot naming though! Oh, good point on "classmap" vs. "autoload" -- the latter is more appropriate if we were registering with spl_autoload directly, while the former is more appropriate for the ClassMapAutoloader (as it's simply the class map itself). I'm of mixed thoughts on having it as a dot-file. On the one hand, as metadata, that's an appropriate paradigm. On the other hand, having it hidden means it may introduce a WTF factor for developers trying to figure out where the map is coming from. > On 17 Aug 2010, at 21:25, Nicolas A. Bérard-Nault <[hidden email]> wrote: > > > Making it a dot file makes a lot of sense indeed. +1 for that. > > On Tue, Aug 17, 2010 at 4:13 PM, Ben Scholzen < [hidden email]> wrote: > > Am 17.08.2010 20:37, schrieb Matthew Weier O'Phinney: > > For general purposes, you'd simply use the one directly below the > > library/Zend/ directory. Per-component map files would only be > shipped > > with individual components (as that's one goal for ZF2 -- the ability > to > > package and distribute individual components via a PEAR channel). > > > > Additionally, while there would be one below the library/Zend/ > > directory, what about other libraries you have? The tool would be > able > > to create such maps for you -- giving some portability to those > > libraries. You could then do this: > > > > $classmap = new Zend\Loader\ClassMapAutoloader(); > > $classmap->registerAutoloadMap(LIBDIR . '/Zend') > > ->registerAutoloadMap(LIBDIR . '/Doctrine') > > ->registerAutoloadMap(LIBDIR . '/Phly'); > > $classmap->register(); > > > > or, via configuration: > > > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Zend" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Doctrine" > > loader.ClassMapAutoloader.maps[] = LIBDIR "/Phly" > > > > Hope that helps clarify some of my points. > > Makes sense. Well in that case, I'd name it ".autoload.map.php" (the > beginning dot is intended). > > -- > Ben Scholzen 'DASPRiD' > Community Review Team Member | [hidden email] > PGP key: http://stuff.dasprids.de/pgp/ben-scholzen-pgp-key.asc > > > > > -- > Nicolas A. Bérard-Nault ( [hidden email]) > -- Matthew Weier O'Phinney Project Lead | [hidden email] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc |
|
I was looking at the Zend_Loader loadClass method and noticed that it
always throw an exception if it could not load the desired class. Can this be optional? Sometimes it might be OK that the class does not exist even when trying to load it via the autoloader, eg: if (class_exists('Custom_Override_Class')) { $obj = new Custom_Override_Class(); } else { $obj = new Default_Class(); } $obj->doSomething(); -- Greg |
|
Instead of making it optional, you probably just need to catch the exception and handle it in a way that doesn't make your code blow up :-)
On Sun, Sep 5, 2010 at 3:19 PM, Greg <[hidden email]> wrote: I was looking at the Zend_Loader loadClass method and noticed that it |
| Powered by Nabble | Edit this page |
