Changeset 1230

Show
Ignore:
Timestamp:
11/21/07 15:02:03 (9 months ago)
Author:
Shadowhand
Message:

Changes to core:

  • Updated Kodoc with a slightly more complete usage.
  • Updated all files with /** instead of /* to start comment blocks (required for Reflection)
Location:
trunk
Files:
1 added
82 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/config/config.php

    r1087 r1230  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * File: config.php 
    44 *  This configuration file is unique to every application. 
     
    2020    'site_protocol'        => 'http', 
    2121    'index_page'           => 'index.php', 
    22     'url_suffix'           => '.html', 
    23     'allow_config_set'     => FALSE, 
     22    'url_suffix'           => '', 
     23    'allow_config_set'     => TRUE, 
    2424    'global_xss_filtering' => FALSE, 
    2525    'extension_prefix'     => 'MY_', 
    2626    'include_paths'        => array 
    2727    ( 
     28        // 'modules/auth', 
     29        // 'modules/ikeafans', 
     30        // 'modules/user_guide', 
     31        // 'modules/orm', 
     32        'modules/kodoc', 
     33        // 'modules/mixnotify' 
    2834    ), 
    2935    'autoload'             => array 
  • trunk/application/controllers/examples.php

    r1104 r1230  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * Class: Examples 
    44 *  Contains examples of various Kohana library examples. You can access these 
     
    1212class Examples_Controller extends Controller { 
    1313 
    14     /* 
     14    /** 
    1515     * Method: index 
    1616     *  Displays a list of available examples 
     
    4040    } 
    4141 
    42     /* 
     42    /** 
    4343     * Method: template 
    4444     *  Demonstrates how to use views inside of views. 
     
    5959    } 
    6060 
    61     /* 
     61    /** 
    6262     * Method: rss 
    6363     *  Demonstrates how to parse RSS feeds by using DOMDocument. 
     
    7474    } 
    7575 
    76     /* 
     76    /** 
    7777     * Method: session 
    7878     *  Demonstrates the Session library and using session data. 
     
    9090    } 
    9191 
    92     /* 
     92    /** 
    9393     * Method: form 
    9494     *  Demonstrates how to use the form helper with the Validation library. 
     
    101101 
    102102        print form::label('imageup', 'Image Uploads').':<br/>'; 
    103         print form::upload('imageup').'<br/>'; 
    104         // print form::upload('imageup[]').'<br/>'; 
    105         // print form::upload('imageup[]').'<br/>'; 
     103        print form::upload('imageup[]').'<br/>'; 
     104        print form::upload('imageup[]').'<br/>'; 
     105        print form::upload('imageup[]').'<br/>'; 
    106106        print form::submit('upload', 'Upload!'); 
    107107 
     
    118118    } 
    119119 
    120     /* 
     120    /** 
    121121     * Method: validation 
    122122     *  Demontrates how to use the Validation library to validate an arbitrary array. 
     
    142142            // Format: 
    143143            // key          friendly name,  validation rules 
    144             'user' => array('username',    'trim|required[1,2]'), 
     144            'user' => array('username',    'trim|required[1,12]|regex[[0-9]+]'), 
    145145            'pass' => array('password',    'required|sha1'), 
    146146            'reme' => array('remember me', 'required') 
     
    151151 
    152152        // Same syntax, but dynamcially generated wth __get() 
    153         print $this->validation->user_error; 
     153        print $this->validation->error_string; 
    154154 
    155155        // Yay! 
     
    157157    } 
    158158 
    159     /* 
     159    /** 
    160160     * Method: database 
    161161     *  Demonstrates the features of the Database library. 
     
    236236    } 
    237237 
    238     /* 
     238    /** 
    239239     * Method: pagination 
    240240     *  Demonstrates how to use the Pagination library and Pagination styles. 
     
    263263    } 
    264264 
    265     /* 
     265    /** 
    266266     * Method: user_agent 
    267267     *  Demonstrates the User_Agent library. 
     
    280280    } 
    281281 
    282     /* 
     282    /** 
    283283     * Method: credit_card 
    284284     *  Demonstrates the CreditCard library. 
  • trunk/application/controllers/welcome.php

    r870 r1230  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * Class: Welcome 
    44 *  Default Kohana controller. 
  • trunk/index.php

    r893 r1230  
    11<?php 
    2 /* 
     2/** 
    33 * File: index.php 
    44 *  This file acts as the "front controller" to your application. You can 
     
    1717 */ 
    1818 
    19 /* 
     19/** 
    2020 * About: Error Reporting 
    2121 *  Set the error reporting level. By default, Kohana will ignore E_NOTICE 
     
    2525error_reporting(E_ALL); 
    2626 
    27 /* 
     27/** 
    2828 * About: Display Errors 
    2929 *  Enable or disable error display. During development, it is very helpful 
     
    3434ini_set('display_errors', TRUE); 
    3535 
    36 /* 
     36/** 
    3737 * About: Application Directory 
    3838 *  Kohana website application directory. Most of your controllers, models, and 
     
    4242$kohana_application = 'application'; 
    4343 
    44 /* 
     44/** 
    4545 * About: System Directory 
    4646 *  Kohana core resources, includes libraries, drivers, language files, helpers, 
     
    4949$kohana_system = 'system'; 
    5050 
    51 /* 
     51/** 
    5252 * About: Filename Extension 
    5353 *  If you have to rename all of the .php files distributed with Kohana to a 
     
    5757define('EXT', '.php'); 
    5858 
    59 /* 
     59/** 
    6060 * PLEASE DO NOT EDIT BELOW THIS LINE, unless you understand the repercussions! 
    6161 * ---------------------------------------------------------------------------- 
  • trunk/modules/auth/libraries/Auth.php

    r1169 r1230  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * Class: Auth 
    44 * 
     
    3333    } 
    3434 
    35     /* 
     35    /** 
    3636     * Method: login 
    3737     *  Attempt a user login. 
     
    7676    } 
    7777 
    78     /* 
     78    /** 
    7979     * Method: logout 
    8080     *  Force a logout of a user. 
     
    9595    } 
    9696 
    97     /* 
     97    /** 
    9898     * Creates a hashed password from a plaintext password, inserting salt 
    9999     * based on the configured salt pattern. 
     
    144144    } 
    145145 
    146     /* 
     146    /** 
    147147     * Perform a hash, using the configured method. 
    148148     * 
     
    158158    } 
    159159 
    160     /* 
     160    /** 
    161161     * Finds the salt from a password, based on the configured salt pattern. 
    162162     * 
  • trunk/modules/kodoc/controllers/kodoc.php

    r1124 r1230  
    55    public function index() 
    66    { 
    7         $kodoc = new Kodoc(); 
    8         print "Data: ".Kohana::debug($kodoc->get_docs()); 
     7        print new View('kodoc_menu'); 
     8    } 
     9 
     10    public function _default() 
     11    { 
     12        if (count($segments = $this->uri->segment_array(1)) > 1) 
     13        { 
     14            // Find directory (type) and filename 
     15            $type = array_shift($segments); 
     16            $file = implode('/', $segments); 
     17 
     18            if (substr($file, -(strlen(EXT))) === EXT) 
     19            { 
     20                // Remove extension 
     21                $file = substr($file, 0, -(strlen(EXT))); 
     22            } 
     23 
     24            // Get absolute path to file 
     25            $file = Kohana::find_file($type, $file); 
     26        } 
     27        else 
     28        { 
     29            // Nothing to document 
     30            url::redirect('kodoc'); 
     31        } 
     32 
     33        if (in_array($type, Kodoc::get_types())); 
     34        { 
     35            $docs = new Kodoc($type, $file); 
     36            print "Debug for $file: ".Kohana::debug($docs->get()); 
     37        } 
     38 
    939        print Kohana::lang('core.stats_footer'); 
    1040    } 
  • trunk/modules/kodoc/libraries/Kodoc.php

    r1124 r1230  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    2 /* 
     2/** 
    33 * Provides self-generating documentation about Kohana. 
    44 * 
     
    1010class Kodoc_Core { 
    1111 
    12     protected $types = array 
     12    protected static $types = array 
    1313    ( 
    1414        'core', 
     
    2020    ); 
    2121 
     22    public static function get_types() 
     23    { 
     24        return self::$types; 
     25    } 
     26 
     27    public static function get_files() 
     28    { 
     29        // Extension length 
     30        $ext_len = -(strlen(EXT)); 
     31 
     32        $files = array(); 
     33        foreach(self::$types as $type) 
     34        { 
     35            $files[$type] = array(); 
     36            foreach(Kohana::list_files($type, TRUE) as $file) 
     37            { 
     38                // Not a source file 
     39                if (substr($file, $ext_len) !== EXT) 
     40                    continue; 
     41 
     42                // Remove the dirs from the filename 
     43                $file = preg_replace('!^.+'.$type.'/(.+)'.EXT.'$!', '$1', $file); 
     44 
     45                if ($type === 'libraries' AND substr($file, 0, 8) === 'drivers/') 
     46                { 
     47                    // Remove the drivers directory from the file 
     48                    $file = explode('_', substr($file, 8)); 
     49 
     50                    if (count($file) === 1) 
     51                    { 
     52                        // Driver interface 
     53                        $files[$type][current($file)][] = current($file); 
     54                    } 
     55                    else 
     56                    { 
     57                        // Driver is class suffix 
     58                        $driver = array_pop($file); 
     59 
     60                        // Library is everything else 
     61                        $library = implode('_', $file); 
     62 
     63                        // Library driver 
     64                        $files[$type][$library][] = $driver; 
     65                    } 
     66                } 
     67                else 
     68                { 
     69                    $files[$type][$file] = NULL; 
     70                } 
     71            } 
     72        } 
     73 
     74        return $files; 
     75    } 
     76 
     77    public static function remove_docroot($file) 
     78    { 
     79        return preg_replace('!^'.preg_quote(DOCROOT, '!').'!', '', $file); 
     80    } 
     81 
    2282    // All files to be parsed 
    23     protected $files = array(); 
    24  
    25     public function __construct() 
    26     { 
    27         // Find all files and parse them 
    28         foreach($this->types as $type) 
    29         { 
    30             foreach(Kohana::list_files($type, TRUE) as $file) 
    31             { 
    32                 $this->files[] = $this->parse($type, $file); 
    33             } 
    34         } 
    35     } 
    36  
    37     /* 
     83    protected $file = array(); 
     84 
     85    public function __construct($type, $filename) 
     86    { 
     87        // Parse the file 
     88        $this->file = $this->parse($type, $filename); 
     89    } 
     90 
     91    /** 
    3892     * Fetch documentation for all files parsed. 
    3993     * 
    4094     * Returns: 
    41      *  Array of files 
    42      */ 
    43     public function get_docs() 
    44     { 
    45         return $this->files; 
    46     } 
    47  
    48     /* 
     95     *  array: file documentation 
     96     */ 
     97    public function get() 
     98    { 
     99        return $this->file; 
     100    } 
     101 
     102    /** 
    49103     * Parse a file for Kodoc commands, classes, and methods. 
    50104     * 
    51105     * Parameters: 
    52      *  type - file type 
    53      *  file - filename to read 
    54      */ 
    55     protected function parse($type, $file) 
    56     { 
    57         $data = array 
     106     *  string: file type 
     107     *  string: absolute filename path 
     108     */ 
     109    protected function parse($type, $filename) 
     110    { 
     111        // File definition 
     112        $file = array 
    58113        ( 
    59114            'type'      => $type, 
    60115            'about'     => '', 
    61             'package'   => '', 
    62             'file'      => preg_replace('!^'.preg_quote(DOCROOT, '!').'!', '', $file), 
    63             'classes'   => array(), 
    64             'functions' => array() 
     116            'file'      => self::remove_docroot($filename), 
     117            'classes'   => array() 
    65118        ); 
    66119 
    67120        // Open the file for reading 
    68         $handle = fopen($file, 'r'); 
    69  
    70         // Start the line number count 
    71         $l = 0; 
    72  
    73         // Loop through each line of the file 
     121        $handle = fopen($filename, 'r'); 
     122 
     123        // Do not start in a comment 
     124        $in_comment = FALSE; 
     125 
     126        // Add first comment to the file info 
     127        $add_about = TRUE; 
     128 
    74129        while ($line = fgets($handle)) 
    75130        { 
    76             $l++; 
    77  
    78             // Handle some basics 
    79131            switch(substr(trim($line), 0, 2)) 
    80132            { 
    81                 case '<?': 
    82                 case '?>': 
     133                case '/*': 
    83134                case '//': 
    84                     // Ignore PHP start and end tags, and non-block comments 
     135                    // Opening of a comment 
     136                    $in_comment = TRUE; 
    85137                    continue; 
    86                 case '/*': 
    87                     // Open a new comment block 
    88                     $block = ''; 
    89138                break; 
    90                 case '* ': 
    91                     if (isset($block)) 
     139                case '*/': 
     140                    // Ending of a comment 
     141                    $in_comment = FALSE; 
     142                    // Stop adding to the about text after the end of the first comment 
     143                    $add_about = FALSE; 
     144                    continue; 
     145                break; 
     146            } 
     147 
     148            if ($in_comment) 
     149            { 
     150                if ($add_about) 
     151                { 
     152                    // Add info to the block 
     153                    $file['about'] .= $line; 
     154                } 
     155 
     156                // Keep ignoring comments... 
     157                continue; 
     158            } 
     159 
     160            if (strpos($line, 'class') !== FALSE AND preg_match('/(?:class|interface) ([a-zA-Z0-9_]+)/', $line, $matches)) 
     161            { 
     162                // Include the file if it has not already been included 
     163                class_exists($matches[1], FALSE) or include_once $filename; 
     164 
     165                // Use reflection to find information 
     166                $reflection = new ReflectionClass($matches[1]); 
     167 
     168                // Class definition 
     169  &