[ 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/ -> ConstraintNameGenerator.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: ConstraintNameGenerator.php 64 2005-05-13 02:43:56Z root $
   5   *
   6   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   7   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   8   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   9   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  10   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  12   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  13   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  14   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  16   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17   *
  18   * This software consists of voluntary contributions made by many individuals
  19   * and is licensed under the LGPL. For more information please see
  20   * <http://propel.phpdb.org>.
  21   */
  22   
  23   
  24  /**
  25   * A <code>NameGenerator</code> implementation for table-specific
  26   * constraints.  Conforms to the maximum column name length for the
  27   * type of database in use.
  28   *
  29   * @author Hans Lellelid <hans@xmpl.org> (Propel)
  30   * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  31   * @version $Revision: 64 $
  32   * @package propel.engine.database.model
  33   */
  34  class ConstraintNameGenerator implements NameGenerator {
  35      /**
  36       * Conditional compilation flag.
  37       */
  38      const DEBUG = false;
  39  
  40      /**
  41       * First element of <code>inputs</code> should be of type {@link Database}, second
  42       * should be a table name, third is the type identifier (spared if
  43       * trimming is necessary due to database type length constraints),
  44       * and the fourth is a <code>Integer</code> indicating the number
  45       * of this contraint.
  46       *
  47       * @see NameGenerator
  48       * @throws EngineException
  49       */
  50      public function generateName($inputs) 
  51      {
  52  
  53          $db = $inputs[0];
  54          $name = $inputs[1];
  55          $namePostfix = $inputs[2];
  56          $constraintNbr = (string) $inputs[3];
  57  
  58          // Calculate maximum RDBMS-specific column character limit.
  59          $maxBodyLength = -1;
  60          try {
  61              $maxColumnNameLength = (int) $db->getPlatform()->getMaxColumnNameLength();
  62              $maxBodyLength = ($maxColumnNameLength - strlen($namePostfix)
  63                      - strlen($constraintNbr) - 2);
  64  
  65              if (self::DEBUG) {
  66                  print("maxColumnNameLength=" . $maxColumnNameLength
  67                          . " maxBodyLength=" . $maxBodyLength . "\n");
  68              }
  69          } catch (EngineException $e) {                
  70              echo $e;            
  71              throw $e;
  72          }
  73  
  74          // Do any necessary trimming.
  75          if ($maxBodyLength !== -1 && strlen($name) > $maxBodyLength) {
  76              $name = substr($name, 0, $maxBodyLength);
  77          }
  78  
  79          $name .= self::STD_SEPARATOR_CHAR . $namePostfix
  80              . self::STD_SEPARATOR_CHAR . $constraintNbr;
  81  
  82          return $name;
  83      }
  84  }


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