[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/addon/ -> sfData.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   * This class defines the interface for interacting with data, as well
  13   * as default implementations.
  14   *
  15   * @package    symfony
  16   * @subpackage addon
  17   * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
  18   * @version    SVN: $Id: sfData.class.php 3382 2007-02-01 07:34:56Z fabien $
  19   */
  20  
  21  abstract class sfData
  22  {
  23    protected
  24      $deleteCurrentData = true,
  25      $object_references = array();
  26  
  27    /**
  28     * Sets a flag to indicate if the current data in the database
  29     * should be deleted before new data is loaded.
  30     *
  31     * @param boolean The flag value
  32     */
  33    public function setDeleteCurrentData($boolean)
  34    {
  35      $this->deleteCurrentData = $boolean;
  36    }
  37  
  38    /**
  39     * Gets the current value of the flag that indicates whether
  40     * current data is to be deleted or not.
  41     *
  42     * @returns boolean
  43     */
  44    public function getDeleteCurrentData()
  45    {
  46      return $this->deleteCurrentData;
  47    }
  48  
  49    /**
  50     * Loads data for the database from a YAML file
  51     *
  52     * @param string The path to the YAML file.
  53     */
  54    protected function doLoadDataFromFile($fixture_file)
  55    {
  56      // import new datas
  57      $data = sfYaml::load($fixture_file);
  58  
  59      $this->loadDataFromArray($data);
  60    }
  61  
  62    /**
  63     * Manages the insertion of data into the data source
  64     *
  65     * @param array The data to be inserted into the data source
  66     */
  67    abstract public function loadDataFromArray($data);
  68  
  69    /**
  70     * Manages reading all of the fixture data files and
  71     * loading them into the data source
  72     *
  73     * @param array The path names of the YAML data files
  74     */
  75    protected function doLoadData($fixture_files)
  76    {
  77      $this->object_references = array();
  78      $this->maps = array();
  79  
  80      sort($fixture_files);
  81      foreach ($fixture_files as $fixture_file)
  82      {
  83        $this->doLoadDataFromFile($fixture_file);
  84      }
  85    }
  86  
  87    /**
  88     * Gets a list of one or more *.yml files and returns the list in an array
  89     *
  90     * @param string A directory or file name; if null, then defaults to 'sf_data_dir'/fixtures
  91     *
  92     * @returns array A list of *.yml files.
  93     *
  94     * @throws sfInitializationException If the directory or file does not exist.
  95     */
  96    protected function getFiles($directory_or_file = null)
  97    {
  98      // directory or file?
  99      $fixture_files = array();
 100      if (!$directory_or_file)
 101      {
 102        $directory_or_file = sfConfig::get('sf_data_dir').'/fixtures';
 103      }
 104  
 105      if (is_file($directory_or_file))
 106      {
 107        $fixture_files[] = $directory_or_file;
 108      }
 109      else if (is_dir($directory_or_file))
 110      {
 111        $fixture_files = sfFinder::type('file')->name('*.yml')->in($directory_or_file);
 112      }
 113      else
 114      {
 115        throw new sfInitializationException('You must give a directory or a file.');
 116      }
 117  
 118      return $fixture_files;
 119    }
 120  }


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