[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/addon/propel/generator/ -> sfPropelCrudGenerator.class.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the symfony package.
   5   * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
   6   *
   7   * For the full copyright and license information, please view the LICENSE
   8   * file that was distributed with this source code.
   9   */
  10  
  11  /**
  12   * Propel CRUD generator.
  13   *
  14   * This class generates a basic CRUD module with propel.
  15   *
  16   * @package    symfony
  17   * @subpackage generator
  18   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  19   * @version    SVN: $Id: sfPropelCrudGenerator.class.php 3302 2007-01-18 13:42:46Z fabien $
  20   */
  21  
  22  class sfPropelCrudGenerator extends sfAdminGenerator
  23  {
  24    /**
  25     * Initializes the current sfGenerator instance.
  26     *
  27     * @param sfGeneratorManager A sfGeneratorManager instance
  28     */
  29    public function initialize($generatorManager)
  30    {
  31      parent::initialize($generatorManager);
  32  
  33      $this->setGeneratorClass('sfPropelCrud');
  34    }
  35  
  36    /**
  37     * Loads primary keys.
  38     *
  39     * This method is ORM dependant.
  40     *
  41     * @throws sfException
  42     */
  43    protected function loadPrimaryKeys()
  44    {
  45      foreach ($this->tableMap->getColumns() as $column)
  46      {
  47        if ($column->isPrimaryKey())
  48        {
  49          $this->primaryKey[] = $column;
  50        }
  51      }
  52  
  53      if (!count($this->primaryKey))
  54      {
  55        throw new sfException(sprintf('Cannot generate a module for a model without a primary key (%s)', $this->className));
  56      }
  57    }
  58  
  59    /**
  60     * Loads map builder classes.
  61     *
  62     * This method is ORM dependant.
  63     *
  64     * @throws sfException
  65     */
  66    protected function loadMapBuilderClasses()
  67    {
  68      // we must load all map builder classes to be able to deal with foreign keys (cf. editSuccess.php template)
  69      $classes = sfFinder::type('file')->name('*MapBuilder.php')->in(sfLoader::getModelDirs());
  70      foreach ($classes as $class)
  71      {
  72        $class_map_builder = basename($class, '.php');
  73        $maps[$class_map_builder] = new $class_map_builder();
  74        if (!$maps[$class_map_builder]->isBuilt())
  75        {
  76          $maps[$class_map_builder]->doBuild();
  77        }
  78  
  79        if ($this->className == str_replace('MapBuilder', '', $class_map_builder))
  80        {
  81          $this->map = $maps[$class_map_builder];
  82        }
  83      }
  84      if (!$this->map)
  85      {
  86        throw new sfException('The model class "'.$this->className.'" does not exist.');
  87      }
  88  
  89      $this->tableMap = $this->map->getDatabaseMap()->getTable(constant($this->className.'Peer::TABLE_NAME'));
  90    }
  91  
  92    /**
  93     * Generates a PHP call to an object helper.
  94     *
  95     * @param string The helper name
  96     * @param string The column name
  97     * @param array  An array of parameters
  98     * @param array  An array of local parameters
  99     *
 100     * @return string PHP code
 101     */
 102    function getPHPObjectHelper($helperName, $column, $params, $localParams = array())
 103    {
 104      $params = $this->getObjectTagParams($params, $localParams);
 105  
 106      return sprintf('object_%s($%s, \'%s\', %s)', $helperName, $this->getSingularName(), $this->getColumnGetter($column, false), $params);
 107    }
 108  
 109    /**
 110     * Returns the getter either non-developped: 'getFoo' or developped: '$class->getFoo()'.
 111     *
 112     * @param string  The column name
 113     * @param boolean true if you want developped method names, false otherwise
 114     * @param string The prefix value
 115     *
 116     * @return string PHP code
 117     */
 118    function getColumnGetter($column, $developed = false, $prefix = '')
 119    {
 120      $getter = 'get'.$column->getPhpName();
 121      if ($developed)
 122      {
 123        $getter = sprintf('$%s%s->%s()', $prefix, $this->getSingularName(), $getter);
 124      }
 125  
 126      return $getter;
 127    }
 128  
 129    /*
 130     * Gets the PHP name of the related class name.
 131     *
 132     * Used for foreign keys only; this method should be removed when we use sfAdminColumn instead.
 133     *
 134     * @param string The column name
 135     *
 136     * @return string The PHP name of the related class name
 137     */
 138    function getRelatedClassName($column)
 139    {
 140      $relatedTable = $this->getMap()->getDatabaseMap()->getTable($column->getRelatedTableName());
 141  
 142      return $relatedTable->getPhpName();
 143    }
 144  }


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