This guy is proof that PHP programmers are a functional clever bunch and PHP
does not box us in with too many limits.

> -----Original Message-----
> From: Matthew M. Boulter [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 24, 2001 9:16 AM
> To: Steve Werby; Toby Miller; indrek siitan
> Cc: PHP General Mailing List
> Subject: RE: [PHP] Site Structure
>
>
>
> G'day all, I thought I'd mention how I developed my last project and got
> around some of these problems, bear with me it can be quite complicated.
> ==================================================================
> ==========
> ===
> In the development we had to develop on many different servers, mine at
> home, my partners at his place then two different ones at work. Here's the
> site structure (Red Hat 7):
>
> /var/www/api/         <-- all my code outside of the web tree
>                config/        <-- where all the API's config
> files go (*.cfg)
>                0.1/           <-- version 0.1 of my API
>                    modules/   <-- all of my 0.1 version modules (*.lib)
>                0.2/           <-- version 0.2 of my API
>                    modules/   <-- all of my 0.2 version modules (*.lib)
> /var/www/html/v1/             <-- version 1 of the site (/html is
> Red Hat 7's name for
> /htdocs)
> /var/www/html/v2/             <-- version 2   "
> ---------------------------------------
>
> [in PHP.INI]          include_path =
> .:/var/www/api/config:/var/www/api/modules
>
> In each /HTML/?? directory there is a file -> api_connect.cfg
>
> [in api_connect.cfg]  include 'api01.cfg'
>
> This basically says use version 0.1 of the API for this website.
> This way as
> I experiment and change my source code I can make an entire new version
> branch of my source code (i.e., make /var/www/api/0.3/modules) and change
> the 'api_connect.cfg' file to suit.
>
> * How to access in a PHP and/or HTML-hybrid file?
>   Easy! <?php include 'api_connect.cfg'; ?> at the top of your document.
>
> --For-example--------------------------
> My index file has a login form, therefore my index.html has the code
> <?php include 'api_connect.cfg';
>       // do other processing here, since that code sets up my API
> connection I
> can use all my objects
>       $dbase = new ApiDbaseConn(); //etc, etc, etc....
> ?>
> <HTML>
> <!-- blah, blah, blah -->
> </HTML>
>
> The include process would look like:                  --I--> Includes
> /var/www/html/v1/index.html   --I-->
> /var/www/html/v1/api_connect.cfg   --I-->   /var/www/api/config/api01.cfg
>
>                       ^^^^^^^^^
> ** NOTE: This link takes advantage of the "/var/www/api/config"
> entry in the
> PHP.INI include_path directive **
>
> ==Now=What??===What=does=API??.CFG=do?============================
> ==========
> ===
> This is where the fun starts ;) Below is a *censored ;)* API04.CFG file:
>
>
> [API04.CFG]
> ------------------------------------------------------------------
> ----------
> ---
> //--begin-file-guard--
> $included_flag='__API_CONFIG_'.basename(__FILE__);
> if(defined($included_flag)) {return true;} define($included_flag,TRUE);
> //--end-file-guard---
>
> /*****************************************************************
> **********
> ***/
> /*==========================FRAMEWORK===CONSTANTS=================
> ==========
> ==*/
> /*****************************************************************
> **********
> ***/
> define('API_VERSION', '0.4');
>
> //==[SITE-DETAILS]================================================
> ==========
> ====
> define('API_DEBUG_ON', 0);                                    //
> 0 - off; 1 - on
> define('API_ERROR_ON', 0);                                    //
> 0 - off; 1 - on
>
> $czServerName = 'vandyk';
>
> switch ($czServerName)
> {
>       case 'vandyk':          define('SLASH', '/');
>                               define('API_PATH', '/var/www/api'.SLASH);
>
> define('API_DBASE_PRIMARY','***CENSORED***');
>
> define('API_DBASE_SECONDARY','***CENSORED***');
>
> define('API_DBASE_DBASENAME','***CENSORED***');
>
> define('API_DBASE_PASSWORD','***CENSORED***');
>
> define('API_DBASE_DBASENAME','***CENSORED***');
>                                       $bIsUnix = TRUE;
>                                       break;
>       //---------------------------------------
>
>       case 'enki':            define('SLASH', '\\');
>
>                                       define('API_PATH',
> 'C:\apache\api'.SLASH);
>
> define('API_DBASE_PRIMARY','***CENSORED***');
>
> define('API_DBASE_SECONDARY','***CENSORED***');
>
> define('API_DBASE_DBASENAME','***CENSORED***');
>
> define('API_DBASE_PASSWORD','***CENSORED***');
>
> define('API_DBASE_DBASENAME','***CENSORED***');
>                                       $bIsUnix = FALSE;
>                                       break;
>       //---------------------------------------
>
>       case 'fontaine':                // you get the idea
>       //---------------------------------------
>
>       case 'morillo':
> // you get the idea
>       //---------------------------------------
>       case 'oakenfold':               // you get the idea
> }
>
>
> //==[LOCATIONS]===================================================
> ==========
> ====
> define('API_CONFIG_PATH',                     API_PATH.'config'.SLASH);
> define('API_LOGS_PATH',                       API_PATH.'logs'.SLASH);
> define('API_LIB_PATH',
> API_PATH.API_VERSION.SLASH.'modules'.SLASH);
>
> //==[EXCEPTION-HANDLING]==========================================
> ==========
> ====
> include(API_LIB_PATH.'api_debug.lib');        // debugging
>
>
> //==[LOGGING]=====================================================
> ==========
> ====
> include(API_LIB_PATH.'api_log_html.lib');
>
> if ($bIsUnix) {
>       if ( !isset($g_LOG) ) {
>         $g_LOG = new ApiLogHtml('/tmp/api_debug.html','a+');
>     }
> } else {
>       if ( !isset($g_LOG) ) {
>         $g_LOG = new ApiLogHtml('c:/temp/api_debug.html',"a+");
>     }
> }
>
> //==[COMPONENT-OBJECT-GROUP]======================================
> ==========
> ====
> include(API_LIB_PATH.'api_dbase.lib');
> // I'll spare you the list of included modules
>
> ==================================================================
> ==========
> ===
> The key here is to note the following:
>
> * At the very top of the config file I state what the Version of the API
> this config is for. Therefore as you'll see in the definition of the
> API_LIB_PATH ([LOCATIONS]) I concatenate the version number to
> the api path.
>
> * Since we had so many servers this was solved with a switch statement and
> settings the variable $czServerName
>
> * In each server's section goes server-specific settings (dah, really?!)
> Therefore to illustrate the portability of this I've left in the
> details for
> two servers, vandyk (awesome DJ) and enki (Sumerian God of the Earth).
> vandyk is Red Hat 7, enki is Win2K
>       I set the direction of the /\ Slash (I later found out that
> doesn't matter,
> you clever PHP developers you)
>       I then set the all important API_PATH that establishes the
> initial base
> root of the API files.
>       Then everything else builds on the API_PATH constant by
> .concatenating.it.with.other.things
> The rest is self-explanatory.
>
> ==================================================================
> ==========
> ===
>
> This took alot (*cry tears of lost sleep - ahhhh stimulants ;)*) of
> refining, but I like it and it worked well once it was inplace.
> Then all was
> good.
>
> Hope it provides someone out there some inspiration.
>
> Happy Coding Guys!!
>
> Matty.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to