Development

/branches/1.0/lib/addon/sfData.class.php

You must first sign up to be able to contribute.

root/branches/1.0/lib/addon/sfData.class.php

Revision 20457, 2.9 kB (checked in by FabianLange, 5 years ago)

[doc] fixed phpdoc (closes #6878)

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