Posted by David Haynes on 04/17/06 22:02
Wescotte wrote:
> That is exactly what I did in my current version but I wanted a cleaner
> method.
>
> In the case you described above I would have to have to modify multiple
> sectiosn of code to add a new class type instead of simply adding a new
> row to a table that contains the code for a new type. I guess the only
> method I can see would be again going by functions but having a prefix
> to each say
>
> Fedex.php
> Fedex_Detected_EDI_Type()
> Fedex_Parse_EDI_File();
> Fedex_Create_Remittance()
>
> DHL.php
> DHL_Detected_EDI_Type()
> DHL_Parse_EDI_File()
> DHL_Create_Remittance()
>
> while (odbc_fetch_row($result) || $done) {
> $function = odbc_result($result, "name") . "_Detected_EDI_Type";
> if ($function()) {
> // Detected edi file format
> // do something....
> $done = true;
> }
> }
>
> With this method I can create a table that contains the source code
> filename
> and the leading characters into the function name so that each name is
> unique
>
> Now to add a new type I simply add a new record ot the table rather
> than adding a new case "formatX": instance in the detcting/pasing and
> creating remittance sections
> which allows me to isolate the code from the user yet allow them to
> create code for new file types
>
> While this method will work I was looking for a way to keep the
> function names identically instead of having a leading unique string +
> function name (Fedex or DHL) _Detected_EDI_Type
>
> Basically I was looking for the ability to include "code.php" and then
> somehow uninclude it after I used it.
>
I don't see why you would need to do apply special naming when the
object will encapsulate that for you.
If you have a column in the DB table called something like 'class_name',
then I think you could do something like:
while( odbc_fetch_row($result) || $done ) {
$class_name = odbc_result($result, 'class_name');
if( $obj = new $class_name() ) {
// call whatever method you need
$obj->Detected_EDI_Type();
$obj->Parse_EDI_File();
$obj->Create_Remittance();
}
}
-david-
Navigation:
[Reply to this message]
|