Ignore:
Timestamp:
03/15/10 14:41:49 (14 years ago)
Author:
pedroerp
Message:

Ticket #609 - Adaptando os processos do workflow para utilizar o nova factory.

File:
1 edited

Legend:

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

    r2233 r2249  
    5858 
    5959        /** 
    60          * Just forward this call to the correct class. 
     60         * Just forward this call. 
    6161         * 
    6262         * @access public 
    63          * @retun object 
     63         * @return object 
    6464         * @static 
    6565         */ 
    6666        public static function &getInstance() { 
    6767 
    68                 /* oops. we are in the process space. */ 
    69                 if (Security::isEnabled()) { 
    70  
    71                         /* must instatiate it */ 
    72                         if (is_null(self::$_securedFactory)) 
    73                                 self::$_securedFactory = new ProcessFactory(); 
    74  
    75                         $args = func_get_args(); 
    76                         return call_user_func_array(array(self::$_securedFactory, "getInstance"), $args); 
    77  
    78                 } 
    79                 /* regular module space */ 
    80                 else { 
    81  
    82                         /* must instatiate it */ 
    83                         if (is_null(self::$_unsecuredFactory)) 
    84                                 self::$_unsecuredFactory = new WorkflowFactory(); 
    85  
    86                         $args = func_get_args(); 
    87                         return call_user_func_array(array(self::$_unsecuredFactory, "getInstance"), $args); 
    88                 } 
     68                $args = func_get_args(); 
     69                return self::_callMethod(__FUNCTION__, $args); 
    8970        } 
    9071 
    9172 
    9273        /** 
    93          * Just forward this call to the correct class. 
     74         * Just forward this call. 
    9475         * 
    9576         * @access public 
    96          * @retun object 
     77         * @return object 
    9778         * @static 
    9879         */ 
    9980        public static function &newInstance() { 
    10081 
    101                 /* oops. we are in the process space. */ 
    102                 if (Security::isEnabled()) { 
     82                $args = func_get_args(); 
     83                return self::_callMethod(__FUNCTION__, $args); 
     84        } 
    10385 
    104                         /* must instatiate it */ 
     86 
     87        /** 
     88         * Selecting the proper factory to call. This function 
     89         * should never be called with a random $methodName. Allowed 
     90         * values are 'getInstance' and 'newInstance'. 
     91         * 
     92         * @access private 
     93         * @return object 
     94         * @static 
     95         */ 
     96        private static function &_callMethod($methodName, $args) { 
     97 
     98                /* security off (module space) */ 
     99                if (!Security::isEnabled()) { 
     100 
     101                        /* it must be instatiated */ 
     102                        if (is_null(self::$_unsecuredFactory)) 
     103                                self::$_unsecuredFactory = new WorkflowFactory(); 
     104 
     105                        return call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args); 
     106                } 
     107                /* oops. we are in the process space (restricted). */ 
     108                else { 
     109 
     110                        /* it must be instatiated */ 
    105111                        if (is_null(self::$_securedFactory)) 
    106112                                self::$_securedFactory = new ProcessFactory(); 
    107113 
    108                         $args = func_get_args(); 
    109                         return call_user_func_array(array(self::$_securedFactory, "newInstance"), $args); 
     114                        /** 
     115                         * If the class is not allowed, we must check who is trying 
     116                         * to instantiate it. If it's a module guy, let's allow him. 
     117                         * Throw up the exception otherwise. 
     118                         */ 
     119                        try { 
     120                                $obj = call_user_func_array(array(self::$_securedFactory, $methodName), $args); 
     121                        } 
    110122 
    111                 } 
    112                 /* regular module space */ 
    113                 else { 
     123                        /** 
     124                         * We are erroneously catching any exceptions. We should catch only the 'class not allowed' 
     125                         * types of exceptions. To do so, a custom exception class must be defined. 
     126                         */ 
     127                        catch(Exception $e) { 
    114128 
    115                         /* must instatiate it */ 
    116                         if (is_null(self::$_unsecuredFactory)) 
    117                                 self::$_unsecuredFactory = new WorkflowFactory(); 
     129                                /** 
     130                                 * Here we are using depth 2 in isSafeDir method, because we are on a private 
     131                                 * method. Thus, we need to know if the "caller's caller's" function is on a 
     132                                 * safe dir, instead of the direct caller's method. 
     133                                 */ 
     134                                if (Security::isSafeDir(2)) 
     135                                        $obj = call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args); 
    118136 
    119                         $args = func_get_args(); 
    120                         return call_user_func_array(array(self::$_unsecuredFactory, "newInstance"), $args); 
     137                                /* nasty one. take this... */ 
     138                                else 
     139                                        throw($e); 
     140                        } 
     141 
     142                        // finally 
     143                        return $obj; 
    121144                } 
    122145        } 
Note: See TracChangeset for help on using the changeset viewer.