Changeset 2935

Show
Ignore:
Timestamp:
06/29/2008 01:26:22 PM (5 months ago)
Author:
Geert
Message:

Pagination groups are now supplied as part of the config array instead of a separate first parameter. Cleaner API. Also allows for initialize() to set/overwrite group name.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Pagination.php

    r2723 r2935  
    3838         * Constructs and returns a new Pagination object. 
    3939         * 
    40          * @param   string  configuration group name 
    41          * @param   array   configuration items that overwrite group defaults 
     40         * @param   array   configuration settings 
    4241         * @return  object 
    4342         */ 
    44         public function factory($group = NULL, $config = array()) 
    45         { 
    46                 return new Pagination($group, $config); 
     43        public function factory($config = array()) 
     44        { 
     45                return new Pagination($config); 
    4746        } 
    4847 
     
    5049         * Constructs the Pagination object. 
    5150         * 
    52          * @param   string  configuration group name 
    53          * @param   array   configuration items that overwrite group defaults 
     51         * @param   array  configuration settings 
    5452         * @return  void 
    5553         */ 
    56         public function __construct($group = NULL, $config = array()) 
    57         { 
    58                 // No group name given, only array with custom config items 
    59                 // Allows for backward compatibility as well 
    60                 if (is_array($group)) 
    61                 { 
    62                         $config = $group; 
    63                         $group = 'default'; 
    64                 } 
    65                 // Use default group 
    66                 elseif ($group === NULL) 
    67                 { 
    68                         $group = 'default'; 
    69                 } 
    70  
    71                 // Load and validate config group 
    72                 if ( ! is_array($group_config = Config::item('pagination.'.$group))) 
    73                         throw new Kohana_Exception('pagination.undefined_group', $group); 
    74  
    75                 // All pagination config groups inherit default config group 
    76                 if ($group !== 'default') 
    77                 { 
    78                         // Load and validate default config group 
    79                         if ( ! is_array($default_config = Config::item('pagination.default'))) 
    80                                 throw new Kohana_Exception('pagination.undefined_group', 'default'); 
    81  
    82                         // Merge config group with default config group 
    83                         $group_config += $default_config; 
    84                 } 
    85  
    86                 // Merge custom config items with config group 
    87                 $config += $group_config; 
     54        public function __construct($config = array()) 
     55        { 
     56                // No custom group name given 
     57                if ( ! isset($config['group'])) 
     58                { 
     59                        $config['group'] = 'default'; 
     60                } 
    8861 
    8962                // Pagination setup 
     
    9467 
    9568        /** 
    96          * Sets or overwrites (some) config values. 
    97          * 
    98          * @param   array  configuration 
     69         * Sets config values. 
     70         * 
     71         * @param   array  configuration settings 
    9972         * @return  void 
    10073         */ 
    10174        public function initialize($config = array()) 
    10275        { 
     76                // Load config group 
     77                if (isset($config['group'])) 
     78                { 
     79                        // Load and validate config group 
     80                        if ( ! is_array($group_config = Config::item('pagination.'.$config['group']))) 
     81                                throw new Kohana_Exception('pagination.undefined_group', $config['group']); 
     82 
     83                        // All pagination config groups inherit default config group 
     84                        if ($config['group'] !== 'default') 
     85                        { 
     86                                // Load and validate default config group 
     87                                if ( ! is_array($default_config = Config::item('pagination.default'))) 
     88                                        throw new Kohana_Exception('pagination.undefined_group', 'default'); 
     89 
     90                                // Merge config group with default config group 
     91                                $group_config += $default_config; 
     92                        } 
     93 
     94                        // Merge custom config items with config group 
     95                        $config += $group_config; 
     96                } 
     97 
    10398                // Assign config values to the object 
    10499                foreach ($config as $key => $value)