You are here: Re: Confused about scope of globals in included files « PHP Programming Language « IT news, forums, messages
Re: Confused about scope of globals in included files

Posted by Jerry Stuckle on 02/23/06 23:09

Wescotte wrote:
> Here is what I'm actually trying to do. I have several different types
> of files the user is loading into the application.
> I have several freight vendors and each has a slightly differnet file
> type. So I detect the file type and then based on that load a specific
> file that sets various constants for this particular vendor and has a
> common set of functions.
>
> So something like (sudocode)
>
> $type = Detect_File_Type($file);
>
> switch ($type) {
> case: "FEDEX"
> include "Fedex.php";
> Create_Batch($Batch_Number, $file);
> break;
> case: "DHL"
> include "DHL.php";
> Create_Batch($Batch_Number, $file);
> break;
> default:
> echo "unable to process file";
> return false;
> break;
> }
>
> Fedex.php
>
> include "general_batch_functions.php";
>
> Define constants
>
> Function Create_Batch()
> {
> }
>
> other specific functions for FEDEX file processing
>
>
> DHL.php
>
> include "general_batch_functions.php";
>
> Define constants
>
> Function Create_Batch()
> {
> }
>
> other specific functions for DHL file processing
>
> How would you go about doing such a task?
>
> The constants defined in each file aren't needed anymore after the
> batch is created.
>
> The only time they are another switch takes place and it's included
> again (done for the payment process because most of the constants are
> like a remittance address and the bank account numbers to make ACH
> payments to and such.) I supose I could simply store these constants in
> a database table but because I need specific functions to read the data
> it seemed like a better caseto group it all into one file. Any
> suggestions on possibly a better design?
>

Well, if you're only going to use them in the Create_Batch() function,
you could put them right in that function.

Or, if you have more than one function using the values and your
Create_Batch function differs between the various types, create classes
for each of the various types, i.e.

class fedex
var $company_id = 'FEDEX';
Create_batch() {
// use as $this->company_id
}
Another_Func () {
...
}
}

class dhl
var $company_id = 'DHL';
Create_batch() {
// use as $this->company_id
}
Another_Func () {
...
}
}

class xyz
var $company_id = 'XYZ';
Create_batch() {
// use as $this->company_id
}
Another_Func () {
...
}
}

Then include all of them in your first file and instantiate an object of
the appropriate type, i.e.

switch ($type) {
case: "FEDEX"
$shipper = new fedex();
break;
case: "DHL"
$shipper = new dhl();
break;
default:
shipper = null;
break;
}

if ($shipper == null)
echo "unable to process file";
else
$shipper->Create_Batch($Batch_Number, $file);


Much cleaner.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация