[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: PHP application packaging policy/best practice?



Le Mer 12 Janvier 2005 10:50, Kees Leune a écrit :
> On Wed, 12 Jan 2005 10:16:43 +0100, Pierre Habouzit
>
> <pierre.habouzit@m4x.org> wrote:
> > Le Mer 12 Janvier 2005 01:31, Matthew Palmer a écrit :
> > > So you patch libfile2.php to require_once 'mylib/libfile1.php'
> > > instead of just 'libfile1.php'.
> >
> > oh and btw, the suggestion I did is better (IMHO) :
> >
> > replace require_once 'libfile.php'; with
> >
> > require dirname(__FILE__).'/'.'libfile1.php';
>
> So far, I have preferred to use files which include
> @ETCDIR@/package/package.cfg. In package.cfg, I define PHPDIR,
> LIBDIR, DATADIR using autotools. That way, after autoconfiguring, all
> PHP scripts have lines like

this indeed work for _apps_.
but I assume you don't want to have a config file per library !
and for those, some __FILE__ magic is really the best you can do.

It's used (e.g.) by smarty. and since the only file you should include 
while using smarty is /usr/share/php/smarty/libs/Smarty.class.php (I 
didn't really understood _why_ it's in libs/ ...), smarty has a 

define('SMARTY_DIR', dirname(__FILE__));

on the top of it.
and all the others files of the library use that magic.

the thing is, for smarty, you allways include Smarty.class.php.
but for more general libs, where there is more include files, and there 
is no preferred include for the programmer, you have to put 
dirname(__FILE__) everywhere.

-- 
·O·  Pierre Habouzit
··O
OOO                                                http://www.madism.org

Attachment: pgpoFp4sFF0NW.pgp
Description: PGP signature


Reply to: