123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- /*
- * This file is part of the symfony package.
- * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- /**
- * This class defines the interface for interacting with data, as well
- * as default implementations.
- *
- * @package symfony
- * @subpackage addon
- * @author Fabien Potencier <fabien.potencier@symfony-project.com>
- * @version SVN: $Id: sfData.class.php 15803 2009-02-26 09:48:55Z fabien $
- */
- abstract class sfData
- {
- protected
- $deleteCurrentData = true,
- $object_references = array();
- /**
- * Sets a flag to indicate if the current data in the database
- * should be deleted before new data is loaded.
- *
- * @param boolean $boolean The flag value
- */
- public function setDeleteCurrentData($boolean)
- {
- $this->deleteCurrentData = $boolean;
- }
- /**
- * Gets the current value of the flag that indicates whether
- * current data is to be deleted or not.
- *
- * @returns boolean
- */
- public function getDeleteCurrentData()
- {
- return $this->deleteCurrentData;
- }
- /**
- * Loads data for the database from a YAML file
- *
- * @param string $fixture_file The path to the YAML file.
- */
- protected function doLoadDataFromFile($fixture_file)
- {
- // import new datas
- $data = sfYaml::load($fixture_file);
- $this->loadDataFromArray($data);
- }
- /**
- * Manages the insertion of data into the data source
- *
- * @param array $data The data to be inserted into the data source
- */
- abstract public function loadDataFromArray($data);
- /**
- * Manages reading all of the fixture data files and
- * loading them into the data source
- *
- * @param array $fixture_files The path names of the YAML data files
- */
- protected function doLoadData($fixture_files)
- {
- $this->object_references = array();
- $this->maps = array();
- sort($fixture_files);
- foreach ($fixture_files as $fixture_file)
- {
- $this->doLoadDataFromFile($fixture_file);
- }
- }
- /**
- * Gets a list of one or more *.yml files and returns the list in an array
- *
- * @param string $directory_or_file A directory or file name; if null, then defaults to 'sf_data_dir'/fixtures
- *
- * @returns array A list of *.yml files.
- *
- * @throws sfInitializationException If the directory or file does not exist.
- */
- protected function getFiles($directory_or_file = null)
- {
- // directory or file?
- $fixture_files = array();
- if (!$directory_or_file)
- {
- $directory_or_file = sfConfig::get('sf_data_dir').'/fixtures';
- }
- if (is_file($directory_or_file))
- {
- $fixture_files[] = $directory_or_file;
- }
- else if (is_dir($directory_or_file))
- {
- $fixture_files = sfFinder::type('file')->name('*.yml')->sort_by_name()->in($directory_or_file);
- }
- else
- {
- throw new sfInitializationException('You must give a directory or a file.');
- }
- return $fixture_files;
- }
- }
|