Changeset 2344

Show
Ignore:
Timestamp:
03/25/2008 09:21:45 AM (8 months ago)
Author:
Geert
Message:

Added prep_url() method to Validation

Files:
1 modified

Legend:

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

    r2334 r2344  
    138138        public function pre_filter($filter, $field = TRUE) 
    139139        { 
     140                if (method_exists($this, $filter)) 
     141                { 
     142                        // Make the filter a valid callback 
     143                        $filter = array($this, $filter); 
     144                } 
     145 
    140146                if ( ! is_callable($filter)) 
    141147                        throw new Kohana_Exception('validation.filter_not_callable'); 
     
    174180        public function post_filter($filter, $field = TRUE) 
    175181        { 
     182                if (method_exists($this, $filter)) 
     183                { 
     184                        // Make the filter a valid callback 
     185                        $filter = array($this, $filter); 
     186                } 
     187 
    176188                if ( ! is_callable($filter, TRUE)) 
    177189                        throw new Kohana_Exception('validation.filter_not_callable'); 
     
    587599        } 
    588600 
     601        /** 
     602         * Filter: prep_url. Prepares a URL for valid::url(). 
     603         * 
     604         * @param   string  possibly incomplete URL 
     605         * @return  string 
     606         */ 
     607        public function prep_url($str = '') 
     608        { 
     609                if ($str === '' OR $str === 'http://' OR $str === 'https://') 
     610                        return ''; 
     611 
     612                if (substr($str, 0, 7) !== 'http://' AND substr($str, 0, 8) !== 'https://') 
     613                        return 'http://'.$str; 
     614        } 
     615 
    589616} // End Validation