Development

Changeset 12064

You must first sign up to be able to contribute.

Changeset 12064

Show
Ignore:
Timestamp:
10/08/08 08:13:45 (2 months ago)
Author:
fabien
Message:

[1.2] added the possibility to pass an array to sfData::getFiles()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.2/UPGRADE_TO_1_2

    r12063 r12064  
    666666The browser classes now add the `HTTP_REFERER` header for each request. 
    667667 
    668 Tests 
    669 ----- 
     668Functional Tests 
     669---------------- 
    670670 
    671671When you write a lot of functional tests for a given module, it is sometimes 
  • branches/1.2/lib/addon/sfData.class.php

    r9083 r12064  
    5050   * Loads data for the database from a YAML file 
    5151   * 
    52    * @param string $fixture_file The path to the YAML file. 
     52   * @param string $file The path to the YAML file. 
    5353   */ 
    54   protected function doLoadDataFromFile($fixture_file) 
     54  protected function doLoadDataFromFile($file) 
    5555  { 
    5656    // import new datas 
    57     $data = sfYaml::load($fixture_file); 
     57    $data = sfYaml::load($file); 
    5858 
    5959    $this->loadDataFromArray($data); 
     
    7171   * loading them into the data source 
    7272   * 
    73    * @param array $fixture_files The path names of the YAML data files 
     73   * @param array $files The path names of the YAML data files 
    7474   */ 
    75   protected function doLoadData($fixture_files) 
     75  protected function doLoadData($files) 
    7676  { 
    7777    $this->object_references = array(); 
    7878    $this->maps = array(); 
    7979 
    80     sort($fixture_files); 
    81     foreach ($fixture_files as $fixture_file) 
     80    foreach ($files as $file) 
    8281    { 
    83       $this->doLoadDataFromFile($fixture_file); 
     82      $this->doLoadDataFromFile($file); 
    8483    } 
    8584  } 
    8685 
    8786  /** 
    88    * Gets a list of one or more *.yml files and returns the list in an array 
     87   * Gets a list of one or more *.yml files and returns the list in an array. 
    8988   * 
    90    * @param string $directory_or_file A directory or file name; if null, then defaults to 'sf_data_dir'/fixtures 
     89   * The returned array of files is sorted by alphabetical order. 
    9190   * 
    92    * @returns array A list of *.yml files. 
     91   * @param  string|array $element A directory or file name or an array of directories and/or file names 
     92   *                               If null, then defaults to 'sf_data_dir'/fixtures 
     93   * 
     94   * @return array A list of *.yml files 
    9395   * 
    9496   * @throws sfInitializationException If the directory or file does not exist. 
    9597   */ 
    96   protected function getFiles($directory_or_file = null) 
     98  public function getFiles($element = null) 
    9799  { 
    98     // directory or file? 
    99     $fixture_files = array(); 
    100     if (!$directory_or_file) 
     100    if (is_null($element)) 
    101101    { 
    102102      $directory_or_file = sfConfig::get('sf_data_dir').'/fixtures'; 
    103103    } 
    104104 
    105     if (is_file($directory_or_file)) 
     105    $files = array(); 
     106    if (is_array($element)) 
    106107    { 
    107       $fixture_files[] = $directory_or_file; 
     108      foreach ($element as $e) 
     109      { 
     110        $files = array_merge($files, $this->getFiles($e)); 
     111      } 
    108112    } 
    109     else if (is_dir($directory_or_file)) 
     113    else if (is_file($element)) 
    110114    { 
    111       $fixture_files = sfFinder::type('file')->name('*.yml')->in($directory_or_file); 
     115      $files[] = $element; 
     116    } 
     117    else if (is_dir($element)) 
     118    { 
     119      $files = sfFinder::type('file')->name('*.yml')->in($element); 
    112120    } 
    113121    else 
    114122    { 
    115       throw new sfInitializationException('You must give a directory or a file.'); 
     123      throw new sfInitializationException('You must give an array, a directory or a file to sfPropelData::getFiles().'); 
    116124    } 
    117125 
    118     return $fixture_files; 
     126    $files = array_unique($files); 
     127    sort($files); 
     128 
     129    return $files; 
    119130  } 
    120131}