Show
Ignore:
Timestamp:
02/23/06 20:09:13 (6 years ago)
Author:
john
Message:

added in phpDoc commenting tests docs - Walt

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trax/vendor/trax/inflector.php

    r137 r138  
    11<?php 
    2 # $Id$ 
    3 # 
    4 # Copyright (c) 2005 John Peterson 
    5 # 
    6 # Permission is hereby granted, free of charge, to any person obtaining 
    7 # a copy of this software and associated documentation files (the 
    8 # "Software"), to deal in the Software without restriction, including 
    9 # without limitation the rights to use, copy, modify, merge, publish, 
    10 # distribute, sublicense, and/or sell copies of the Software, and to 
    11 # permit persons to whom the Software is furnished to do so, subject to 
    12 # the following conditions: 
    13 # 
    14 # The above copyright notice and this permission notice shall be 
    15 # included in all copies or substantial portions of the Software. 
    16 # 
    17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
    19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
    20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
    21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
    22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
    23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
     2/** 
     3 *  File containing the Inflector class 
     4 * 
     5 *  (PHP 5) 
     6 * 
     7 *  @package PHPonTrax 
     8 *  @version $Id$ 
     9 *  @copyright (c) 2005 John Peterson 
     10 * 
     11 *  Permission is hereby granted, free of charge, to any person obtaining 
     12 *  a copy of this software and associated documentation files (the 
     13 *  "Software"), to deal in the Software without restriction, including 
     14 *  without limitation the rights to use, copy, modify, merge, publish, 
     15 *  distribute, sublicense, and/or sell copies of the Software, and to 
     16 *  permit persons to whom the Software is furnished to do so, subject to 
     17 *  the following conditions: 
     18 * 
     19 *  The above copyright notice and this permission notice shall be 
     20 *  included in all copies or substantial portions of the Software. 
     21 * 
     22 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
     23 *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
     24 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
     25 *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 
     26 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 
     27 *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 
     28 *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
     29 */ 
    2430 
     31/** 
     32 *  Inflector contains static methods to convert English words between 
     33 *  singular and plural, and phrases between the camel case form and 
     34 *  the lower case underscore form.  For details see the 
     35 *  {@tutorial PHPonTrax/Inflector.cls} tutorial. 
     36 * 
     37 *  @package PHPonTrax 
     38 * 
     39 */ 
    2540class Inflector { 
    2641 
     42    /** 
     43     *  Rules for converting an English singular word to plural form 
     44     */ 
    2745    private static $plural_rules = 
    2846        array(  '/(x|ch|ss|sh)$/' => '\1es',            # search, switch, fix, box, process, address 
     
    4159        ); 
    4260 
     61    /** 
     62     *  Rules for converting an English plural word to singular form 
     63     */ 
    4364    private static $singular_rules = 
    4465        array(  '/(x|ch|ss)es$/' => '\1', 
     
    5879        ); 
    5980 
     81    /** 
     82     *  Pluralize a word according to English rules 
     83     * 
     84     *  Convert a lower-case singular word to plural form. 
     85     *  @param  string $word  Word to be pluralized 
     86     *  @return string  Plural of $word 
     87     */ 
    6088    function pluralize($word) { 
    6189        $original = $word; 
     
    6795    } 
    6896 
     97    /** 
     98     *  Singularize a word according to English rules  
     99     * 
     100     *  @param  string $word  Word to be singularized 
     101     *  @return string  Singular of $word 
     102     */ 
    69103    function singularize($word) { 
    70104        $original = $word; 
     
    76110    } 
    77111 
     112    /** 
     113     *  Convert a phrase from the lower case and underscored form 
     114     *  to the camel case form 
     115     * 
     116     *  @param string $lower_case_and_underscored_word  Phrase to 
     117     *                                                  convert 
     118     *  @return string  Camel case form of the phrase 
     119     */ 
    78120    function camelize($lower_case_and_underscored_word) { 
    79121        return str_replace(" ","",ucwords(str_replace("_"," ",$lower_case_and_underscored_word))); 
    80122    } 
    81123 
     124    /** 
     125     *  Convert a phrase from the camel case form to the lower case 
     126     *  and underscored form 
     127     * 
     128     *  @param string $camel_cased_word  Phrase to convert 
     129     *  @return string Lower case and underscored form of the phrase 
     130     */ 
    82131    function underscore($camel_cased_word) { 
    83132        $camel_cased_word = preg_replace('/([A-Z]+)([A-Z])/','\1_\2',$camel_cased_word); 
     
    85134    } 
    86135 
     136    /** 
     137     *  Generate a more human version of a lower case underscored word 
     138     * 
     139     *  @param string $lower_case_and_underscored_word  A word or phrase in 
     140     *                                           lower_case_underscore form 
     141     *  @return string The input value with underscores replaced by 
     142     *  blanks and the first letter of each word capitalized 
     143     */ 
    87144    function humanize($lower_case_and_underscored_word) { 
    88145        return ucwords(str_replace("_"," ",$lower_case_and_underscored_word)); 
    89146    } 
    90147 
     148    /** 
     149     *  Convert a class name to the corresponding table name 
     150     * 
     151     *  The class name is a singular word or phrase in CamelCase. 
     152     *  By convention it corresponds to a table whose name is a plural 
     153     *  word or phrase in lower case underscore form. 
     154     *  @param string $class_name  Name of {@link ActiveRecord} sub-class 
     155     *  @return string Pluralized lower_case_underscore form of name 
     156     */ 
    91157    function tableize($class_name) { 
    92158        return self::pluralize(self::underscore($class_name)); 
    93159    } 
    94160 
     161    /** 
     162     *  Convert a table name to the corresponding class name 
     163     * 
     164     *  @param string $table_name Name of table in the database 
     165     *  @return string Singular CamelCase form of $table_name 
     166     */ 
    95167    function classify($table_name) { 
    96168        return self::camelize(self::singularize($table_name)); 
    97169    } 
    98170 
     171    /** 
     172     *  Get foreign key column corresponding to a table name 
     173     * 
     174     *  @param string $table_name Name of table referenced by foreign 
     175     *    key 
     176     *  @return string Column name of the foreign key column 
     177     */ 
    99178    function foreign_key($class_name) { 
    100179        return self::underscore($class_name) . "_id";