PHPonTrax
[ class tree: PHPonTrax ] [ index: PHPonTrax ] [ all elements ]

Class: Inflector

Source Location: /vendor/trax/inflector.php

Class Overview


Implement the Trax naming convention


Author(s):

Variables

Methods



Class Details

[line 39]
Implement the Trax naming convention

This class provides static methods to implement the Trax naming convention. Inflector is never instantiated.




Tags:

tutorial:  Inflector


[ Top ]


Class Variables

$plural_rules = array(  '/(x|ch|ss|sh)$/' => '\1es',            # search, switch, fix, box, process, address
                '/series$/' => '\1series',
                '/([^aeiouy]|qu)ies$/' => '\1y',
                '/([^aeiouy]|qu)y$/' => '\1ies',        # query, ability, agency
                '/(?:([^f])fe|([lr])f)$/' => '\1\2ves', # half, safe, wife
                '/sis$/' => 'ses',                      # basis, diagnosis
                '/([ti])um$/' => '\1a',                 # datum, medium
                '/person$/' => 'people',                # person, salesperson
                '/man$/' => 'men',                      # man, woman, spokesman
                '/child$/' => 'children',               # child
                '/(.*)status$/' => '\1statuses',
                '/s$/' => 's',                          # no change (compatibility)
                '/$/' => 's'
        )

[line 44]

Rules for converting an English singular word to plural form



Tags:

static:  
access:  private

Type:   mixed


[ Top ]

$singular_rules = array(  '/(x|ch|ss)es$/' => '\1',
                '/movies$/' => 'movie',
                '/series$/' => 'series',
                '/([^aeiouy]|qu)ies$/' => '\1y',
                '/([lr])ves$/' => '\1f',
                '/([^f])ves$/' => '\1fe',
                '/(analy|ba|diagno|parenthe|progno|synop|the)ses$/' => '\1sis',
                '/([ti])a$/' => '\1um',
                '/people$/' => 'person',
                '/men$/' => 'man',
                '/(.*)statuses$/' => '\1status',
                '/children$/' => 'child',
                '/news$/' => 'news',
                '/s$/' => ''
        )

[line 63]

Rules for converting an English plural word to singular form



Tags:

static:  
access:  private

Type:   mixed


[ Top ]



Class Methods


method camelize [line 129]

string camelize( string $lower_case_and_underscored_word)

Convert a phrase from the lower case and underscored form to the camel case form



Tags:

return:  Camel case form of the phrase


Parameters:

string   $lower_case_and_underscored_word   Phrase to convert

[ Top ]

method capitalize [line 117]

string capitalize( string $word)

Capitalize a word making it all lower case with first letter uppercase



Tags:

return:  Capitalized $word


Parameters:

string   $word   Word to be capitalized

[ Top ]

method classify [line 176]

string classify( string $table_name)

Convert a table name to the corresponding class name



Tags:

return:  Singular CamelCase form of $table_name
usedby:  TraxGenerator::generate_scaffold()


Parameters:

string   $table_name   Name of table in the database

[ Top ]

method foreign_key [line 187]

string foreign_key( mixed $class_name, string $table_name)

Get foreign key column corresponding to a table name



Tags:

return:  Column name of the foreign key column


Parameters:

string   $table_name   Name of table referenced by foreign key

[ Top ]

method humanize [line 153]

string humanize( string $lower_case_and_underscored_word)

Generate a more human version of a lower case underscored word



Tags:

return:  The input value with underscores replaced by blanks and the first letter of each word capitalized
usedby:  TraxGenerator::generate_scaffold()
usedby:  ActiveRecordHelper::error_messages_for()
usedby:  ActiveRecord::set_content_columns()


Parameters:

string   $lower_case_and_underscored_word   A word or phrase in lower_case_underscore form

[ Top ]

method pluralize [line 87]

string pluralize( string $word)

Pluralize a word according to English rules

Convert a lower-case singular word to plural form.




Tags:

return:  Plural of $word
usedby:  TraxGenerator::generate_scaffold()


Parameters:

string   $word   Word to be pluralized

[ Top ]

method singularize [line 102]

string singularize( string $word)

Singularize a word according to English rules



Tags:

return:  Singular of $word
usedby:  TraxGenerator::generate_scaffold()


Parameters:

string   $word   Word to be singularized

[ Top ]

method tableize [line 166]

string tableize( string $class_name)

Convert a class name to the corresponding table name

The class name is a singular word or phrase in CamelCase. By convention it corresponds to a table whose name is a plural word or phrase in lower case underscore form.




Tags:

return:  Pluralized lower_case_underscore form of name
usedby:  ActiveRecord::set_table_name_using_class_name()


Parameters:

string   $class_name   Name of ActiveRecord sub-class

[ Top ]

method underscore [line 140]

string underscore( string $camel_cased_word)

Convert a phrase from the camel case form to the lower case and underscored form



Tags:

return:  Lower case and underscored form of the phrase
usedby:  TraxGenerator::generate_scaffold()
usedby:  TraxGenerator::generate_model()
usedby:  TraxGenerator::generate_controller()


Parameters:

string   $camel_cased_word   Phrase to convert

[ Top ]


Documentation generated on Thu, 04 May 2006 19:47:46 -0600 by phpDocumentor 1.3.0RC4