Re: [Coding Standards] Loading all files at once

From: Date: Tue, 10 Jul 2007 13:12:30 +0000
Subject: Re: [Coding Standards] Loading all files at once
References: 1 2 3 4 5  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-47382@lists.php.net to get a copy of this message
On Jul 10, 2007, at 7:59 AM, Matthew Weier O'Phinney wrote:
On 7/9/07, Joshua Eichorn <josh@bluga.net> wrote:
Matthew Weier O'Phinney wrote:
I'm clueless as to what you're referring to here. I use PEAR,
Solar, and
Zend Framework regularly, and typically have them installed to a
common
directory, leaving me with a simple include_path of: .:/path/to/pear and never have a problem, even when using __autoload() (check out Zend_Loader::registerAutoload() for a PEAR-friendly spl_autoload implementation, btw). Could you please elaborate on the
"include_path
mess" that you're trying to solve with this?
Trying making this work without setting your include path.
Honestly, if a developer can't set the include_path, s/he probably needs to read the PHP manual a bit more. However, even this can be relatively easily overcome with something like a PEAR2_Loader class; if we create methods to manipulate the include_path, it could be something like this: require_once '/path/to/PEAR2/Loader.php'; PEAR2_Loader::initIncludePath(); // Sets the include_path to
                                      // include PEAR2 based on the
                                      // location of the PEAR2_Loader
                                      // class file.
PEAR2_Loader::registerAutoload(); // Register autoload callback
                                      // with spl_autoload.
Also note that you have a mix of autoload and normal includes, which may or may not give you the minimum # of required files.
It'll almost certainly give you fewer than those loaded via allfiles.php.
Alexey Borzov, in a related thread, remarks:
Now that I have a better understanding of what we are trying to achieve, I'd like to present a solution that looks better to me: * Create a PEAR2_Loader class that'll take care of loading files / classes * Disallow direct inclusion of files in packages via include[_once] / require[_once] * All inclusions should go through PEAR2_Loader::loadClass('classname'); or PEAR2_Loader::loadFile('filename'); * PEAR2_Loader will also provide an __autoload() implementation for PEAR2 classes. * PEAR2_Loader may be configured to use include_path / not use include_path / make loadClass() a no-op (if called from hypothetical allfiles.php) * Instead of directly using an allfiles.php, PEAR2_Loader may have a loadPackage() convenience method.
Zend and Solar both use a static method for class-loading; I think PEAR2 might benefit from using something like that too. (It's not a base class, just a class with some static methods.) Alexey's inclusion of a loadPackage() method is particularly interesting. However, there is a chicken-and-egg problem here: you have to include the PEAR2_Loader class to begin with. Dunno if that's a deal-breaker or not. -- Paul M. Jones <http://paul-m-jones.com> Solar: Simple Object Library and Application Repository for PHP5. <http://solarphp.com> Join the Solar community wiki! <http://solarphp.org> Savant: The simple, elegant, and powerful solution for templates in PHP. <http://phpsavant.com>

« previous php.pear.dev (#47382) next »