phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] phpgwapi/inc class.object_factory.inc.php,1.1


From: fipsfuchs
Subject: [Phpgroupware-cvs] phpgwapi/inc class.object_factory.inc.php,1.1
Date: Fri, 8 Apr 2005 10:54:00 +0200

Update of phpgwapi/inc

Added Files:
     Branch: MAIN
            class.object_factory.inc.php 

Log Message:
parent factory class

====================================================
Index: class.object_factory.inc.php
<?php
        /**
        * Object Factory
        *
        * @author Dirk Schaller <address@hidden>
        * @copyright Copyright (C) 2003 Free Software Foundation, Inc. 
http://www.fsf.org/
        * @license http://www.fsf.org/licenses/gpl.html GNU General Public 
License
        * @package phpgwapi
        * @subpackage application
        * @version $Id: class.object_factory.inc.php,v 1.1 2005/04/08 08:54:59 
fipsfuchs Exp $
        */

        /**
        * Object factory
        *
        * @package phpgwapi
        * @subpackage application
        */
        class object_factory
        {
                function object_factory()
                {
                        die ('not allowed');
                }


                /*!
                 @function CreateObject
                 @abstract Load a class and include the class file if not done 
so already.
                 @author mdean
                 @author milosch
                 @author (thanks to jengo and ralf)
                 @discussion This function is used to create an instance of a 
class, and if the class file has not been included it will do so.
                 @syntax CreateObject('app.class', 'constructor_params');
                 @example $phpgw->acl = CreateObject('phpgwapi.acl');
                 @param $classname name of class
                 @param $p1-$p16 class parameters (all optional)
                */
                function CreateObject($class,
                        $p1='_UNDEF_',$p2='_UNDEF_',$p3='_UNDEF_',$p4='_UNDEF_',
                        $p5='_UNDEF_',$p6='_UNDEF_',$p7='_UNDEF_',$p8='_UNDEF_',
                        
$p9='_UNDEF_',$p10='_UNDEF_',$p11='_UNDEF_',$p12='_UNDEF_',
                        
$p13='_UNDEF_',$p14='_UNDEF_',$p15='_UNDEF_',$p16='_UNDEF_')
                {
                        global $phpgw_info, $phpgw;

                        if (is_object(@$GLOBALS['phpgw']->log) && $class != 
'phpgwapi.error' && $class != 'phpgwapi.errorlog')
                        {
                                
//$GLOBALS['phpgw']->log->write(array('text'=>'D-Debug, dbg: %1','p1'=>'This 
class was run: '.$class,'file'=>__FILE__,'line'=>__LINE__));
                        }

                        list($appname,$classname) = explode('.', $class);
                        $is_included = include_class($appname, $classname);
                        if($is_included)
                        {
                                if ($p1 == '_UNDEF_' && $p1 != 1)
                                {
                                        $obj = new $classname;
                                }
                                else
                                {
                                        $input = 
array($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9,$p10,$p11,$p12,$p13,$p14,$p15,$p16);
                                        $i = 1;
                                        $code = '$obj = new ' . $classname . 
'(';
                                        while (list($x,$test) = each($input))
                                        {
                                                if (($test == '_UNDEF_' && 
$test != 1 ) || $i == 17)
                                                {
                                                        break;
                                                }
                                                else
                                                {
                                                        $code .= '$p' . $i . 
',';
                                                }
                                                $i++;
                                        }
                                        $code = substr($code,0,-1) . ');';
                                        eval($code);
                                }
                                /* error_reporting(E_ERROR | E_WARNING | 
E_PARSE); */
                                return $obj;
                        }
                }

                /*!
                 @function getClassInfo
                 @abstract Convert the class string into an array.
                 @author Dirk Schaller <address@hidden>
                 @discussion This function is used to convert the first 
parameter of CreateObject method ('app.class') into an array (array('app'=>app, 
'class'=>class)).
                 @syntax getClassInfo('app.class');
                 @example $ci = CreateObject('phpgwapi.acl');
                 @param $class 'app.class' string
                 @return array with key 'app' and key 'class'.
                */
                function getClassInfo($class)
                {
                        list($app,$class) = explode('.', $class, 2);
                        return array('app' => $app, 'class' => $class);
                }

        }


?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]