Re: Net_FTP design issues
| From: | Bjori | Date: | Thu, 14 Oct 2004 15:52:50 +0000 |
| Subject: | Re: Net_FTP design issues | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-33848@lists.php.net to get a copy of this message | ||
> Tobias Schlitt wrote:
> > Hi all!
> >
> > I recently got a new member for maintainance/development of Net_FTP. A
> > friend of Helgi (CC'ed) started implementing the FTP functions provided
> > by PHP using sockets and we will develop the new backend together.
I would be that guy.
> > Now we're hanging at the decision of implementing the new backend in an
> > OO or procedural manner. On the one hand I would preffer OO style, since
> > all in PEAR is OO. On the other hand, if native FTP is not available one
> > can simple include the code (if it's procedural) and will have the
> > functions available with the same API. Forethat I'd preffer to have it
> > procedural.
>
> On the other hand, if native ftp is available, one can't include the
> code at all. This will make the user's job much more complex. Instead of
>
> <?php
> require_once 'Net/Ftp.php';
> ?>
>
> we will then have to go
>
> <?php
> if (!function_exists('ftp_whatever')) {
> include_once 'Net/Ftp.php';
> }
> ?>
Net/Ftp.php would need to contain something like this;
<?php
if (!extension_loaded('ftp')) {
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN')) {
@dl('php_ftp.dll');
} else {
@dl('ftp.so');
}
}
if (!extension_loaded('ftp')) {
require_once 'Socket.php';
}
?>
Earasing any user problems to check for extension.
> Also, what if you decide you want to add new functionality later? You
> can't. Procedural code is completely inappropriate for a package like
> Net_FTP.
I belive using "the other hand" way ( procedural ) is more appropriate cause users can now
use this class even thou they don't have access to PHPs FTP extension.
Going procedural way also allows users to include Net_FTP, even thou they don't want to use
that class, and use the ftp functions just as they were loaded into PHP as extension.
>
> > What do you think?
> >
> > The procedural way would have another difficulty to ship around: Storage
> > of the config stuff and Co., which would have been stored in the object
> > in an OO way. I would suggest to store all of that in a global array
> > (e.g. $_NET_FTP), which should not affect most of the scripts it would
> > be used in.
>
> This also smacks of greater-than-needed complexity in the
> implementation. Better is to expect that speed-hungry users will use
> the native ftp functions no matter what, and that everyone else will
> welcome the abstraction that allows a redistributable application to run
> without the ftp extension dependency.
Speed-hungry users don't always get what they want and "expecting users to have
something" has never been a good friend to programmers.
>
> A good compromise solution is to provide a file that has wrapper
> functions to the procedural functions. This will satisfy the users who
> want to only use the procedural stuff.
>
> user file:
> <?php
> require_once 'Net/Ftp/Proecedural.php';
> ?>
>
> Procedural.php:
> <?php
> if (!function_exists('ftp_whatever')) {
> include_once 'Net/FTP.php';
> $GLOBALS['_NET_FTP_INSTANCE'] = &new Net_FTP;
> function ftp_whatever(blahblah)
> {
> $GLOBALS['_NET_FTP_INSTANCE']->doWhatever(blahblah);
> }
> }
> ?>
Interesting solution. Worth looking into.
- Hannes