root

Changeset 271

Show
Ignore:
Timestamp:
10/06/08 22:57:48 (2 years ago)
Author:
wbond
Message:

Added fCore::callback(), change fCore::call() to accept two different parameter styles and changed all of the remaining static method callbacks to use fCore::callback()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fCore.php

    r270 r271 Hide Line Numbers
    185185     
    186186    /** 
    187      * Performs a call_user_func_array, while translating PHP 5.2 static callback syntax for PHP 5.1 and 5.0 
    188      *  
    189      * To pass parameters by reference they must be assigned to the parameters 
     187     * Performs a call_user_func, while translating PHP 5.2 static callback syntax for PHP 5.1 and 5.0 
     188     *  
     189     * Parameters can be passed either as a single array of parameters or as 
     190     * multiple parameters. 
     191     *  
     192     * <code> 
     193     * // Passing multiple parameters in a normal fashion 
     194     * fCore::call('Class::method', TRUE, 0, 'test'); 
     195     *  
     196     * // Passing multiple parameters in a parameters array 
     197     * fCore::call('Class::method', array(TRUE, 0, 'test')); 
     198     * </code> 
     199     *  
     200     * To pass parameters by reference they must be assigned to an 
    190201     * array by reference and the function/method being called must accept those 
    191202     * parameters by reference. If either condition is not met, the parameter 
    192203     * will be passed by value. 
    193204     *  
     205     * <code> 
     206     * // Passing parameters by reference 
     207     * fCore::call('Class::method', array(&$var1, &$var2)); 
     208     * </code> 
     209     *  
    194210     * @param  callback $callback    The function or method to call 
    195211     * @param  array    $parameters  The parameters to pass to the function/method 
     
    203219        } 
    204220         
     221        $parameters = array_shift(func_get_args()); 
     222        if (sizeof($parameters) == 1 && is_array($parameters[0])) { 
     223            $parameters = $parameters[0];    
     224        } 
     225         
    205226        return call_user_func_array($callback, $parameters); 
     227    } 
     228     
     229     
     230    /** 
     231     * Translates a Class::method style static method callback to array style for compatibility with PHP 5.0 and 5.1 and built-in PHP functions 
     232     *  
     233     * @param  callback $callback  The callback to translate 
     234     * @return array  The translated callback 
     235     */ 
     236    static public function callback($callback) 
     237    { 
     238        if (!is_string($callback) || strpos($callback, '::') === FALSE) { 
     239            fCore::toss( 
     240                'fProgrammerException', 
     241                fGrammar::compose( 
     242                    'Only string static method callbacks can be translated with this method' 
     243                ) 
     244            );   
     245        } 
     246         
     247        if (self::getPHPVersion() < '5.2.0') { 
     248            return explode('::', $callback);     
     249        } 
     250         
     251        return $callback; 
    206252    } 
    207253     
     
    367413        self::$error_destination = $destination; 
    368414        self::$handles_errors    = TRUE; 
    369         set_error_handler(array('fCore', 'handleError')); 
     415        set_error_handler(self::callback(self::handleError)); 
    370416    } 
    371417     
     
    391437        settype($parameters, 'array'); 
    392438        self::$exception_handler_parameters = $parameters; 
    393         set_exception_handler(array('fCore', 'handleException')); 
     439        set_exception_handler(self::callback(self::handleException)); 
    394440    } 
    395441     
     
    646692        static $registered_function = FALSE; 
    647693        if (!$registered_function) { 
    648             register_shutdown_function(array('fCore', 'sendMessagesOnShutdown')); 
     694            register_shutdown_function(self::callback(self::sendMessagesOnShutdown)); 
    649695            $registered_function = TRUE; 
    650696        } 
  • fGrammar.php

    r270 r271 Hide Line Numbers
    221221        if (self::$compose_callbacks) { 
    222222            foreach (self::$compose_callbacks['pre'] as $callback) { 
    223                 $message = fCore::call($callback, array($message)); 
     223                $message = fCore::call($callback, $message); 
    224224            } 
    225225        } 
     
    230230        if (self::$compose_callbacks) { 
    231231            foreach (self::$compose_callbacks['post'] as $callback) { 
    232                 $message = fCore::call($callback, array($message)); 
     232                $message = fCore::call($callback, $message); 
    233233            } 
    234234        } 
     
    344344         
    345345        if (self::$join_array_callback) { 
    346             return fCore::call(self::$join_array_callback, array($strings, $type)); 
     346            return fCore::call(self::$join_array_callback, $strings, $type); 
    347347        } 
    348348         
  • fMoney.php

    r270 r271 Hide Line Numbers
    242242        // Unformat any money value 
    243243        if (self::$unformat_callback !== NULL) { 
    244             $amount = fCore::call(self::$unformat_callback, array($amount, $this->currency)); 
     244            $amount = fCore::call(self::$unformat_callback, $amount, $this->currency); 
    245245        } else { 
    246246            $amount = str_replace( 
     
    426426    { 
    427427        if (self::$format_callback !== NULL) { 
    428             return fCore::call(self::$format_callback, array($this->value, $this->currency)); 
     428            return fCore::call(self::$format_callback, $this->value, $this->currency); 
    429429        } 
    430430         
  • fNumber.php

    r270 r271 Hide Line Numbers
    258258         
    259259        if (self::$unformat_callback) { 
    260             $number = fCore::call(self::$unformat_callback, array($number)); 
     260            $number = fCore::call(self::$unformat_callback, $number); 
    261261        } else { 
    262262            $number = str_replace(',', '', $number);     
     
    11021102    { 
    11031103        if (self::$format_callback !== NULL) { 
    1104             return fCore::call(self::$format_callback, array($this->value)); 
     1104            return fCore::call(self::$format_callback, $this->value); 
    11051105        } 
    11061106         
  • fORM.php

    r270 r271 Hide Line Numbers
    462462         
    463463        if (!empty(self::$objectify_callbacks[$class][$column])) { 
    464             return fCore::call(self::$objectify_callbacks[$class][$column], array($class, $column, $value)); 
     464            return fCore::call(self::$objectify_callbacks[$class][$column], $class, $column, $value); 
    465465        } 
    466466         
     
    763763         
    764764        if (!empty(self::$scalarize_callbacks[$class][$column])) { 
    765             return fCore::call(self::$scalarize_callbacks[$class][$column], array($class, $column, $value)); 
     765            return fCore::call(self::$scalarize_callbacks[$class][$column], $class, $column, $value); 
    766766        } 
    767767         
  • fORMFile.php

    r270 r271 Hide Line Numbers
    159159         
    160160        self::$fupload_method_calls[$class][$column][] = array( 
    161             'callback'   => array('fUpload', $method)
     161            'callback'   => 'fUpload::' . $method
    162162            'parameters' => $parameters 
    163163        ); 
  • fRecordSet.php

    r270 r271 Hide Line Numbers
    521521                $value = $record->$method(); 
    522522            } else { 
    523                 $value = fCore::call($callback, array($record)); 
     523                $value = fCore::call($callback, $record); 
    524524            } 
    525525            if ($value) { 
     
    953953         
    954954        foreach($values as $value) { 
    955             $result = fCore::call($callback, array($result, $value)); 
     955            $result = fCore::call($callback, $result, $value); 
    956956        } 
    957957         
  • fSQLTranslation.php

    r265 r271 Hide Line Numbers
    387387        $functions[] = array('ceiling',  'ceil',                                         1); 
    388388        $functions[] = array('cos',      'cos',                                          1); 
    389         $functions[] = array('cot',      array('fSQLTranslation', 'sqliteCotangent'),    1); 
     389        $functions[] = array('cot',      fCore::callback(self::sqliteCotangent),         1); 
    390390        $functions[] = array('degrees',  'rad2deg',                                      1); 
    391391        $functions[] = array('exp',      'exp',                                          1); 
    392392        $functions[] = array('floor',    'floor',                                        1); 
    393393        $functions[] = array('ln',       'log',                                          1); 
    394         $functions[] = array('log',      array('fSQLTranslation', 'sqliteLogBaseFirst'), 2); 
     394        $functions[] = array('log',      fCore::callback(self::sqliteLogBaseFirst),      2); 
    395395        $functions[] = array('pi',       'pi',                                           1); 
    396396        $functions[] = array('power',    'pow',                                          1); 
    397397        $functions[] = array('radians',  'deg2rad',                                      1); 
    398         $functions[] = array('sign',     array('fSQLTranslation', 'sqliteSign'),         1); 
     398        $functions[] = array('sign',     fCore::callback(self::sqliteSign),              1); 
    399399        $functions[] = array('sqrt',     'sqrt',                                         1); 
    400400        $functions[] = array('sin',      'sin',                                          1); 
  • fTimestamp.php

    r270 r271 Hide Line Numbers
    5353    { 
    5454        if (self::$format_callback) { 
    55             return fCore::call(self::$format_callback, array($formatted_string)); 
     55            return fCore::call(self::$format_callback, $formatted_string); 
    5656        } 
    5757        return $formatted_string; 
  • fValidation.php

    r267 r271 Hide Line Numbers
    221221                 
    222222                if (!$found) { 
    223                     $required_field = array_map(array('fGrammar', 'humanize'), $required_field); 
     223                    $required_field = array_map(fCore::callback(fGrammar::humanize), $required_field); 
    224224                    $messages[] = fGrammar::compose( 
    225225                        '%s: Please enter at least one',