Re: Re: Silencing @
| From: | Alan Knowles | Date: | Tue, 01 Nov 2005 00:30:10 +0000 |
| Subject: | Re: Re: Silencing @ | ||
| References: | 1 2 3 4 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-3207@lists.php.net to get a copy of this message | ||
Of course the big question you have to ask is:
Is this an end user error, or a serious program/setup issue.. - in which
case good ole PHP errors are probably more helpfull than anything you
can write. (obviously PEAR installer may be a little different, but for
most PEAR Packages, I suspect the later is the case)
Regards
Alan
On Mon, 2005-10-31 at 17:52 -0600, Greg Beaver wrote:
> Ian Eure wrote:
>
> > What I typically do is:
> >
> > function factory($driver)
> > {
> > $file = 'My/Package/' . $driver . '.php;
> > $class = 'My_Package_Driver';
> > if (!file_exists($file)) {
> > return PEAR::raiseError(...);
> > }
> > include_once $file;
> > if (!class_exists($class)) {
> > return PEAR::raiseError(...);
> > }
> > return new $class();
> > }
> >
> > Any other suggestions? I don't really like using $driver without
> > veriification. Perhaps filtering it through escapeshellarg()? Not sure
> > this is all CS-worthy, but some best practices would be nice.
>
> Better is:
>
> function factory($driver)
> {
> $file = 'My/Package/' . $driver . '.php;
> $class = 'My_Package_Driver';
> if (class_exists($class)) {
> return new $class;
> }
> $ip = get_include_path();
> foreach (explode(PATH_SEPARATOR, $ip) as $fragment) {
> if (file_exists($frag . DIRECTORY_SEPARATOR . $file)) {
> include_once $file;
> break;
> }
> }
> if (!class_exists($class)) {
> return PEAR::raiseError(...);
> }
> return new $class;
> }
>
> this scans the include_path. Your example will only work if the file is
> in a subdirectory of the current directory.
>
> Examples of a way to do this generically are in PEAR_Common::isIncludeable()
>
> Greg
>
--
Alan Knowles <alan@akbkhome.com>