Changeset 1168

Show
Ignore:
Timestamp:
11/18/07 03:13:52 (10 months ago)
Author:
Shadowhand
Message:

Batch of core changes:

  • Added a configuration file for profiler, to enable/disable specific profiler information
  • Implemented configuration handling in Profiler and views/kohana_profiler.php
  • Added system/models/form.php and views/kohana_form.php, see: http://kohanaphp.com/tutorials/quick_forms.html
  • text::random('unique') now uses sha1, instead of md5
  • Added a couple of missing connect() calls in Database
  • Added Database::list_fields() and Database_Mysql::list_fields()
  • Fixed Database_Mysql::escape_table()
  • Changed Loader::helper() to just do a Log::add('debug') instead of actually loading the helper
  • Updated some comment styles to prepare for Kodoc

Location:
trunk/system
Files:
4 added
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/core/Benchmark.php

    r939 r1168  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
    3  * Class: Benchmark 
    4  *  Simple benchmarking. 
     2/** 
     3 * Simple benchmarking. 
    54 * 
    65 * Kohana Source Code: 
  • trunk/system/core/Kohana.php

    r1121 r1168  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * Class: Kohana 
    44 *  Provides Kohana-specific helper functions. This is where the magic happens! 
     
    420420    } 
    421421 
    422     /* 
     422    /** 
    423423     * Method: show_error 
    424424     *  Show a custom error message 
     
    437437    } 
    438438 
    439     /* 
     439    /** 
    440440     * Method: auto_load 
    441441     *  Provides class auto-loading 
     
    500500    } 
    501501 
    502     /* 
     502    /** 
    503503     * Method: find_file 
    504504     *  Find a resource file in a given directory 
     
    563563    } 
    564564 
    565     /* 
     565    /** 
    566566     * Method: list_files 
    567567     *  Lists all files and directories in a resource path 
     
    570570     *  directory - directory to search 
    571571     *  recursive - list all files to the maximum depth? 
    572     *  path      - full path to search (used for recursion, *never* set this manually) 
     572    *  path      - full path to search (used for recursion, *never* set this manually) 
    573573     */ 
    574574    public static function list_files($directory, $recursive = FALSE, $path = FALSE) 
  • trunk/system/helpers/text.php

    r936 r1168  
    104104     * 
    105105     * Default Types: 
    106      *  unique  - a 32 character unique hash 
     106     *  unique  - 40 character unique hash 
    107107     *  alnum   - alpha-numeric characters 
    108108     *  alpha   - alphabetical characters 
     
    118118        { 
    119119            case 'unique': 
    120                 return md5(uniqid(mt_rand())); 
    121             case '': 
     120                return sha1(uniqid(NULL, TRUE)); 
    122121            case 'alnum': 
    123122                $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; 
  • trunk/system/libraries/Database.php

    r1166 r1168  
    728728            $table = $this->from[0]; 
    729729        } 
    730         $sql = $this->driver->update($this->config['table_prefix'].$table, $this->set, $this->where); 
     730 
     731        $table = $this->driver->escape_table($this->config['table_prefix'].$table); 
     732 
     733        $sql = $this->driver->update($table, $this->set, $this->where); 
    731734 
    732735        $this->reset_write(); 
     
    862865    public function list_tables() 
    863866    { 
    864         $this->link OR $this->driver->connect(); 
     867        $this->link or $this->connect(); 
    865868 
    866869        $this->reset_select(); 
     
    928931    public function field_data($table ='') 
    929932    { 
     933        $this->link or $this->connect(); 
     934 
    930935        return $this->driver->field_data($table); 
     936    } 
     937 
     938    /* 
     939     * Method: list_fields 
     940     *  Get the field data for a database table, along with the field's attributes. 
     941     * 
     942     * Parameters: 
     943     *  table - table name 
     944     * 
     945     * Returns: 
     946     *  Array containing the field data 
     947     */ 
     948    public function list_fields($table ='') 
     949    { 
     950        $this->link or $this->connect(); 
     951 
     952        return $this->driver->list_fields($table); 
    931953    } 
    932954 
  • trunk/system/libraries/Loader.php

    r1015 r1168  
    109109    public function helper($name) 
    110110    { 
    111         // Allow recursive loading 
    112         if (is_array($name)) 
    113         { 
    114             $helpers = $name; 
    115  
    116             foreach($helpers as $name) 
    117             { 
    118                 $this->helper($name); 
    119             } 
    120         } 
    121         else 
    122         { 
    123             include Kohana::find_file('helpers', $name, TRUE); 
    124         } 
     111        // Just don't do this... there's no point. 
     112        Log::add('debug', 'Using $this->load->helper() is deprecated. See Kohana::auto_load().'); 
    125113    } 
    126114 
     
    158146        $model = new $class(); 
    159147 
     148        // Return the model 
    160149        if ($alias === TRUE) 
    161150            return $model; 
  • trunk/system/libraries/Profiler.php

    r1123 r1168  
    5252    public function render($return = FALSE) 
    5353    { 
    54         $data = array 
    55         ( 
    56             'benchmarks' => array(), 
    57             'queries'    => FALSE 
    58         ); 
     54        if (Config::item('profiler.benchmarks')) 
     55        { 
     56            // Clean unique id from system benchmark names 
     57            foreach (Benchmark::get(TRUE) as $name => $time) 
     58            { 
     59                $data['benchmarks'][str_replace(SYSTEM_BENCHMARK.'_', '', $name)] = $time; 
     60            } 
     61        } 
    5962 
    6063        // Load database benchmarks, if Database has been loaded 
    61         if (class_exists('Database', FALSE)) 
     64        if (Config::item('profiler.database') AND class_exists('Database', FALSE)) 
    6265        { 
    6366            $data['queries'] = Database::$benchmarks; 
    6467        } 
    6568 
    66         // Clean unique id from system benchmark names 
    67         foreach (Benchmark::get(TRUE) as $name => $time) 
     69        // Load POST data 
     70        if (Config::item('profiler.post')) 
    6871        { 
    69             $data['benchmarks'][str_replace(SYSTEM_BENCHMARK.'_', '', $name)] = $time; 
     72            $data['post'] = TRUE; 
     73        } 
     74 
     75        if (Config::item('profiler.session')) 
     76        { 
     77            $data['session'] = TRUE; 
    7078        } 
    7179 
  • trunk/system/libraries/drivers/Database_Mysql.php

    r1166 r1168  
    8282    public function escape_table($table) 
    8383    { 
    84         return str_replace('.', '`.`', $table); 
     84        return '`'.str_replace('.', '`.`', $table).'`'; 
    8585    } 
    8686 
     
    316316    } 
    317317 
     318    public function list_fields($table) 
     319    { 
     320        $query = mysql_query('DESCRIBE '.$this->escape_table($table), $this->link); 
     321 
     322        $fields = array(); 
     323        while ($row = mysql_fetch_object($query)) 
     324        { 
     325            $fields[] = $row->Field; 
     326        } 
     327        return $fields; 
     328    } 
     329 
    318330    public function field_data($table) 
    319331    { 
  • trunk/system/views/kohana_profiler.php

    r1114 r1168  
    8282<div id="kohana-profiler"> 
    8383 
     84<?php if (isset($benchmarks)): ?> 
    8485    <table id="kp-benchmarks"> 
    8586        <tr> 
     
    109110?> 
    110111    </table> 
    111  
     112<?php endif; ?> 
     113 
     114<?php if (isset($queries)): ?> 
    112115    <table id="kp-queries"> 
    113116        <tr> 
     
    150153?> 
    151154    </table> 
    152  
     155<?php endif; ?> 
     156 
     157<?php if (isset($post)): ?> 
    153158    <table id="kp-postdata"> 
    154159        <tr> 
     
    181186?> 
    182187    </table> 
    183  
     188<?php endif; ?> 
     189 
     190<?php if (isset($session)): ?> 
    184191    <table id="kp-sessiondata"> 
    185192        <tr> 
     
    212219?> 
    213220    </table> 
     221<?php endif; ?> 
    214222 
    215223</div>