[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/database/model/ -> PhpNameGenerator.php (source)

   1  <?php
   2  /*
   3   *  $Id: PhpNameGenerator.php 64 2005-05-13 02:43:56Z root $
   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 LGPL. For more information please see
  19   * <http://propel.phpdb.org>.
  20   */
  21   
  22  include_once 'propel/engine/database/model/NameGenerator.php';
  23  
  24  /**
  25   * A <code>NameGenerator</code> implementation for PHP-esque names.
  26   *
  27   * @author Hans Lellelid <hans@xmpl.org> (Propel)
  28   * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  29   * @author Byron Foster <byron_foster@yahoo.com> (Torque)
  30   * @version $Revision: 64 $
  31   * @package propel.engine.database.model
  32   */
  33  class PhpNameGenerator implements NameGenerator {
  34  
  35      /**
  36       * <code>inputs</code> should consist of two elements, the
  37       * original name of the database element and the method for
  38       * generating the name.  There are currently three methods:
  39       * <code>CONV_METHOD_NOCHANGE</code> - xml names are converted
  40       * directly to php names without modification.
  41       * <code>CONV_METHOD_UNDERSCORE</code> will capitalize the first
  42       * letter, remove underscores, and capitalize each letter before
  43       * an underscore.  All other letters are lowercased. "phpname"
  44       * works the same as the <code>CONV_METHOD_PHPNAME</code> method
  45       * but will not lowercase any characters.
  46       *
  47       * @param inputs list expected to contain two parameters, element
  48       * 0 contains name to convert, element 1 contains method for conversion.
  49       * @return The generated name.
  50       * @see NameGenerator
  51       */
  52      public function generateName($inputs)
  53      {
  54          $schemaName = $inputs[0];
  55          $method = $inputs[1];
  56          $phpName = null;
  57  
  58          if ($method == self::CONV_METHOD_UNDERSCORE) {
  59              $phpName = $this->underscoreMethod($schemaName);
  60          } elseif ($method == self::CONV_METHOD_PHPNAME) {
  61              $phpName = $this->phpnameMethod($schemaName);
  62          } else if ($method == self::CONV_METHOD_NOCHANGE) {
  63              $phpName = $this->nochangeMethod($schemaName);
  64          } else {
  65              // if for some reason nothing is defined then we default
  66              // to the traditional method.
  67              $phpName = $this->underscoreMethod($schemaName);
  68          }
  69  
  70          return $phpName;
  71      }
  72  
  73      /**
  74       * Converts a database schema name to php object name.  Removes
  75       * <code>STD_SEPARATOR_CHAR</code>, capitilizes first letter of
  76       * name and each letter after the <code>STD_SEPERATOR</code>,
  77       * converts the rest of the letters to lowercase.
  78       *
  79       * my_CLASS_name -> MyClassName
  80       *
  81       * @param string $schemaName name to be converted.
  82       * @return string Converted name.
  83       * @see NameGenerator
  84       * @see #underscoreMethod()
  85       */
  86      protected function underscoreMethod($schemaName)
  87      {
  88          $name = "";
  89          $tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
  90          while($tok) {            
  91              $name .= ucfirst(strtolower($tok));
  92              $tok = strtok(self::STD_SEPARATOR_CHAR);
  93          }
  94          return $name;
  95      }
  96  
  97      /**
  98       * Converts a database schema name to php object name.  Operates
  99       * same as underscoreMethod but does not convert anything to
 100       * lowercase.
 101       * 
 102       * my_CLASS_name -> MyCLASSName
 103       * 
 104       * @param string $schemaName name to be converted.
 105       * @return string Converted name.
 106       * @see NameGenerator
 107       * @see #underscoreMethod(String)
 108       */
 109      protected function phpnameMethod($schemaName)
 110      {
 111          $name = "";
 112          $tok = strtok($schemaName, self::STD_SEPARATOR_CHAR);
 113          while($tok) {            
 114              $name .= ucfirst($tok);
 115              $tok = strtok(self::STD_SEPARATOR_CHAR);
 116          }
 117          return $name;
 118      }
 119  
 120      /**
 121       * Converts a database schema name to PHP object name.  In this
 122       * case no conversion is made.
 123       *
 124       * @param string $name name to be converted.
 125       * @return string The <code>name</code> parameter, unchanged.
 126       */
 127      protected function nochangeMethod($name)
 128      {
 129          return $name;
 130      }
 131  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7