Changeset 2278 for sandbox/workflow


Ignore:
Timestamp:
03/17/10 11:21:02 (14 years ago)
Author:
pedroerp
Message:

Ticket #609 - Corrigindo a passagem de referências de objetos na factory.

Location:
sandbox/workflow/branches/609/lib/factory
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sandbox/workflow/branches/609/lib/factory/BaseFactory.php

    r2233 r2278  
    1414 * This class implements all the common behaviour of 
    1515 * it's specialized classes (ProcessFactory and WorkflowFactory). 
     16 * The only class allowed to use it's methods should be the 
     17 * Factory frontend. 
    1618 * 
    1719 * @package Factory 
     
    3234         * atribute. 
    3335         * 
    34          * @todo Maybe here we should receive more parameters... 
    3536         * @access protected 
    3637         * @return void 
     
    5152         * into our private object cache. If there is no 
    5253         * object of the given type into the cache, 'newInstance' 
    53          * will be called. 
     54         * will be called. This method must deal with 
     55         * pointers (&) to avoid object duplications. 
    5456         * 
    5557         * @access public 
    5658         * @return object 
    5759         */ 
    58         public function &getInstance(){ 
     60        public function &getInstance($className, $classArgs){ 
    5961 
    60                 /* at least the class name */ 
    61                 if (func_num_args() <= 0) 
     62                /* have we a class name? */ 
     63                if (empty($className)) 
    6264                        return null; 
    6365 
    64                 $args = func_get_args(); 
    65  
    6666                /* recovering class data */ 
    67                 if ($entry = $this->_getEntry($args[0])) { 
     67                if ($entry = &$this->_getEntry($className)) { 
    6868 
    6969                        if (is_null($entry['instance'])) { 
    7070 
    71                                 /* must instantiate it */ 
    72                 if (($obj = call_user_func_array(array($this, "newInstance"), $args)) == null) 
    73                                         throw new Exception("Unable to instantiate '".$args[0]."'"); 
     71                                /* we must instantiate it */ 
     72                if (($obj = &$this->newInstance($className, $classArgs)) == null) 
     73                                        throw new Exception("Unable to instantiate '".$className."'"); 
    7474 
    7575                                /* saving the object reference */ 
    76                                 $this->_setEntryInstance($args[0], $obj); 
     76                                $this->_setEntryInstance($className, $obj); 
    7777                                return $obj; 
    7878                        } 
     
    8282                /* class not allowed */ 
    8383                else 
    84                         throw new Exception("You are not allowed to instantiate class '".$args[0]."'."); 
     84                        throw new Exception("You are not allowed to instantiate class '".$className."'."); 
    8585        } 
    8686 
    8787        /** 
    88          * Instantiate classes. 
     88         * Instantiating classes. 
    8989         * 
    90          * @todo I think that we don't need to use the reflection 
     90         * @todo Maybe we don't have to use the reflection 
    9191         *               class here. Future work... 
    9292         * @access public 
    9393         * @return object 
    9494         */ 
    95         public function &newInstance(){ 
     95        public function &newInstance($className, $classArgs){ 
    9696 
    97                 /* at least the class name */ 
    98                 if (func_num_args() <= 0) 
     97                /* have we a class name? */ 
     98                if (empty($className)) 
    9999                        return null; 
    100100 
    101                 $args = func_get_args(); 
    102  
    103                 $className = array_shift($args); 
     101                /* just to be sure. If this method fails, it will throw an exception anyway... */ 
    104102                if(!$this->_import($className)) 
    105103                        return null; 
    106104 
    107                 /* I dont know.. maybe we could do better here.. */ 
     105                /** 
     106                 * Here we use this big white elephant (by big white elephant I mean php 
     107                 * reflection interface) just because we have to pass an unknown number 
     108                 * of parameters to the constructor of the class. 
     109                 * If you know a better way to do this, please update this code =D 
     110                 */ 
    108111                $reflectionObj = new ReflectionClass($className); 
    109112 
    110                 if (count($args) == 0) 
     113                if (count($classArgs) == 0) 
    111114                        return $reflectionObj->newInstance(); 
    112                 return $reflectionObj->newInstanceArgs($args); 
     115                return $reflectionObj->newInstanceArgs($classArgs); 
    113116        } 
    114117 
     
    121124         * @return array 
    122125         */ 
    123         private function _getEntry($className){ 
     126        private function &_getEntry($className){ 
    124127                return $this->_fileInfo[$className]; 
    125128        } 
     
    133136         * @return boolean 
    134137         */ 
    135         private function _setEntryInstance($className, $obj){ 
     138        private function _setEntryInstance($className, &$obj){ 
    136139 
    137140                if (is_array($this->_fileInfo[$className])) { 
    138                         $this->_fileInfo[$className]['instance'] = $obj; 
     141                        $this->_fileInfo[$className]['instance'] = &$obj; 
    139142                        return true; 
    140143                } 
  • sandbox/workflow/branches/609/lib/factory/Factory.php

    r2249 r2278  
    103103                                self::$_unsecuredFactory = new WorkflowFactory(); 
    104104 
    105                         return call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args); 
     105                        $className = array_shift($args); 
     106                        return self::$_unsecuredFactory->$methodName($className, $args); 
    106107                } 
    107108                /* oops. we are in the process space (restricted). */ 
     
    112113                                self::$_securedFactory = new ProcessFactory(); 
    113114 
     115                        $className = array_shift($args); 
     116 
    114117                        /** 
    115118                         * If the class is not allowed, we must check who is trying 
     
    118121                         */ 
    119122                        try { 
    120                                 $obj = call_user_func_array(array(self::$_securedFactory, $methodName), $args); 
     123                                $obj = &self::$_securedFactory->$methodName($className, $args); 
    121124                        } 
    122125 
     
    133136                                 */ 
    134137                                if (Security::isSafeDir(2)) 
    135                                         $obj = call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args); 
     138                                        $obj = &self::$_unsecuredFactory->$methodName($className, $args); 
    136139 
    137                                 /* nasty one. take this... */ 
     140                                /* naaasty one. take this! */ 
    138141                                else 
    139142                                        throw($e); 
  • sandbox/workflow/branches/609/lib/factory/WorkflowFactory.php

    r2268 r2278  
    8383                $this->registerFileInfo('common', 'class.common.inc.php', '', EGW_INC_ROOT); 
    8484                $this->registerFileInfo('session', 'class.session.inc.php', '', EGW_INC_ROOT); 
    85                 $this->registerFileInfo('nextmachs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT); 
     85                $this->registerFileInfo('nextmatchs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT); 
    8686                $this->registerFileInfo('categories', 'class.categories.inc.php', '', EGW_INC_ROOT); 
    8787                $this->registerFileInfo('listbox', 'class.listbox.inc.php', '', EGW_INC_ROOT); 
Note: See TracChangeset for help on using the changeset viewer.