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

   1  <?php
   2  
   3  /*
   4   *  $Id: NameFactory.php 366 2006-05-23 13:00:30Z hans $
   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  include_once 'propel/engine/EngineException.php';
  24  include_once 'propel/engine/database/model/NameGenerator.php';
  25  
  26  /**
  27   * A name generation factory.
  28   *
  29   * @author Hans Lellelid <hans@xmpl.org> (Propel)
  30   * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  31   * @version $Revision: 366 $
  32   * @package propel.engine.database.model
  33   */
  34  class NameFactory {
  35  
  36      /**
  37       * The class name of the PHP name generator.
  38       */
  39      const PHP_GENERATOR = 'PhpNameGenerator';
  40  
  41      /**
  42       * The fully qualified class name of the constraint name generator.
  43       */
  44      const CONSTRAINT_GENERATOR = 'ConstraintNameGenerator';
  45  
  46      /**
  47       * The single instance of this class.
  48       */
  49      private static $instance;
  50  
  51      /**
  52       * The cache of <code>NameGenerator</code> algorithms in use for
  53       * name generation, keyed by fully qualified class name.
  54       */
  55      private $algorithms;
  56  
  57      /**
  58       * Creates a new instance with storage for algorithm implementations.
  59       */
  60      protected function __construct()
  61      {
  62          $this->algorithms = array();
  63      }
  64  
  65      private static function instance()
  66      {
  67          if (self::$instance === null) {
  68              self::$instance = new NameFactory();            
  69          }
  70          return self::$instance;
  71      }
  72      
  73      /**
  74       * Factory method which retrieves an instance of the named generator.
  75       *
  76       * @param name The fully qualified class name of the name
  77       * generation algorithm to retrieve.
  78       */
  79      protected function getAlgorithm($name)
  80      {
  81          $algorithm = isset($this->algorithms[$name]) ? $this->algorithms[$name] : null;
  82          if ($algorithm === null) {
  83              try {
  84                  include_once 'propel/engine/database/model/' . $name . '.php';
  85                  if (!class_exists($name)) {
  86                      throw new Exception("Unable to instantiate class " . $name
  87                          . ": Make sure it's in your include_path");
  88                  }                
  89                  $algorithm = new $name();
  90              } catch (BuildException $e) {
  91                  print $e->getMessage() . "\n";
  92                  print $e->getTraceAsString();
  93              }
  94              $this->algorithms[$name] = $algorithm;
  95          }
  96          return $algorithm;
  97          
  98      }
  99  
 100      /**
 101       * Given a list of <code>String</code> objects, implements an
 102       * algorithm which produces a name.
 103       *
 104       * @param algorithmName The fully qualified class name of the
 105       * {@link NameGenerator}
 106       * implementation to use to generate names.
 107       * @param array $inputs Inputs used to generate a name.
 108       * @return The generated name.
 109       * @throws EngineException
 110       */
 111      public static function generateName($algorithmName, $inputs)
 112      {
 113          $algorithm = self::instance()->getAlgorithm($algorithmName);
 114          return $algorithm->generateName($inputs);
 115      }
 116  }


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