Class Inflector

Description

Inflector for pluralize and singularize English nouns.

This Inflector is a port of Ruby on Rails Inflector.

It can be really helpful for developers that want to create frameworks based on naming conventions rather than configurations.

It was ported to PHP for the Akelos Framework, a multilingual Ruby on Rails like framework for PHP that will be launched soon.

  • version: $Revision 0.1 $
  • since: 0.1
  • license: GNU
  • copyright: Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
  • author: Bermi Ferrer Martinez <akelos com bermi akelos com>

Located in /Inflector.php (line 38)


	
			
Method Summary
 string camelize (string $word)
 string classify (string $table_name)
 string humanize (string $word, [string $uppercase = ''])
 string ordinalize (integer $number)
 string pluralize (string $word)
 string singularize (string $word)
 string tableize (string $class_name)
 string titleize (string $word, [string $uppercase = ''])
 string underscore (string $word)
 string variablize (string $word)
Methods
camelize (line 222)

Returns given word as CamelCased

Converts a word like "send_email" to "SendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "WhoSOnline"

string camelize (string $word)
  • string $word: Word to convert to camel case
classify (line 333)

Converts a table name to its class name according to rails naming conventions.

Converts "people" to "Person"

string classify (string $table_name)
  • string $table_name: Table name for getting related ClassName.
humanize (line 270)

Returns a human-readable string from $word

Returns a human-readable string from $word, by replacing underscores with a space, and by upper-casing the initial character by default.

If you need to uppercase all the words you just have to pass 'all' as a second parameter.

  • return: Human-readable word
  • static:
  • access: public
string humanize (string $word, [string $uppercase = ''])
  • string $word: String to "humanize"
  • string $uppercase: If set to 'all' it will uppercase all the words instead of just the first one.
ordinalize (line 351)

Converts number to its ordinal English form.

This method converts 13 to 13th, 2 to 2nd ...

  • return: Ordinal representation of given string.
  • static:
  • access: public
string ordinalize (integer $number)
  • integer $number: Number to get its ordinal value
pluralize (line 54)

Pluralizes English nouns.

  • return: Plural noun
  • static:
  • access: public
string pluralize (string $word)
  • string $word: English noun to pluralize
singularize (line 119)

Singularizes English nouns.

  • return: Singular noun.
  • static:
  • access: public
string singularize (string $word)
  • string $word: English noun to singularize
tableize (line 313)

Converts a class name to its table name according to rails naming conventions.

Converts "Person" to "people"

string tableize (string $class_name)
  • string $class_name: Class name for getting related table_name.
titleize (line 200)

Converts an underscored or CamelCase word into a English sentence.

The titleize function converts text like "WelcomePage", "welcome_page" or "welcome page" to this "Welcome Page". If second parameter is set to 'first' it will only capitalize the first character of the title.

  • return: Text formatted as title
  • static:
  • access: public
string titleize (string $word, [string $uppercase = ''])
  • string $word: Word to format as tile
  • string $uppercase: If set to 'first' it will only uppercase the first character. Otherwise it will uppercase all the words in the title.
underscore (line 243)

Converts a word "into_it_s_underscored_version"

Convert any "CamelCased" or "ordinary Word" into an "underscored_word".

This can be really useful for creating friendly URLs.

  • return: Underscored word
  • static:
  • access: public
string underscore (string $word)
  • string $word: Word to underscore
variablize (line 292)

Same as camelize but first char is underscored

Converts a word like "send_email" to "sendEmail". It will remove non alphanumeric character from the word, so "who's online" will be converted to "whoSOnline"

string variablize (string $word)
  • string $word: Word to lowerCamelCase

Documentation generated on Sat, 07 Jan 2006 14:12:44 +0100 by phpDocumentor 1.3.0RC3