Changeset 908

Show
Ignore:
Timestamp:
10/28/2007 04:46:51 AM (13 months ago)
Author:
Geert
Message:

Small changes:

  • Optimized filetype regex in the constructor by applying non-capturing parentheses and letting substr() pull out the leading dot
  • Fixed bug in get() that would not return empty view variables like int(0)
  • Converted comments
Files:
1 modified

Legend:

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

    r892 r908  
    2323 
    2424        // The view file name and type 
    25         protected $kohana_filename  = FALSE; 
    26         protected $kohana_filetype  = FALSE; 
     25        protected $kohana_filename = FALSE; 
     26        protected $kohana_filetype = FALSE; 
    2727 
    2828        // Set variables 
    2929        protected $data = array(); 
    3030 
    31         /** 
    32          * Construct 
     31        /* 
     32         * Method: __construct 
     33         * 
     34         * Parameters: 
     35         *  name - view filename string 
     36         *  data - view data 
    3337         */ 
    3438        public function __construct($name, $data = NULL) 
    3539        { 
    36                 if (preg_match('/\.(gif|jpe?g|png|tiff?|js|css|swf)$/Di', $name, $type)) 
     40                if (preg_match('/\.(?:gif|jpe?g|png|css|js|tiff?|swf)$/Di', $name, $type)) 
    3741                { 
    38                         $type = $type[1]; 
     42                        $type = substr($type[0], 1); 
    3943 
    4044                        $this->kohana_filename = Kohana::find_file('views', $name, TRUE, $type); 
     
    5357                if (is_array($data) AND ! empty($data)) 
    5458                { 
    55                         foreach($data as $key => $val) 
     59                        foreach($data as $name => $value) 
    5660                        { 
    57                                 $this->data[$key] = $val; 
     61                                $this->data[$name] = $value; 
    5862                        } 
    5963                } 
     
    6266        } 
    6367 
    64         /** 
    65          * Set a variable 
     68        /* 
     69         * Method: set 
     70         *  Sets a view variable 
    6671         * 
    67          * @access public 
    68          * @param  string 
    69          * @param  mixed 
    70          * @return object 
     72         * Parameters: 
     73         *  name  - variable name 
     74         *  value - variable contents 
     75         *  
     76         * Returns: 
     77         *  View object 
    7178         */ 
    7279        public function set($name, $value) 
     
    7683        } 
    7784 
    78         /** 
    79          * Magic setting of a variable 
     85        /* 
     86         * Method: __set 
     87         *  Magically sets a view variable 
    8088         * 
    81          * @access public 
    82          * @param  string 
    83          * @param  mixed 
    84          * @return void 
     89         * Parameters: 
     90         *  name  - variable name 
     91         *  value - variable contents 
    8592         */ 
    8693        public function __set($name, $value) 
     
    9299        } 
    93100 
    94         /** 
    95          * Magic getting of a variable 
     101        /* 
     102         * Method: __get 
     103         *  Magically gets a view variable 
    96104         * 
    97          * @access public 
    98          * @param  string 
    99          * @return void 
     105         * Parameters: 
     106         *  name - variable name 
     107         *  
     108         * Returns: 
     109         *  The variable contents or NULL if the variable does not exist 
    100110         */ 
    101111        public function __get($name) 
    102112        { 
    103                 return empty($this->data[$name]) ? NULL : $this->data[$name]; 
     113                return isset($this->data[$name]) ? $this->data[$name] : NULL; 
    104114        } 
    105115 
    106         /** 
    107          * Magic object to string 
     116        /* 
     117         * Method: __toString 
     118         *  Magically converts view object to string 
    108119         * 
    109          * @access public 
    110          * @param  string 
    111          * @param  mixed 
    112          * @return void 
     120         * Returns: 
     121         *  The rendered view 
    113122         */ 
    114123        public function __toString() 
     
    117126        } 
    118127 
    119         /** 
    120          * Render a view 
     128        /* 
     129         * Method: render 
     130         *  Renders a view 
    121131         * 
    122          * @access public 
    123          * @param  string 
    124          * @param  callback 
    125          * @return mixed 
     132         * Parameters: 
     133         *  print    - echo the output instead of returning it 
     134         *  renderer - user defined renderer callback 
     135         *  
     136         * Returns: 
     137         *  The rendered view if print is set to FALSE 
    126138         */ 
    127139        public function render($print = FALSE, $renderer = FALSE) 
     
    147159                else 
    148160                { 
    149                         // Send the filetype header 
     161                        // Overwrite the content-type header 
    150162                        header('Content-type: '.$this->kohana_filetype); 
    151163