root

Changeset 603

Show
Ignore:
Timestamp:
06/15/09 22:55:43 (1 year ago)
Author:
wbond
Message:

Performance improvements, especially related to the ORM

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • fActiveRecord.php

    r600 r603 Hide Line Numbers
    1616 * @link       http://flourishlib.com/fActiveRecord 
    1717 *  
    18  * @version    1.0.0b20 
     18 * @version    1.0.0b21 
     19 * @changes    1.0.0b21  Performance tweaks and updates for fORM and fORMRelated API changes [wb, 2009-06-15] 
    1920 * @changes    1.0.0b20  Changed replacement values in preg_replace() calls to be properly escaped [wb, 2009-06-11] 
    2021 * @changes    1.0.0b19  Added `list{RelatedRecords}()` methods, updated code for new fORMRelated API [wb, 2009-06-02] 
     
    265266    public function __call($method_name, $parameters) 
    266267    { 
    267         if ($callback = fORM::getActiveRecordMethod($this, $method_name)) { 
     268        $class = get_class($this); 
     269         
     270        if ($callback = fORM::getActiveRecordMethod($class, $method_name)) { 
    268271            return call_user_func_array( 
    269272                $callback, 
     
    326329                 
    327330                if (isset($parameters[1])) { 
    328                     return fORMRelated::associateRecords($this, $this->related_records, $subject, $parameters[0], $parameters[1]); 
    329                 } 
    330                 return fORMRelated::associateRecords($this, $this->related_records, $subject, $parameters[0]); 
     331                    return fORMRelated::associateRecords($class, $this->related_records, $subject, $parameters[0], $parameters[1]); 
     332                } 
     333                return fORMRelated::associateRecords($class, $this->related_records, $subject, $parameters[0]); 
    331334             
    332335            case 'build': 
     
    335338                 
    336339                if (isset($parameters[0])) { 
    337                     return fORMRelated::buildRecords($this, $this->values, $this->related_records, $subject, $parameters[0]); 
    338                 } 
    339                 return fORMRelated::buildRecords($this, $this->values, $this->related_records, $subject); 
     340                    return fORMRelated::buildRecords($class, $this->values, $this->related_records, $subject, $parameters[0]); 
     341                } 
     342                return fORMRelated::buildRecords($class, $this->values, $this->related_records, $subject); 
    340343             
    341344            case 'count': 
     
    344347                 
    345348                if (isset($parameters[0])) { 
    346                     return fORMRelated::countRecords($this, $this->values, $this->related_records, $subject, $parameters[0]); 
    347                 } 
    348                 return fORMRelated::countRecords($this, $this->values, $this->related_records, $subject); 
     349                    return fORMRelated::countRecords($class, $this->values, $this->related_records, $subject, $parameters[0]); 
     350                } 
     351                return fORMRelated::countRecords($class, $this->values, $this->related_records, $subject); 
    349352             
    350353            case 'create': 
     
    352355                 
    353356                if (isset($parameters[0])) { 
    354                     return fORMRelated::createRecord($this, $this->values, $subject, $parameters[0]); 
    355                 } 
    356                 return fORMRelated::createRecord($this, $this->values, $subject); 
     357                    return fORMRelated::createRecord($class, $this->values, $subject, $parameters[0]); 
     358                } 
     359                return fORMRelated::createRecord($class, $this->values, $subject); 
    357360              
    358361            case 'inject': 
     
    361364                  
    362365                if (isset($parameters[1])) { 
    363                     return fORMRelated::setRecordSet($this, $this->related_records, $subject, $parameters[0], $parameters[1]); 
    364                 } 
    365                 return fORMRelated::setRecordSet($this, $this->related_records, $subject, $parameters[0]); 
     366                    return fORMRelated::setRecordSet($class, $this->related_records, $subject, $parameters[0], $parameters[1]); 
     367                } 
     368                return fORMRelated::setRecordSet($class, $this->related_records, $subject, $parameters[0]); 
    366369 
    367370            case 'link': 
     
    370373                 
    371374                if (isset($parameters[0])) { 
    372                     return fORMRelated::linkRecords($this, $this->related_records, $subject, $parameters[0]); 
    373                 } 
    374                 return fORMRelated::linkRecords($this, $this->related_records, $subject); 
     375                    return fORMRelated::linkRecords($class, $this->related_records, $subject, $parameters[0]); 
     376                } 
     377                return fORMRelated::linkRecords($class, $this->related_records, $subject); 
    375378             
    376379            case 'list': 
     
    379382                 
    380383                if (isset($parameters[0])) { 
    381                     return fORMRelated::getPrimaryKeys($this, $this->values, $this->related_records, $subject, $parameters[0]); 
    382                 } 
    383                 return fORMRelated::getPrimaryKeys($this, $this->values, $this->related_records, $subject); 
     384                    return fORMRelated::getPrimaryKeys($class, $this->values, $this->related_records, $subject, $parameters[0]); 
     385                } 
     386                return fORMRelated::getPrimaryKeys($class, $this->values, $this->related_records, $subject); 
    384387             
    385388            case 'populate': 
     
    388391                 
    389392                if (isset($parameters[0])) { 
    390                     return fORMRelated::populateRecords($this, $this->related_records, $subject, $parameters[0]); 
    391                 } 
    392                 return fORMRelated::populateRecords($this, $this->related_records, $subject); 
     393                    return fORMRelated::populateRecords($class, $this->related_records, $subject, $parameters[0]); 
     394                } 
     395                return fORMRelated::populateRecords($class, $this->related_records, $subject); 
    393396             
    394397            case 'tally': 
     
    397400                 
    398401                if (isset($parameters[1])) { 
    399                     return fORMRelated::setCount($this, $this->related_records, $subject, $parameters[0], $parameters[1]); 
    400                 } 
    401                 return fORMRelated::setCount($this, $this->related_records, $subject, $parameters[0]); 
     402                    return fORMRelated::setCount($class, $this->related_records, $subject, $parameters[0], $parameters[1]); 
     403                } 
     404                return fORMRelated::setCount($class, $this->related_records, $subject, $parameters[0]); 
    402405             
    403406            // Error handler 
     
    426429    public function __clone() 
    427430    { 
     431        $class = get_class($this); 
     432         
    428433        // Copy values and cache, making sure objects are cloned to prevent reference issues 
    429434        $temp_values  = $this->values; 
     
    431436        $this->values =& $new_values; 
    432437        foreach ($temp_values as $column => $value) { 
    433             $this->values[$column] = fORM::replicate($this, $column, $value); 
     438            $this->values[$column] = fORM::replicate($class, $column, $value); 
    434439        } 
    435440         
     
    458463         
    459464        // If we have a single auto incrementing primary key, remove the value 
    460         $table      = fORM::tablize($this); 
     465        $table      = fORM::tablize($class); 
    461466        $pk_columns = fORMSchema::retrieve()->getKeys($table, 'primary'); 
    462467         
     
    500505        } 
    501506         
    502         if (fORM::getActiveRecordMethod($this, '__construct')) { 
     507        if (fORM::getActiveRecordMethod($class, '__construct')) { 
    503508            return $this->__call('__construct', array($key)); 
    504509        } 
     
    516521        } elseif ($key !== NULL) { 
    517522             
    518             $pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary'); 
     523            $table      = fORM::tablize($class); 
     524            $pk_columns = fORMSchema::retrieve()->getKeys($table, 'primary'); 
    519525             
    520526            // If the primary key does not look properly formatted, check to see if it is a UNIQUE key 
    521527            $is_unique_key = FALSE; 
    522528            if (is_array($key) && (sizeof($pk_columns) == 1 || array_keys($key) != $pk_columns)) { 
    523                 $unique_keys = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'unique'); 
     529                $unique_keys = fORMSchema::retrieve()->getKeys($table, 'unique'); 
    524530                $key_keys    = array_keys($key); 
    525531                foreach ($unique_keys as $unique_key) { 
     
    537543                throw new fProgrammerException( 
    538544                    'An invalidly formatted primary or unique key was passed to this %s object', 
    539                     fORM::getRecordName($this) 
     545                    fORM::getRecordName($class) 
    540546                ); 
    541547            } 
     
    569575        // Create an empty array for new objects 
    570576        } else { 
    571             $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this)); 
     577            $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class)); 
    572578            foreach ($column_info as $column => $info) { 
    573579                $this->values[$column] = NULL; 
     
    577583                        $this->old_values, 
    578584                        $column, 
    579                         fORM::objectify($this, $column, $info['default']) 
     585                        fORM::objectify($class, $column, $info['default']) 
    580586                    );   
    581587                } 
     
    584590         
    585591        fORM::callHookCallbacks( 
    586             $this, 
     592            $class, 
    587593            'post::__construct()', 
    588594            $this->values, 
     
    646652    protected function constructInsertSQL($sql_values) 
    647653    { 
    648         $sql = 'INSERT INTO ' . fORM::tablize($this) . ' ('; 
     654        $sql = 'INSERT INTO ' . fORM::tablize(get_class($this)) . ' ('; 
    649655         
    650656        $columns = ''; 
     
    671677    protected function constructUpdateSQL($sql_values) 
    672678    { 
    673         $table = fORM::tablize($this); 
     679        $table = fORM::tablize(get_class($this)); 
    674680         
    675681        $sql = 'UPDATE ' . $table . ' SET '; 
     
    696702    public function delete() 
    697703    { 
    698         if (fORM::getActiveRecordMethod($this, 'delete')) { 
     704        $class = get_class($this); 
     705         
     706        if (fORM::getActiveRecordMethod($class, 'delete')) { 
    699707            return $this->__call('delete', array()); 
    700708        } 
     
    703711            throw new fProgrammerException( 
    704712                'This %s object does not yet exist in the database, and thus can not be deleted', 
    705                 fORM::getRecordName($this) 
     713                fORM::getRecordName($class) 
    706714            ); 
    707715        } 
     
    715723        ); 
    716724         
    717         $table = fORM::tablize($this); 
     725        $table = fORM::tablize($class); 
    718726         
    719727        $inside_db_transaction = fORMDatabase::retrieve()->isInsideTransaction(); 
     
    780788                    sprintf( 
    781789                        "<p>%1\$s</p>\n<ul>\n<li>%2\$s</li>\n</ul>", 
    782                         self::compose('This %s can not be deleted because:', fORM::getRecordName($this)), 
     790                        self::compose('This %s can not be deleted because:', fORM::getRecordName($class)), 
    783791                        join("</li>\n<li>", $restriction_messages) 
    784792                    ) 
     
    825833            // If we just deleted an object that has an auto-incrementing primary key, 
    826834            // lets delete that value from the object since it is no longer valid 
    827             $column_info = fORMSchema::retrieve()->getColumnInfo($table); 
    828835            $pk_columns  = fORMSchema::retrieve()->getKeys($table, 'primary'); 
    829             if (sizeof($pk_columns) == 1 && $column_info[$pk_columns[0]]['auto_increment']) { 
     836            if (sizeof($pk_columns) == 1 && fORMSchema::retrieve()->getColumnInfo($table, $pk_columns[0], 'auto_increment')) { 
    830837                $this->values[$pk_columns[0]] = NULL; 
    831838                unset($this->old_values[$pk_columns[0]]); 
     
    849856            if ($e instanceof fValidationException) { 
    850857                $message = $e->getMessage(); 
    851                 $search  = self::compose('This %s can not be deleted because:', fORM::getRecordName($this)); 
     858                $search  = self::compose('This %s can not be deleted because:', fORM::getRecordName($class)); 
    852859                if (stripos($message, $search) === FALSE) { 
    853860                    $regex       = self::compose('This %s can not be deleted because:', '__'); 
     
    855862                    $regex       = '#(' . preg_quote($regex_parts[0], '#') . ').*?(' . preg_quote($regex_parts[0], '#') . ')#'; 
    856863                     
    857                     $message = preg_replace($regex, '\1' . strtr(fORM::getRecordName($this), array('\\' => '\\\\', '$' => '\\$')) . '\2', $message); 
     864                    $message = preg_replace($regex, '\1' . strtr(fORM::getRecordName($class), array('\\' => '\\\\', '$' => '\\$')) . '\2', $message); 
    858865                     
    859866                    $find          = self::compose("One or more %s references it", '__'); 
     
    909916        } 
    910917         
    911         $column_type = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column, 'type'); 
     918        $table       = fORM::tablize(get_class($this)); 
     919        $column_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type'); 
    912920         
    913921        // Ensure the programmer is calling the function properly 
     
    950958        // Make sure we don't mangle a non-float value 
    951959        if ($column_type == 'float' && is_numeric($value)) { 
    952             $column_decimal_places = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column, 'decimal_places'); 
     960            $column_decimal_places = fORMSchema::retrieve()->getColumnInfo($table, $column, 'decimal_places'); 
    953961             
    954962            // If the user passed in a formatting value, use it 
     
    981989    public function exists() 
    982990    { 
    983         if (fORM::getActiveRecordMethod($this, 'exists')) { 
     991        $class = get_class($this); 
     992         
     993        if (fORM::getActiveRecordMethod($class, 'exists')) { 
    984994            return $this->__call('exists', array()); 
    985995        } 
    986996         
    987         $pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary'); 
     997        $pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($class), 'primary'); 
    988998        $exists     = FALSE; 
    989999         
     
    10091019    protected function fetchResultFromUniqueKey($values) 
    10101020    {        
     1021        $class = get_class($this); 
    10111022        try { 
    10121023            if ($values === array_combine(array_keys($values), array_fill(0, sizeof($values), NULL))) { 
     
    10141025            } 
    10151026             
    1016             $table = fORM::tablize($this); 
     1027            $table = fORM::tablize($class); 
    10171028            $sql = 'SELECT * FROM ' . $table . ' WHERE '; 
    10181029            $conditions = array(); 
     
    10281039            throw new fNotFoundException( 
    10291040                'The %s requested could not be found', 
    1030                 fORM::getRecordName($this) 
     1041                fORM::getRecordName($class) 
    10311042            ); 
    10321043        } 
     
    10431054     */ 
    10441055    protected function get($column) 
     1056    { 
     1057        if (!isset($this->values[$column]) && !array_key_exists($column, $this->values)) { 
     1058            throw new fProgrammerException( 
     1059                'The column specified, %s, does not exist', 
     1060                $column 
     1061            ); 
     1062        } 
     1063        return $this->values[$column]; 
     1064    } 
     1065     
     1066     
     1067    /** 
     1068     * Takes a row of data or a primary key and makes a hash from the primary key 
     1069     *  
     1070     * @param  mixed $data   An array of the records data, an array of primary key data or a scalar primary key value 
     1071     * @return string  A hash of the record's primary key value 
     1072     */ 
     1073    protected function hash($data) 
     1074    { 
     1075        $class      = get_class($this); 
     1076        $pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize(get_class($this)), 'primary'); 
     1077         
     1078        // Build an array of just the primary key data 
     1079        $pk_data = array(); 
     1080        foreach ($pk_columns as $pk_column) { 
     1081            $pk_data[$pk_column] = fORM::scalarize( 
     1082                $class, 
     1083                $pk_column, 
     1084                is_array($data) ? $data[$pk_column] : $data 
     1085            ); 
     1086            if (is_numeric($pk_data[$pk_column]) || is_object($pk_data[$pk_column])) { 
     1087                $pk_data[$pk_column] = (string) $pk_data[$pk_column];    
     1088            } 
     1089        } 
     1090         
     1091        return md5(serialize($pk_data)); 
     1092    } 
     1093     
     1094     
     1095    /** 
     1096     * Retrieves information about a column 
     1097     *  
     1098     * @param  string $column   The name of the column to inspect 
     1099     * @param  string $element  The metadata element to retrieve 
     1100     * @return mixed  The metadata array for the column, or the metadata element specified 
     1101     */ 
     1102    protected function inspect($column, $element=NULL) 
    10451103    { 
    10461104        if (!array_key_exists($column, $this->values)) { 
     
    10501108            ); 
    10511109        } 
    1052         return $this->values[$column]; 
    1053     } 
    1054      
    1055      
    1056     /** 
    1057      * Takes a row of data or a primary key and makes a hash from the primary key 
    1058      *  
    1059      * @param  mixed $data   An array of the records data, an array of primary key data or a scalar primary key value 
    1060      * @return string  A hash of the record's primary key value 
    1061      */ 
    1062     protected function hash($data) 
    1063     { 
    1064         $pk_columns = fORMSchema::retrieve()->getKeys(fORM::tablize($this), 'primary'); 
    1065          
    1066         // Build an array of just the primary key data 
    1067         $pk_data = array(); 
    1068         foreach ($pk_columns as $pk_column) { 
    1069             $pk_data[$pk_column] = fORM::scalarize( 
    1070                 $this, 
    1071                 $pk_column, 
    1072                 is_array($data) ? $data[$pk_column] : $data 
    1073             ); 
    1074             if (is_numeric($pk_data[$pk_column]) || is_object($pk_data[$pk_column])) { 
    1075                 $pk_data[$pk_column] = (string) $pk_data[$pk_column];    
    1076             } 
    1077         } 
    1078          
    1079         return md5(serialize($pk_data)); 
    1080     } 
    1081      
    1082      
    1083     /** 
    1084      * Retrieves information about a column 
    1085      *  
    1086      * @param  string $column   The name of the column to inspect 
    1087      * @param  string $element  The metadata element to retrieve 
    1088      * @return mixed  The metadata array for the column, or the metadata element specified 
    1089      */ 
    1090     protected function inspect($column, $element=NULL) 
    1091     { 
    1092         if (!array_key_exists($column, $this->values)) { 
    1093             throw new fProgrammerException( 
    1094                 'The column specified, %s, does not exist', 
    1095                 $column 
    1096             ); 
    1097         } 
    1098          
    1099         $info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column); 
     1110         
     1111        $info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize(get_class($this)), $column); 
    11001112         
    11011113        if (!in_array($info['type'], array('varchar', 'char', 'text'))) { 
     
    11381150    public function load() 
    11391151    { 
    1140         if (fORM::getActiveRecordMethod($this, 'load')) { 
     1152        $class = get_class($this); 
     1153         
     1154        if (fORM::getActiveRecordMethod($class, 'load')) { 
    11411155            return $this->__call('load', array()); 
    11421156        } 
    11431157         
    11441158        try { 
    1145             $table = fORM::tablize($this); 
     1159            $table = fORM::tablize($class); 
    11461160            $sql = 'SELECT * FROM ' . $table . ' WHERE ' . fORMDatabase::createPrimaryKeyWhereClause($table, $table, $this->values, $this->old_values); 
    11471161         
     
    11521166            throw new fNotFoundException( 
    11531167                'The %s requested could not be found', 
    1154                 fORM::getRecordName($this) 
     1168                fORM::getRecordName($class) 
    11551169            ); 
    11561170        } 
     
    11701184    protected function loadFromResult($result) 
    11711185    { 
     1186        $class       = get_class($this); 
    11721187        $row         = $result->current(); 
    1173         $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this)); 
     1188        $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class)); 
     1189         
     1190        $db = fORMDatabase::retrieve(); 
    11741191         
    11751192        foreach ($row as $column => $value) { 
    1176             if ($value === NULL) { 
    1177                 $this->values[$column] = $value; 
    1178             } else { 
    1179                 $this->values[$column] = fORMDatabase::retrieve()->unescape($column_info[$column]['type'], $value); 
    1180             } 
    1181              
    1182             $this->values[$column] = fORM::objectify($this, $column, $this->values[$column]); 
     1193            if ($value !== NULL) { 
     1194                $value = $db->unescape($column_info[$column]['type'], $value); 
     1195            } 
     1196             
     1197            $this->values[$column] = fORM::objectify($class, $column, $value); 
    11831198        } 
    11841199         
    11851200        // Save this object to the identity map 
    1186         $class = get_class($this); 
    11871201        $hash  = $this->hash($row); 
    11881202         
     
    12471261    public function populate() 
    12481262    { 
    1249         if (fORM::getActiveRecordMethod($this, 'populate')) { 
     1263        $class = get_class($this); 
     1264         
     1265        if (fORM::getActiveRecordMethod($class, 'populate')) { 
    12501266            return $this->__call('populate', array()); 
    12511267        } 
     
    12601276        ); 
    12611277         
    1262         $table = fORM::tablize($this); 
     1278        $table = fORM::tablize($class); 
    12631279         
    12641280        $column_info = fORMSchema::retrieve()->getColumnInfo($table); 
     
    13081324        } 
    13091325         
    1310         $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this), $column); 
     1326        $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize(get_class($this)), $column); 
    13111327        $column_type = $column_info['type']; 
    13121328         
    13131329        // Ensure the programmer is calling the function properly 
    1314         if (in_array($column_type, array('blob'))) { 
     1330        if ($column_type == 'blob') { 
    13151331            throw new fProgrammerException( 
    13161332                'The column specified, %s, can not be prepared because it is a blob column', 
     
    13971413        $signatures = array(); 
    13981414         
    1399         $columns_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($this)); 
     1415        $class        = get_class($this); 
     1416        $columns_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class)); 
    14001417        foreach ($columns_info as $column => $column_info) { 
    14011418            $camelized_column = fGrammar::camelize($column, TRUE); 
     
    15521569        } 
    15531570         
    1554         fORMRelated::reflect($this, $signatures, $include_doc_comments); 
     1571        fORMRelated::reflect($class, $signatures, $include_doc_comments); 
    15551572         
    15561573        fORM::callReflectCallbacks($this, $signatures, $include_doc_comments); 
    15571574         
    1558         $reflection = new ReflectionClass(get_class($this)); 
     1575        $reflection = new ReflectionClass($class); 
    15591576        $methods    = $reflection->getMethods(); 
    15601577         
     
    16631680        $class = get_class($this); 
    16641681        $hash  = self::hash($this->values); 
    1665          
     1682        $table = fORM::tablize($class); 
     1683             
    16661684        // If the object has not been replicated yet, do it now 
    16671685        if (!isset(fActiveRecord::$replicate_map[$class])) { 
     
    16721690             
    16731691            // We need the primary key to get a hash, otherwise certain recursive relationships end up losing members 
    1674             $table      = fORM::tablize($class); 
    16751692            $pk_columns = fORMSchema::retrieve()->getKeys($table, 'primary'); 
    16761693            if (sizeof($pk_columns) == 1 && fORMSchema::retrieve()->getColumnInfo($table, $pk_columns[0], 'auto_increment')) { 
     
    16821699         
    16831700        $parameters = func_get_args(); 
    1684          
    1685         $table = fORM::tablize($this); 
    16861701         
    16871702        $recursive                  = FALSE; 
     
    17411756                    'The related class specified, %1$s, does not appear to be in a many-to-many or one-to-many relationship with %$2s', 
    17421757                    $parameter, 
    1743                     fORM::getClass($this) 
     1758                    get_class($this) 
    17441759                );   
    17451760            } 
    17461761             
    17471762            // Get the related records 
    1748             $record_set = fORMRelated::buildRecords($this, $this->values, $this->related_records, $related_class, $route); 
     1763            $record_set = fORMRelated::buildRecords($class, $this->values, $this->related_records, $related_class, $route); 
    17491764             
    17501765            // One-to-many records need to be replicated, possibly recursively 
     
    17631778             
    17641779            // Cause the related records to be associated with the new clone 
    1765             fORMRelated::associateRecords($this, $clone->related_records, $related_class, $record_set, $route); 
     1780            fORMRelated::associateRecords($class, $clone->related_records, $related_class, $record_set, $route); 
    17661781        } 
    17671782         
     
    18071822        } 
    18081823         
    1809         $value = fORM::objectify($this, $column, $value); 
     1824        $class = get_class($this); 
     1825        $value = fORM::objectify($class, $column, $value); 
    18101826         
    18111827        // Float and int columns that look like numbers with commas will have the commas removed 
    18121828        if (is_string($value)) { 
    1813             $table = fORM::tablize($this); 
     1829            $table = fORM::tablize($class); 
    18141830            $type  = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type'); 
    18151831            if (in_array($type, array('integer', 'float')) && preg_match('#^(\d+,)+\d+(\.\d+)?$#', $value)) { 
     
    18341850    public function store() 
    18351851    { 
    1836         if (fORM::getActiveRecordMethod($this, 'store')) { 
     1852        $class = get_class($this); 
     1853         
     1854        if (fORM::getActiveRecordMethod($class, 'store')) { 
    18371855            return $this->__call('store', array()); 
    18381856        } 
     
    18481866         
    18491867        try { 
    1850             $table       = fORM::tablize($this); 
     1868            $table       = fORM::tablize($class); 
    18511869            $column_info = fORMSchema::retrieve()->getColumnInfo($table); 
    18521870             
     
    18921910            $sql_values = array(); 
    18931911            foreach ($column_info as $column => $info) { 
    1894                 $value = fORM::scalarize($this, $column, $this->values[$column]); 
     1912                $value = fORM::scalarize($class, $column, $this->values[$column]); 
    18951913                $sql_values[$column] = fORMDatabase::escapeBySchema($table, $column, $value); 
    18961914            } 
     
    19161934             
    19171935            // Storing *-to-many relationships 
    1918             fORMRelated::store($this, $this->values, $this->related_records); 
     1936            fORMRelated::store($class, $this->values, $this->related_records); 
    19191937             
    19201938             
     
    19922010    public function validate($return_messages=FALSE) 
    19932011    { 
    1994         if (fORM::getActiveRecordMethod($this, 'validate')) { 
     2012        $class = get_class($this); 
     2013         
     2014        if (fORM::getActiveRecordMethod($class, 'validate')) { 
    19952015            return $this->__call('validate', array($return_messages)); 
    19962016        } 
     
    20122032         
    20132033        // Validate related records 
    2014         $related_validation_messages = fORMValidation::validateRelated($this, $this->related_records); 
     2034        $related_validation_messages = fORMValidation::validateRelated($class, $this->related_records); 
    20152035         
    20162036        $validation_messages = array_merge($validation_messages, $local_validation_messages, $related_validation_messages); 
     
    20262046        ); 
    20272047         
    2028         fORMValidation::reorderMessages($this, $validation_messages); 
     2048        fORMValidation::reorderMessages($class, $validation_messages); 
    20292049         
    20302050        if ($return_messages) { 
  • fDatabase.php

    r600 r603 Hide Line Numbers
    4747 * @link       http://flourishlib.com/fDatabase 
    4848 *  
    49  * @version    1.0.0b11 
     49 * @version    1.0.0b12 
     50 * @changes    1.0.0b12  Updates to ::unescape() to improve performance [wb, 2009-06-15] 
    5051 * @changes    1.0.0b11  Changed replacement values in preg_replace() calls to be properly escaped [wb, 2009-06-11] 
    5152 * @changes    1.0.0b10  Changed date/time/timestamp escaping from `strtotime()` to fDate/fTime/fTimestamp for better localization support [wb, 2009-06-01] 
     
    22802281         
    22812282        switch ($data_type) { 
    2282             case 'blob': 
    2283             case '%l': 
    2284                 $callback = $this->unescapeBlob; 
    2285                 break; 
    2286             case 'boolean': 
    2287             case '%b': 
    2288                 $callback = $this->unescapeBoolean; 
    2289                 break; 
    2290             case 'date': 
    2291             case '%d': 
    2292                 $callback = $this->unescapeDate; 
    2293                 break; 
    2294             case 'float': 
    2295             case '%f': 
    2296                 $callback = $this->unescapeFloat; 
    2297                 break; 
    2298             case 'integer': 
    2299             case '%i': 
    2300                 $callback = $this->unescapeInteger; 
    2301                 break; 
     2283            // Testing showed that strings tend to be most common, 
     2284            // and moving this to the top of the switch statement 
     2285            // improved performance on read-heavy pages 
    23022286            case 'string': 
    23032287            case 'varchar': 
     
    23052289            case 'text': 
    23062290            case '%s': 
    2307                 $callback = $this->unescapeString; 
     2291                return $value; 
     2292             
     2293            case 'boolean': 
     2294            case '%b': 
     2295                $callback = $this->unescapeBoolean; 
    23082296                break; 
     2297                 
     2298            case 'date': 
     2299            case '%d': 
     2300                $callback = $this->unescapeDate; 
     2301                break; 
     2302                 
     2303            case 'float': 
     2304            case '%f': 
     2305                return $value; 
     2306                 
     2307            case 'integer': 
     2308            case '%i': 
     2309                return $value; 
     2310             
    23092311            case 'time': 
    23102312            case '%t': 
    23112313                $callback = $this->unescapeTime; 
    23122314                break; 
     2315                 
    23132316            case 'timestamp': 
    23142317            case '%p': 
    23152318                $callback = $this->unescapeTimestamp; 
     2319                break; 
     2320             
     2321            case 'blob': 
     2322            case '%l': 
     2323                $callback = $this->unescapeBlob; 
    23162324                break; 
    23172325        } 
     
    23822390        } 
    23832391        return date('Y-m-d', strtotime($value)); 
    2384     } 
    2385      
    2386      
    2387     /** 
    2388      * Unescapes a float coming out of the database (included for completeness) 
    2389      *  
    2390      * @param  string $value  The value to unescape 
    2391      * @return float  The float 
    2392      */ 
    2393     private function unescapeFloat($value) 
    2394     { 
    2395         return $value; 
    2396     } 
    2397      
    2398      
    2399     /** 
    2400      * Unescapes an integer coming out of the database (included for completeness) 
    2401      *  
    2402      * @param  string $value  The value to unescape 
    2403      * @return integer  The integer 
    2404      */ 
    2405     private function unescapeInteger($value) 
    2406     { 
    2407         return $value; 
    2408     } 
    2409      
    2410      
    2411     /** 
    2412      * Unescapes a string coming out of the database (included for completeness) 
    2413      *  
    2414      * @param  string $value  The value to unescape 
    2415      * @return string  The string 
    2416      */ 
    2417     private function unescapeString($value) 
    2418     { 
    2419         return $value; 
    24202392    } 
    24212393     
  • fGrammar.php

    r600 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fGrammar 
    1111 *  
    12  * @version    1.0.0b2 
     12 * @version    1.0.0b4 
     13 * @changes    1.0.0b4  Added caching for various methods - provided significant performance boost to ORM [wb, 2009-06-15]  
    1314 * @changes    1.0.0b3  Changed replacement values in preg_replace() calls to be properly escaped [wb, 2009-06-11] 
    1415 * @changes    1.0.0b2  Fixed a bug where some words would lose capitalization with ::pluralize() and ::singularize() [wb, 2009-01-25] 
     
    3132    const underscorize              = 'fGrammar::underscorize'; 
    3233     
     34     
     35    /** 
     36     * Cache for plural <-> singular and underscore <-> camelcase 
     37     *  
     38     * @var array 
     39     */ 
     40    static private $cache = array( 
     41        'camelize'     => array(0 => array(), 1 => array()), 
     42        'humanize'     => array(), 
     43        'pluralize'    => array(), 
     44        'singularize'  => array(), 
     45        'underscorize' => array() 
     46    ); 
    3347     
    3448    /** 
     
    124138    { 
    125139        self::$humanize_rules[$non_humanized_string] = $humanized_string; 
     140         
     141        self::$cache['humanize'] = array(); 
    126142    } 
    127143     
     
    139155        self::$underscorize_rules[$camel_case] = $underscore_notation; 
    140156        self::$camelize_rules[$underscore_notation] = $camel_case; 
     157         
     158        self::$cache['camelize']     = array(0 => array(), 1 => array()); 
     159        self::$cache['underscorize'] = array(); 
    141160    } 
    142161     
     
    165184            self::$plural_to_singular_rules 
    166185        ); 
     186         
     187        self::$cache['pluralize']   = array(); 
     188        self::$cache['singularize'] = array(); 
    167189    } 
    168190     
     
    177199    static public function camelize($string, $upper) 
    178200    { 
     201        $upper = (int) $upper; 
     202        if (isset(self::$cache['camelize'][$upper][$string])) { 
     203            return self::$cache['camelize'][$upper][$string];        
     204        } 
     205         
     206        $original = $string; 
     207         
    179208        // Handle custom rules 
    180209        if (isset(self::$camelize_rules[$string])) { 
    181             $camel = self::$camelize_rules[$string]; 
     210            $string = self::$camelize_rules[$string]; 
    182211            if ($upper) { 
    183                 return strtoupper($camel[0]) . substr($camel, 1); 
     212                $string = strtoupper($camel[0]) . substr($camel, 1); 
    184213            } 
    185             return $camel;   
    186         } 
    187214         
    188215        // Make a humanized string like underscore notation 
    189         if (strpos($string, ' ') !== FALSE) { 
     216        } elseif (strpos($string, ' ') !== FALSE) { 
    190217            $string = strtolower(preg_replace('#\s+#', '_', $string)); 
    191         } 
    192218         
    193219        // Check to make sure this is not already camel case 
    194         if (strpos($string, '_') === FALSE) { 
     220        } elseif (strpos($string, '_') === FALSE) { 
    195221            if ($upper) { 
    196222                $string = strtoupper($string[0]) . substr($string, 1); 
    197223            } 
    198             return $string; 
    199         } 
    200          
     224             
    201225        // Handle underscore notation 
    202         $string = strtolower($string); 
    203         if ($upper) { 
    204             $string = strtoupper($string[0]) . substr($string, 1); 
    205         } 
    206         return preg_replace('/(_([a-z0-9]))/e', 'strtoupper("\2")', $string); 
     226        } else { 
     227            $string = strtolower($string); 
     228            if ($upper) { 
     229                $string = strtoupper($string[0]) . substr($string, 1); 
     230            } 
     231            $string = preg_replace('/(_([a-z0-9]))/e', 'strtoupper("\2")', $string);         
     232        } 
     233         
     234        self::$cache['camelize'][$upper][$original] = $string; 
     235        return $string; 
    207236    } 
    208237     
     
    216245    static public function humanize($string) 
    217246    { 
     247        if (isset(self::$cache['humanize'][$string])) { 
     248            return self::$cache['humanize'][$string]; 
     249        } 
     250         
     251        $original = $string; 
     252         
    218253        if (isset(self::$humanize_rules[$string])) { 
    219             return self::$humanize_rules[$string];   
    220         } 
    221          
    222         // If there is a space, it is already humanized 
    223         if (strpos($string, ' ') !== FALSE) { 
    224             return $string; 
    225         } 
    226          
    227         // If we don't have an underscore we probably have camelCase 
    228         if (strpos($string, '_') === FALSE) { 
    229             $string = self::underscorize($string); 
    230         } 
    231          
    232         return preg_replace( 
    233             '/(\b(api|css|gif|html|id|jpg|js|mp3|pdf|php|png|sql|swf|url|xhtml|xml)\b|\b\w)/e', 
    234             'strtoupper("\1")', 
    235             str_replace('_', ' ', $string) 
    236         ); 
     254            $string = self::$humanize_rules[$string];    
     255         
     256        // If there is no space, it isn't already humanized 
     257        } elseif (strpos($string, ' ') === FALSE) { 
     258             
     259            // If we don't have an underscore we probably have camelCase 
     260            if (strpos($string, '_') === FALSE) { 
     261                $string = self::underscorize($string); 
     262            } 
     263             
     264            $string = preg_replace( 
     265                '/(\b(api|css|gif|html|id|jpg|js|mp3|pdf|php|png|sql|swf|url|xhtml|xml)\b|\b\w)/e', 
     266                'strtoupper("\1")', 
     267                str_replace('_', ' ', $string) 
     268            ); 
     269        } 
     270         
     271        self::$cache['humanize'][$original] = $string; 
     272         
     273        return $string; 
    237274    } 
    238275     
     
    347384    static public function pluralize($singular_noun) 
    348385    { 
     386        if (isset(self::$cache['pluralize'][$singular_noun])) { 
     387            return self::$cache['pluralize'][$singular_noun];        
     388        } 
     389         
     390        $original    = $singular_noun; 
     391        $plural_noun = NULL; 
     392         
    349393        list ($beginning, $singular_noun) = self::splitLastWord($singular_noun); 
    350394        foreach (self::$singular_to_plural_rules as $from => $to) { 
    351395            if (preg_match('#' . $from . '#iD', $singular_noun)) { 
    352                 return $beginning . preg_replace('#' . $from . '#iD', $to, $singular_noun); 
     396                $plural_noun = $beginning . preg_replace('#' . $from . '#iD', $to, $singular_noun); 
     397                break; 
    353398            } 
    354399        } 
    355         throw new fProgrammerException('The noun specified could not be pluralized'); 
     400         
     401        if (!$plural_noun) { 
     402            throw new fProgrammerException('The noun specified could not be pluralized'); 
     403        } 
     404         
     405        self::$cache['pluralize'][$original] = $plural_noun; 
     406         
     407        return $plural_noun; 
    356408    } 
    357409     
     
    384436    static public function reset() 
    385437    { 
    386         self::$camelize_rules    = array(); 
     438        self::$cache                    = array( 
     439            'camelize'     => array(0 => array(), 1 => array()), 
     440            'humanize'     => array(), 
     441            'pluralize'    => array(), 
     442            'singularize'  => array(), 
     443            'underscorize' => array() 
     444        ); 
     445        self::$camelize_rules           = array(); 
    387446        self::$humanize_rules           = array(); 
    388447        self::$join_array_callback      = NULL; 
     
    439498    static public function singularize($plural_noun) 
    440499    { 
     500        if (isset(self::$cache['singularize'][$plural_noun])) { 
     501            return self::$cache['singularize'][$plural_noun];        
     502        } 
     503         
     504        $original      = $plural_noun; 
     505        $singular_noun = NULL; 
     506         
    441507        list ($beginning, $plural_noun) = self::splitLastWord($plural_noun); 
    442508        foreach (self::$plural_to_singular_rules as $from => $to) { 
    443509            if (preg_match('#' . $from . '#iD', $plural_noun)) { 
    444                 return $beginning . preg_replace('#' . $from . '#iD', $to, $plural_noun); 
     510                $singular_noun = $beginning . preg_replace('#' . $from . '#iD', $to, $plural_noun); 
     511                break; 
    445512            } 
    446513        } 
    447         throw new fProgrammerException('The noun specified could not be singularized'); 
     514         
     515        if (!$singular_noun) { 
     516            throw new fProgrammerException('The noun specified could not be singularized'); 
     517        } 
     518         
     519        self::$cache['singularize'][$original] = $singular_noun; 
     520         
     521        return $singular_noun; 
    448522    } 
    449523     
     
    485559    static public function underscorize($string) 
    486560    { 
     561        if (isset(self::$cache['underscorize'][$string])) { 
     562            return self::$cache['underscorize'][$string];        
     563        } 
     564         
     565        $original = $string; 
    487566        $string = strtolower($string[0]) . substr($string, 1); 
    488567         
    489568        // Handle custom rules 
    490569        if (isset(self::$underscorize_rules[$string])) { 
    491             return self::$underscorize_rules[$string]; 
    492         } 
     570            $string = self::$underscorize_rules[$string]; 
    493571         
    494572        // If the string is already underscore notation then leave it 
    495         if (strpos($string, '_') !== FALSE) { 
    496             return $string; 
    497         } 
     573        } elseif (strpos($string, '_') !== FALSE) { 
    498574         
    499575        // Allow humanized string to be passed in 
    500         if (strpos($string, ' ') !== FALSE) { 
    501             return strtolower(preg_replace('#\s+#', '_', $string)); 
    502         } 
    503          
    504         do { 
    505             $old_string = $string; 
    506             $string = preg_replace('/([a-zA-Z])([0-9])/', '\1_\2', $string); 
    507             $string = preg_replace('/([a-z0-9A-Z])([A-Z])/', '\1_\2', $string); 
    508         } while ($old_string != $string); 
    509          
    510         return strtolower($string); 
     576        } elseif (strpos($string, ' ') !== FALSE) { 
     577            $string = strtolower(preg_replace('#\s+#', '_', $string)); 
     578         
     579        } else { 
     580            do { 
     581                $old_string = $string; 
     582                $string = preg_replace('/([a-zA-Z])([0-9])/', '\1_\2', $string); 
     583                $string = preg_replace('/([a-z0-9A-Z])([A-Z])/', '\1_\2', $string); 
     584            } while ($old_string != $string); 
     585             
     586            $string = strtolower($string); 
     587        } 
     588         
     589        self::$cache['underscorize'][$original] = $string; 
     590         
     591        return $string; 
    511592    } 
    512593     
  • fORM.php

    r591 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORM 
    1111 *  
    12  * @version    1.0.0b8 
     12 * @version    1.0.0b9 
     13 * @changes    1.0.0b9  Added caching for performance and changed some method APIs to only allow class names instead of instances [wb, 2009-06-15] 
    1314 * @changes    1.0.0b8  Updated documentation to reflect removal of `$associate` parameter for callbacks passed to ::registerRecordSetMethod() [wb, 2009-06-02] 
    1415 * @changes    1.0.0b7  Added ::enableSchemaCaching() to replace fORMSchema::enableSmartCaching() [wb, 2009-05-04] 
     
    6061     
    6162    /** 
     63     * Cache for repetitive computation 
     64     *  
     65     * @var array 
     66     */ 
     67    static private $cache = array( 
     68        'parseMethod'           => array(), 
     69        'getActiveRecordMethod' => array(), 
     70        'objectify'             => array() 
     71    ); 
     72     
     73    /** 
    6274     * Custom mappings for class <-> table 
    6375     *  
     
    159171    static public function callHookCallbacks($object, $hook, &$values, &$old_values, &$related_records, &$cache, &$parameter=NULL) 
    160172    { 
    161         $class = self::getClass($object); 
     173        $class = get_class($object); 
    162174         
    163175        if (empty(self::$hook_callbacks[$class][$hook]) && empty(self::$hook_callbacks['*'][$hook])) { 
     
    205217    static public function callReflectCallbacks($object, &$signatures, $include_doc_comments) 
    206218    { 
    207         $class = self::getClass($object); 
     219        $class = get_class($object); 
    208220         
    209221        if (!isset(self::$reflect_callbacks[$class]) && !isset(self::$reflect_callbacks['*'])) { 
     
    242254     * @internal 
    243255     *  
    244      * @param  mixed  $class     The name of the class, or an instance of it 
     256     * @param  string $class     The name of the class 
    245257     * @param  string $hook      The hook to check 
    246258     * @param  array  $callback  The specific callback to check for 
     
    249261    static public function checkHookCallback($class, $hook, $callback=NULL) 
    250262    { 
    251         $class = self::getClass($class); 
    252          
    253263        if (empty(self::$hook_callbacks[$class][$hook]) && empty(self::$hook_callbacks['*'][$hook])) { 
    254264            return FALSE; 
     
    360370     * @internal 
    361371     *  
    362      * @param  mixed  $class   The name of the class, or an instance of it 
     372     * @param  string $class   The name of the class 
    363373     * @param  string $method  The method to get the callback for 
    364374     * @return string|null  The callback for the method or `NULL` if none exists - see method description for details 
     
    366376    static public function getActiveRecordMethod($class, $method) 
    367377    { 
    368         $class = self::getClass($class); 
     378        // This caches method lookups, providing a significant performance 
     379        // boost to pages with lots of method calls that get passed to 
     380        // fActiveRecord::__call() 
     381        if (isset(self::$cache['getActiveRecordMethod'][$class . '::' . $method])) { 
     382            return (!$method = self::$cache['getActiveRecordMethod'][$class . '::' . $method]) ? NULL : $method;     
     383        } 
     384         
     385        $callback = NULL; 
    369386         
    370387        if (isset(self::$active_record_method_callbacks[$class][$method])) { 
    371             return self::$active_record_method_callbacks[$class][$method];   
    372         } 
    373          
    374         if (isset(self::$active_record_method_callbacks['*'][$method])) { 
    375             return self::$active_record_method_callbacks['*'][$method];  
    376         } 
    377          
    378         if (preg_match('#[A-Z0-9]#', $method)) { 
     388            $callback = self::$active_record_method_callbacks[$class][$method];  
     389         
     390        } elseif (isset(self::$active_record_method_callbacks['*'][$method])) { 
     391            $callback = self::$active_record_method_callbacks['*'][$method];     
     392         
     393        } elseif (preg_match('#[A-Z0-9]#', $method)) { 
    379394            list($action, $subject) = self::parseMethod($method); 
    380395            if (isset(self::$active_record_method_callbacks[$class][$action . '*'])) { 
    381                 return self::$active_record_method_callbacks[$class][$action . '*'];   
     396                $callback = self::$active_record_method_callbacks[$class][$action . '*'];  
    382397            }    
    383398        } 
    384399         
    385         return NULL;     
     400        self::$cache['getActiveRecordMethod'][$class . '::' . $method] = ($callback === NULL) ? FALSE : $callback; 
     401        return $callback; 
    386402    } 
    387403     
     
    410426     * @internal 
    411427     *  
    412      * @param  mixed  $class   The class name or instance of the class the column is part of 
     428     * @param  string $class   The class name the column is part of 
    413429     * @param  string $column  The database column 
    414430     * @return string  The column name for the column specified 
     
    416432    static public function getColumnName($class, $column) 
    417433    { 
    418         $class = self::getClass($class); 
    419          
    420434        if (!isset(self::$column_names[$class])) { 
    421435            self::$column_names[$class] = array(); 
     
    438452     * @internal 
    439453     *  
    440      * @param  mixed $class  The class name or instance of the class to get the record name of 
     454     * @param  string $class  The class name to get the record name of 
    441455     * @return string  The record name for the class specified 
    442456     */ 
    443457    static public function getRecordName($class) 
    444458    { 
    445         $class = self::getClass($class); 
    446          
    447459        if (!isset(self::$record_names[$class])) { 
    448460            self::$record_names[$class] = fGrammar::humanize($class); 
     
    496508    static public function objectify($class, $column, $value) 
    497509    { 
    498         $class = self::getClass($class); 
     510        // This short-circuits computation for already checked columns, providing 
     511        // a nice little performance boost to pages with lots of records 
     512        if (isset(self::$cache['objectify'][$class . '::' . $column])) { 
     513            return $value;   
     514        } 
    499515         
    500516        if (!empty(self::$objectify_callbacks[$class][$column])) { 
     
    520536                // Validation exception results in the raw value being saved 
    521537            } 
     538         
     539        } else { 
     540            self::$cache['objectify'][$class . '::' . $column] = TRUE;   
    522541        } 
    523542         
     
    576595    static public function parseMethod($method) 
    577596    { 
     597        if (isset(self::$cache['parseMethod'][$method])) { 
     598            return self::$cache['parseMethod'][$method];     
     599        } 
     600         
    578601        if (!preg_match('#^([a-z]+)(.*)$#D', $method, $matches)) { 
    579602            throw new fProgrammerException( 
     
    582605            );   
    583606        } 
    584         return array($matches[1], fGrammar::underscorize($matches[2])); 
     607        self::$cache['parseMethod'][$method] = array($matches[1], fGrammar::underscorize($matches[2])); 
     608        return self::$cache['parseMethod'][$method]; 
    585609    } 
    586610     
     
    617641         
    618642        self::$active_record_method_callbacks[$class][$method] = $callback; 
     643         
     644        self::$cache['getActiveRecordMethod'] = array(); 
    619645    } 
    620646     
     
    733759         
    734760        self::$objectify_callbacks[$class][$column] = $callback; 
     761         
     762        self::$cache['objectify'] = array(); 
    735763    } 
    736764     
     
    849877     * @internal 
    850878     *  
    851      * @param  mixed  $class   The class name or instance of the class the column is part of 
     879     * @param  string $class   The class the column is part of 
    852880     * @param  string $column  The database column 
    853881     * @param  mixed  $value   The value to copy/clone 
     
    856884    static public function replicate($class, $column, $value) 
    857885    { 
    858         $class = self::getClass($class); 
    859          
    860886        if (!empty(self::$replicate_callbacks[$class][$column])) { 
    861887            return call_user_func(self::$replicate_callbacks[$class][$column], $class, $column, $value); 
     
    879905    static public function reset() 
    880906    { 
     907        self::$active_record_method_callbacks = array(); 
     908        self::$cache                          = array( 
     909            'parseMethod'           => array(), 
     910            'getActiveRecordMethod' => array(), 
     911            'objectify'             => array() 
     912        ); 
    881913        self::$class_table_map                = array(); 
    882         self::$active_record_method_callbacks = array(); 
    883914        self::$column_names                   = array(); 
    884915        self::$hook_callbacks                 = array(); 
     
    928959    static public function tablize($class) 
    929960    { 
    930         $class = self::getClass($class); 
    931          
    932961        if (!isset(self::$class_table_map[$class])) { 
    933962            self::$class_table_map[$class] = fGrammar::underscorize(fGrammar::pluralize($class)); 
  • fORMColumn.php

    r598 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORMColumn 
    1111 *  
    12  * @version    1.0.0b3 
     12 * @version    1.0.0b4 
     13 * @changes    1.0.0b4  Updated code for new fORM API [wb, 2009-06-15] 
    1314 * @changes    1.0.0b3  Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]   
    1415 * @changes    1.0.0b2  Fixed a bug with objectifying number columns [wb, 2008-11-24] 
     
    331332        list ($action, $column) = fORM::parseMethod($method_name); 
    332333         
    333         $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($object), $column);   
     334        $class       = get_class($object); 
     335        $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column); 
    334336        $value       = $values[$column]; 
    335337         
     
    365367        list ($action, $column) = fORM::parseMethod($method_name); 
    366368         
    367         $class = fORM::getClass($object); 
     369        $class = get_class($object); 
    368370        $table = fORM::tablize($class); 
    369371         
     
    540542        list ($action, $column) = fORM::parseMethod($method_name); 
    541543         
    542         $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($object), $column);   
     544        $class       = get_class($object); 
     545        $column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column); 
    543546        $value       = $values[$column]; 
    544547         
     
    594597         
    595598        if (isset(self::$number_columns[$class])) { 
     599             
     600            $table = fORM::tablize($class); 
     601             
    596602            foreach(self::$number_columns[$class] as $column => $enabled) { 
    597603                $camelized_column = fGrammar::camelize($column, TRUE); 
    598                 $type             = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column, 'type'); 
     604                $type             = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type'); 
    599605                 
    600606                // Get and set methods 
  • fORMFile.php

    r600 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORMFile 
    1111 *  
    12  * @version    1.0.0b12 
     12 * @version    1.0.0b13 
     13 * @changes    1.0.0b13  Updated code for new fORM API [wb, 2009-06-15] 
    1314 * @changes    1.0.0b12  Changed replacement values in preg_replace() calls to be properly escaped [wb, 2009-06-11] 
    1415 * @changes    1.0.0b11  Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]   
     
    744745        list ($action, $column) = fORM::parseMethod($method_name); 
    745746         
    746         $class = fORM::getClass($object); 
     747        $class = get_class($object); 
    747748         
    748749        self::processImage($class, $column, $values[$column]); 
  • fORMOrdering.php

    r602 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORMOrdering 
    1111 *  
    12  * @version    1.0.0b5 
     12 * @version    1.0.0b6 
     13 * @changes    1.0.0b6  Updated code for new fORM API [wb, 2009-06-15] 
    1314 * @changes    1.0.0b5  Updated class to automatically correct ordering values that are too high [wb, 2009-06-14] 
    1415 * @changes    1.0.0b4  Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]   
     
    561562    static public function validate($object, &$values, &$old_values, &$related_records, &$cache, &$validation_messages) 
    562563    { 
    563         $class = fORM::getClass($object); 
     564        $class = get_class($object); 
    564565        $table = fORM::tablize($class); 
    565566         
  • fORMRelated.php

    r598 r603 Hide Line Numbers
    1313 * @link       http://flourishlib.com/fORMRelated 
    1414 *  
    15  * @version    1.0.0b6 
     15 * @version    1.0.0b7 
     16 * @changes    1.0.0b7  Updated code for new fORM API, fixed API documentation bugs [wb, 2009-06-15] 
    1617 * @changes    1.0.0b6  Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]   
    1718 * @changes    1.0.0b5  Added ::getPrimaryKeys() and ::setPrimaryKeys(), renamed ::setRecords() to ::setRecordSet() and ::tallyRecords() to ::setCount() [wb, 2009-06-02] 
     
    6768     * @internal 
    6869     *  
    69      * @param  mixed             $class                 The class name or instance of the class to get the related values for 
     70     * @param  string            $class                 The class to get the related values for 
    7071     * @param  array             &$related_records      The related records existing for the fActiveRecord class 
    7172     * @param  string            $related_class         The class we are associating with the current record 
     
    111112     * @internal 
    112113     *  
    113      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     114     * @param  string $class             The class to get the related values for 
    114115     * @param  array  &$values           The values for the fActiveRecord class 
    115116     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
     
    186187     * @internal 
    187188     *  
    188      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     189     * @param  string $class             The class to get the related values for 
    189190     * @param  array  &$values           The values for the fActiveRecord class 
    190191     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
     
    242243     * @internal 
    243244     *  
    244      * @param  mixed  $class          The class name or instance of the class to get the related values for 
     245     * @param  string $class          The class to create the related record for 
    245246     * @param  array  $values         The values existing in the fActiveRecord class 
    246247     * @param  string $related_class  The related class name 
     
    250251    static public function createRecord($class, $values, $related_class, $route=NULL) 
    251252    { 
    252         $table = fORM::tablize($class); 
    253          
     253        $table         = fORM::tablize($class); 
    254254        $related_table = fORM::tablize($related_class); 
    255255         
     
    265265     * @internal 
    266266     *  
    267      * @param  mixed  $class          The class name or instance of the main class 
     267     * @param  string $class          The class name of the main class 
    268268     * @param  string $related_class  The related class being filtered for 
    269269     * @param  string $route          The route to the related table 
     
    300300     * @internal 
    301301     *  
    302      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     302     * @param  string $class             The class to associate the related records to 
    303303     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
    304304     * @param  string $related_class     The class we are associating with the current record 
     
    331331     * @internal 
    332332     *  
    333      * @param  mixed  $class          The class name or instance of the class this ordering rule applies to 
     333     * @param  string $class          The class to get the order bys for 
    334334     * @param  string $related_class  The related class the ordering rules apply to 
    335335     * @param  string $route          The route to the related table, should be a column name in the current table or a join table name 
     
    356356     * @internal 
    357357     *  
    358      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     358     * @param  string $class             The class to get the related primary keys for 
    359359     * @param  array  &$values           The values for the fActiveRecord class 
    360360     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
     
    448448     * @internal 
    449449     *  
    450      * @param  mixed $class          The class name or instance of the class to get the related class name for 
    451      * @param  mixed $related_class  The related class/class name to get the record name of 
     450     * @param  string $class          The class to get the related class name for 
     451     * @param  string $related_class  The related class to get the record name of 
    452452     * @return string  The record name for the related class specified 
    453453     */ 
    454454    static public function getRelatedRecordName($class, $related_class, $route=NULL) 
    455455    { 
    456         $table = fORM::tablize($class); 
    457          
    458         $related_class = fORM::getClass($related_class); 
     456        $table         = fORM::tablize($class); 
    459457        $related_table = fORM::tablize($related_class); 
    460458         
     
    476474     * @internal 
    477475     *  
    478      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     476     * @param  string $class             The class to get link the related records to 
    479477     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
    480478     * @param  string $related_class     The related class to populate 
     
    551549    static public function overrideRelatedRecordName($class, $related_class, $record_name, $route=NULL) 
    552550    { 
    553         $table = fORM::tablize($class); 
    554          
     551        $class         = fORM::getClass($class); 
     552        $table         = fORM::tablize($class); 
    555553        $related_class = fORM::getClass($related_class); 
    556554        $related_table = fORM::tablize($related_class); 
     
    575573     * @internal 
    576574     *  
    577      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     575     * @param  string $class             The class to populate the related records of 
    578576     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
    579577     * @param  string $related_class     The related class to populate 
     
    583581    static public function populateRecords($class, &$related_records, $related_class, $route=NULL) 
    584582    { 
     583        $table           = fORM::tablize($class); 
    585584        $related_table   = fORM::tablize($related_class); 
    586585        $pk_columns      = fORMSchema::retrieve()->getKeys($related_table, 'primary'); 
     
    590589         
    591590            $first_pk_column = NULL; 
    592             $relationships   = fORMSchema::getRoutes($related_table, fORM::tablize($class), '*-to-one'); 
     591            $relationships   = fORMSchema::getRoutes($related_table, $table, '*-to-one'); 
    593592            foreach ($pk_columns as $pk_column) { 
    594593                foreach ($relationships as $relationship) { 
     
    652651     * @internal 
    653652     *  
    654      * @param  mixed   $class                 The class name or instance of the class this ordering rule applies to 
     653     * @param  string  $class                 The class to reflect the related record methods for 
    655654     * @param  array   &$signatures           The associative array of `{method_name} => {signature}` 
    656655     * @param  boolean $include_doc_comments  If the doc block comments for each method should be included 
     
    882881    static public function setOrderBys($class, $related_class, $order_bys, $route=NULL) 
    883882    { 
     883        $class         = fORM::getClass($class); 
    884884        $table         = fORM::tablize($class); 
    885885        $related_table = fORM::tablize($related_class); 
     
    904904     * @internal 
    905905     *  
    906      * @param  mixed   $class             The class name or instance of the class to get the related values for 
     906     * @param  string  $class             The class to set the related records count for 
    907907     * @param  array   &$values           The values for the fActiveRecord class 
    908908     * @param  array   &$related_records  The related records existing for the fActiveRecord class 
     
    942942     * @internal 
    943943     *  
    944      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     944     * @param  string $class             The class to set the related primary keys for 
    945945     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
    946946     * @param  string $related_class     The class we are setting the records for 
     
    975975     * @internal 
    976976     *  
    977      * @param  mixed  $class             The class name or instance of the class to get the related values for 
     977     * @param  string $class             The class to set the related records for 
    978978     * @param  array  &$related_records  The related records existing for the fActiveRecord class 
    979979     * @param  string $related_class     The class we are associating with the current record 
     
    10081008     * @internal 
    10091009     *  
    1010      * @param  mixed      $class             The class name or instance of the class to store the related records for 
    1011      * @param  array      &$values           The current values for the main record being stored 
    1012      * @param  array      &$related_records  The related records array 
     1010     * @param  string $class             The class to store the related records for 
     1011     * @param  array  &$values           The current values for the main record being stored 
     1012     * @param  array  &$related_records  The related records array 
    10131013     * @return void 
    10141014     */ 
     
    11561156     * @internal 
    11571157     *  
    1158      * @param  mixed      $class             The class name or instance of the class to validate the related records for 
    1159      * @param  array      &$related_records  The related records array 
     1158     * @param  string $class             The class to validate the related records for 
     1159     * @param  array  &$related_records  The related records array 
    11601160     * @return void 
    11611161     */ 
    11621162    static public function validate($class, &$related_records) 
    11631163    { 
    1164         $class = fORM::getClass($class); 
    11651164        $table = fORM::tablize($class); 
    11661165         
     
    11961195     * @internal 
    11971196     *  
    1198      * @param  mixed      $class          The class name or instance of the class these records are related to 
     1197     * @param  string     $class          The class to validate the related records for 
    11991198     * @param  string     $related_class  The name of the class for this record set 
    12001199     * @param  string     $route          The route between the table and related table 
     
    12541253     * @internal 
    12551254     *  
    1256      * @param  mixed      $class          The class name or instance of the class these records are related to 
     1255     * @param  string     $class          The class to validate the related records for 
    12571256     * @param  string     $related_class  The name of the class for this record set 
    12581257     * @param  string     $route          The route between the table and related table 
  • fORMSchema.php

    r562 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORMSchema 
    1111 *  
    12  * @version    1.0.0b2 
     12 * @version    1.0.0b3 
     13 * @changes    1.0.0b3  Added routes caching for performance [wb, 2009-06-15] 
    1314 * @changes    1.0.0b2  Backwards Compatiblity Break - removed ::enableSmartCaching(), fORM::enableSchemaCaching() now provides equivalent functionality [wb, 2009-05-04] 
    1415 * @changes    1.0.0b   The initial implementation [wb, 2007-06-14] 
     
    2728     
    2829    /** 
     30     * A cache for computed information 
     31     *  
     32     * @var array 
     33     */ 
     34    static private $cache = array( 
     35        'getRoutes' => array() 
     36    ); 
     37     
     38     
     39    /** 
    2940     * The schema object to use for all ORM functionality 
    3041     *  
     
    204215    static public function getRoutes($table, $related_table, $relationship_type=NULL) 
    205216    { 
     217        $key = $table . '::' . $related_table . '::' . $relationship_type; 
     218        if (isset(self::$cache['getRoutes'][$key])) { 
     219            return self::$cache['getRoutes'][$key];  
     220        } 
     221         
    206222        $valid_relationship_types = array( 
    207223            NULL, 
     
    249265        } 
    250266         
     267        self::$cache['getRoutes'][$key] = $routes; 
     268         
    251269        return $routes; 
    252270    } 
  • fORMValidation.php

    r598 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fORMValidation 
    1111 *  
    12  * @version    1.0.0b8 
     12 * @version    1.0.0b9 
     13 * @changes    1.0.0b9  Updated code for new fORM API [wb, 2009-06-15] 
    1314 * @changes    1.0.0b8  Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]   
    1415 * @changes    1.0.0b7  Updated ::validateRelated() to use new fORMRelated::validate() method and ::checkRelatedOneOrMoreRule() to use new `$related_records` structure [wb, 2009-06-02] 
     
    230231    static private function checkAgainstSchema($object, $column, &$values, &$old_values) 
    231232    { 
    232         $class = fORM::getClass($object); 
     233        $class = get_class($object); 
    233234        $table = fORM::tablize($class); 
    234235         
     
    282283     * Validates against a conditional validation rule 
    283284     * 
    284      * @param  mixed  $class                The class name or instance of the class this validation rule applies to 
     285     * @param  string $class                The class this validation rule applies to 
    285286     * @param  array  &$values              An associative array of all values for the record 
    286287     * @param  string $main_column          The column to check for a value 
     
    316317     * Validates a value against the database data type 
    317318     * 
    318      * @param  mixed  $class   The class name or instance of the class the column is part of 
     319     * @param  string $class   The class the column is part of 
    319320     * @param  string $column  The column to check 
    320321     * @param  mixed  $value   The value to check 
     
    387388     * Validates values against foreign key constraints 
    388389     * 
    389      * @param  mixed  $class    The class name or instance of the class to check the foreign keys for 
     390     * @param  string $class    The class to check the foreign keys for 
    390391     * @param  string $column   The column to check 
    391392     * @param  array  &$values  The values to check 
     
    426427     * Validates against a one-or-more validation rule 
    427428     * 
    428      * @param  mixed  $class    The class name or instance of the class the columns are part of 
     429     * @param  string $class    The class the columns are part of 
    429430     * @param  array  &$values  An associative array of all values for the record 
    430431     * @param  array  $columns  The columns to check 
     
    458459     * Validates against an only-one validation rule 
    459460     * 
    460      * @param  mixed  $class    The class name or instance of the class the columns are part of 
     461     * @param  string $class    The class the columns are part of 
    461462     * @param  array  &$values  An associative array of all values for the record 
    462463     * @param  array  $columns  The columns to check 
     
    504505    static private function checkPrimaryKeys($object, &$values, &$old_values) 
    505506    { 
    506         $class = fORM::getClass($object); 
     507        $class = get_class($object); 
    507508        $table = fORM::tablize($class); 
    508509         
     
    570571     * Validates against a *-to-many one or more validation rule 
    571572     * 
    572      * @param  mixed  $class             The class name or instance of the class we are checking 
     573     * @param  string $class             The class we are checking 
    573574     * @param  array  &$related_records  The related records array to check 
    574575     * @param  string $related_class     The name of the related class 
     
    604605    static private function checkUniqueConstraints($object, $column, &$values, &$old_values) 
    605606    { 
    606         $class = fORM::getClass($object); 
     607        $class = get_class($object); 
    607608        $table = fORM::tablize($class); 
    608609         
     
    700701     * @internal 
    701702     *  
    702      * @param  mixed  $class  The class name or an instance of the class to initilize the arrays for 
     703     * @param  string $class  The class to initilize the arrays for 
    703704     * @return void 
    704705     */ 
     
    717718     * @internal 
    718719     *  
    719      * @param  mixed $class   The class to check 
     720     * @param  string $class   The class to check 
    720721     * @param  string $column  The column to check 
    721722     * @return boolean  If the column is set to be case insensitive 
     
    723724    static private function isCaseInsensitive($class, $column) 
    724725    { 
    725         if (!isset(self::$case_insensitive_columns[$class][$column])) { 
    726             return FALSE; 
    727         }    
    728         return TRUE; 
     726        return isset(self::$case_insensitive_columns[$class][$column]); 
    729727    } 
    730728     
     
    735733     * @internal 
    736734     *  
    737      * @param  mixed $class                 The class name or an instance of the class to reorder messages for 
    738      * @param  array &$validation_messages  An array of one validation message per value 
     735     * @param  string $class                 The class to reorder messages for 
     736     * @param  array &$validation_messages  An array of one validation message per value 
    739737     * @return void 
    740738     */ 
    741739    static public function reorderMessages($class, &$validation_messages) 
    742740    { 
    743         $class = fORM::getClass($class); 
    744          
    745741        if (!isset(self::$message_orders[$class])) { 
    746742            return; 
     
    882878    static public function validate($object, $values, $old_values) 
    883879    { 
    884         $class = fORM::getClass($object); 
     880        $class = get_class($object); 
    885881        $table = fORM::tablize($class); 
    886882         
     
    932928     * @internal 
    933929     *  
    934      * @param  mixed $class             The class name or instance of the class to validate 
    935      * @param  array &$related_records  The related records to validate 
     930     * @param  string $class             The class to validate 
     931     * @param  array &$related_records  The related records to validate 
    936932     * @return array  An array of validation messages 
    937933     */ 
    938934    static public function validateRelated($class, &$related_records) 
    939935    { 
    940         $class = fORM::getClass($class); 
    941936        $table = fORM::tablize($class); 
    942937         
  • fSchema.php

    r597 r603 Hide Line Numbers
    1010 * @link       http://flourishlib.com/fSchema 
    1111 *  
    12  * @version    1.0.0b19 
     12 * @version    1.0.0b20 
     13 * @changes    1.0.0b20  Add caching of merged info, improved performance of ::getColumnInfo() [wb, 2009-06-15] 
    1314 * @changes    1.0.0b19  Fixed a couple of bugs with ::setKeysOverride() [wb, 2009-06-04] 
    1415 * @changes    1.0.0b18  Added missing support for MySQL mediumint columns [wb, 2009-05-18] 
     
    176177            $this->cache->delete($prefix . 'databases'); 
    177178            $this->cache->delete($prefix . 'keys'); 
     179            $this->cache->delete($prefix . 'merged_column_info'); 
     180            $this->cache->delete($prefix . 'merged_keys'); 
     181            $this->cache->delete($prefix . 'relationships'); 
    178182            $this->cache->delete($prefix . 'tables'); 
    179183        } 
     
    192196         
    193197        $prefix = $this->makeCachePrefix(); 
    194         $this->column_info = $this->cache->get($prefix . 'column_info', array()); 
    195         $this->databases   = $this->cache->get($prefix . 'databases',   NULL); 
    196         $this->keys        = $this->cache->get($prefix . 'keys',        array()); 
    197         $this->tables      = $this->cache->get($prefix . 'tables',      NULL); 
     198        $this->column_info        = $this->cache->get($prefix . 'column_info',          array()); 
     199        $this->databases          = $this->cache->get($prefix . 'databases',            NULL); 
     200        $this->keys               = $this->cache->get($prefix . 'keys',                 array()); 
     201         
     202        if (!$this->column_info_override && !$this->keys_override) { 
     203            $this->merged_column_info = $this->cache->get($prefix . 'merged_column_info',   array()); 
     204            $this->merged_keys        = $this->cache->get($prefix . 'merged_keys',          array());   
     205            $this->relationships      = $this->cache->get($prefix . 'relationships',        array()); 
     206        } 
     207         
     208        $this->tables             = $this->cache->get($prefix . 'tables',               NULL);    
    198209    } 
    199210     
     
    17141725            $this->findOneToManyRelationships($table); 
    17151726        } 
     1727         
     1728        if ($this->cache) { 
     1729            $this->cache->set($this->makeCachePrefix() . 'relationships', $this->relationships);     
     1730        } 
    17161731    } 
    17171732     
     
    17721787    public function getColumnInfo($table, $column=NULL, $element=NULL) 
    17731788    { 
    1774         $valid_elements = array('type', 'not_null', 'default', 'valid_values', 'max_length', 'decimal_places', 'auto_increment'); 
    1775         if ($element && !in_array($element, $valid_elements)) { 
    1776             throw new fProgrammerException( 
    1777                 'The element specified, %1$s, is invalid. Must be one of: %2$s.', 
    1778                 $element, 
    1779                 join(', ', $valid_elements) 
    1780             ); 
     1789        // Return the saved column info if possible 
     1790        if (!$column && isset($this->merged_column_info[$table])) { 
     1791            return $this->merged_column_info[$table]; 
     1792        } 
     1793        if ($column && isset($this->merged_column_info[$table][$column])) { 
     1794            if ($element !== NULL) { 
     1795                if (!isset($this->merged_column_info[$table][$column][$element]) && !array_key_exists($element, $this->merged_column_info[$table][$column])) { 
     1796                    throw new fProgrammerException( 
     1797                        'The element specified, %1$s, is invalid. Must be one of: %2$s.', 
     1798                        $element, 
     1799                        join(', ', array('type', 'not_null', 'default', 'valid_values', 'max_length', 'decimal_places', 'auto_increment')) 
     1800                    );   
     1801                } 
     1802                return $this->merged_column_info[$table][$column][$element]; 
     1803            } 
     1804            return $this->merged_column_info[$table][$column]; 
    17811805        } 
    17821806         
     
    17861810                $table 
    17871811            ); 
    1788         } 
    1789          
    1790         // Return the saved column info if possible 
    1791         if (!$column && isset($this->merged_column_info[$table])) { 
    1792             return $this->merged_column_info[$table]; 
    1793         } 
    1794         if ($column && isset($this->merged_column_info[$table][$column])) { 
    1795             if ($element !== NULL) { 
    1796                 return $this->merged_column_info[$table][$column][$element]; 
    1797             } 
    1798             return $this->merged_column_info[$table][$column]; 
    17991812        } 
    18001813         
     
    22182231            } 
    22192232        } 
     2233         
     2234        if ($this->cache) { 
     2235            $this->cache->set($this->makeCachePrefix() . 'merged_column_info', $this->merged_column_info);   
     2236        } 
    22202237    } 
    22212238         
     
    22362253            } 
    22372254            $this->merged_keys[$table] = array_merge($this->merged_keys[$table], $info); 
     2255        } 
     2256         
     2257        if ($this->cache) { 
     2258            $this->cache->set($this->makeCachePrefix() . 'merged_keys', $this->merged_keys);     
    22382259        } 
    22392260