best way to set up an include path for a multi-level project?

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

 



  i have a project (let's call it "proj") which lives in the "proj"
directory and which contains several subdirs, some of which might
contain their own subdirs and so on.  some of those subdirs might
contain utility classes that i want to include or require elsewhere,
so i want to be able to just:

  require 'util.php';

and have the PHP include path "do the right thing."  right now, it's
ugly, as in, having PHP files that do:

  require '../../proj/util.php';

meaning every single file that wants to include another proj-related
file has to know its relative position in the proj hierarchy.   barf.

  based on my experience with shell and makefile-based projects, my
preference would be that anyone who checks out a copy of the project
can check it out anywhere they want, then they need to set the single
shell environment variable, say PROJ_DIR, to the top-level directory
location, say:

  $ export PROJ_DIR=/home/rpjday/php/things/proj

  i would then make sure that env vars are available to PHP scripts
via /etc/php.ini:

  variables_order = "EGPCS"
                     ^

and all PHP scripts would start off with something like:

set_include_path(get_include_path() . PATH_SEPARATOR . getenv('PROJ_DIR'));

at that point (and correct me if i'm wrong), all subsequent includes
or requires would simply need to reflect the location of the file
relative to its PROJ_DIR location (barring any weird conflicts with
system files having the same name, of course).

  does that sound about right?  is there a standard way to do this?
that is, to have a sizable PHP hierarchy and allow any files within
that hierarchy to include others conveniently without having to
hardcode directory names.

  requiring users to simply set a single env var has always worked for
me.  is that what others do to solve this?  thanks.

rday
--

========================================================================
Robert P. J. Day                               Waterloo, Ontario, CANADA

            Linux Consulting, Training and Kernel Pedantry.

Web page:                                          http://crashcourse.ca
Twitter:                                       http://twitter.com/rpjday
========================================================================

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux