~ubuntu-branches/ubuntu/wily/php-doctrine-common/wily-proposed

« back to all changes in this revision

Viewing changes to DoctrineCommon-2.3.0/Doctrine/Common/Util/Inflector.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2013-10-21 18:31:11 UTC
  • Revision ID: package-import@ubuntu.com-20131021183111-eabfxiw5k0zrbns0
Tags: upstream-2.3.0
Import upstream version 2.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 *  $Id: Inflector.php 3189 2007-11-18 20:37:44Z meus $
 
4
 *
 
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
16
 *
 
17
 * This software consists of voluntary contributions made by many individuals
 
18
 * and is licensed under the MIT license. For more information, see
 
19
 * <http://www.doctrine-project.org>.
 
20
 */
 
21
 
 
22
namespace Doctrine\Common\Util;
 
23
 
 
24
/**
 
25
 * Doctrine inflector has static methods for inflecting text
 
26
 *
 
27
 * The methods in these classes are from several different sources collected
 
28
 * across several different php projects and several different authors. The
 
29
 * original author names and emails are not known
 
30
 *
 
31
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 
32
 * @link        www.doctrine-project.org
 
33
 * @since       1.0
 
34
 * @version     $Revision: 3189 $
 
35
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 
36
 * @author      Jonathan H. Wage <jonwage@gmail.com>
 
37
 */
 
38
class Inflector
 
39
{
 
40
    /**
 
41
     * Convert word in to the format for a Doctrine table name. Converts 'ModelName' to 'model_name'
 
42
     *
 
43
     * @param  string $word  Word to tableize
 
44
     * @return string $word  Tableized word
 
45
     */
 
46
    public static function tableize($word)
 
47
    {
 
48
        return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
 
49
    }
 
50
 
 
51
    /**
 
52
     * Convert a word in to the format for a Doctrine class name. Converts 'table_name' to 'TableName'
 
53
     *
 
54
     * @param string  $word  Word to classify
 
55
     * @return string $word  Classified word
 
56
     */
 
57
    public static function classify($word)
 
58
    {
 
59
        return str_replace(" ", "", ucwords(strtr($word, "_-", "  ")));
 
60
    }
 
61
 
 
62
    /**
 
63
     * Camelize a word. This uses the classify() method and turns the first character to lowercase
 
64
     *
 
65
     * @param string $word
 
66
     * @return string $word
 
67
     */
 
68
    public static function camelize($word)
 
69
    {
 
70
        return lcfirst(self::classify($word));
 
71
    }
 
72
}