Development

Changeset 19777

You must first sign up to be able to contribute.

Changeset 19777

Show
Ignore:
Timestamp:
07/01/09 12:14:21 (5 years ago)
Author:
fabien
Message:

[1.0, 1.1, 1.2, 1.3] fixed warnings when trying to load a non-valid XML file with the XLIFF i18n message source class (closes #6728)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/lib/i18n/sfMessageSource_XLIFF.class.php

    r9806 r19777  
    6868  protected function &loadData($filename) 
    6969  { 
    70     //load it. 
    71  
    72     $XML = simplexml_load_file($filename); 
    73  
    74     if (!$XML) 
    75     { 
    76       return false; 
    77     } 
    78  
    79     $translationUnit = $XML->xpath('//trans-unit'); 
     70    libxml_use_internal_errors(true); 
     71    if (!$xml = simplexml_load_file($filename)) 
     72    { 
     73      $error = false; 
     74 
     75      return $error; 
     76    } 
     77    libxml_use_internal_errors(false); 
     78 
     79    $translationUnit = $xml->xpath('//trans-unit'); 
    8080 
    8181    $translations = array(); 
  • branches/1.1/lib/i18n/sfMessageSource_XLIFF.class.php

    r13419 r19777  
    4747   * 
    4848   * @param string $filename  XLIFF file. 
    49    * @return array of messages
     49   * @return array|false An array of messages or false if there was a problem loading the file
    5050   */ 
    5151  public function &loadData($filename) 
    5252  { 
    53     $XML = simplexml_load_file($filename); 
    54  
    55     if (!$XML) 
    56     { 
    57       return false; 
    58     } 
    59  
    60     $translationUnit = $XML->xpath('//trans-unit'); 
     53    libxml_use_internal_errors(true); 
     54    if (!$xml = simplexml_load_file($filename)) 
     55    { 
     56      $error = false; 
     57 
     58      return $error; 
     59    } 
     60    libxml_use_internal_errors(false); 
     61 
     62    $translationUnit = $xml->xpath('//trans-unit'); 
    6163 
    6264    $translations = array(); 
  • branches/1.1/test/unit/i18n/sfMessageSource_XLIFFTest.php

    r9805 r19777  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(10, new lime_output_color()); 
     13$t = new lime_test(11, new lime_output_color()); 
    1414 
    1515// setup 
     
    2020// copy fixtures to tmp directory 
    2121copy(dirname(__FILE__).'/fixtures/messages.fr.xml', $temp.'/messages.fr.xml'); 
     22copy(dirname(__FILE__).'/fixtures/invalid.xml', $temp.'/invalid.xml'); 
    2223 
    2324$source = sfMessageSource::factory('XLIFF', $temp); 
     
    2829$messages = $source->loadData($source->getSource('messages.fr.xml')); 
    2930$t->is($messages['an english sentence'][0], 'une phrase en français', '->loadData() loads messages from a XLIFF file'); 
     31 
     32$t->is($source->loadData($source->getSource('invalid.xml')), false, '->loadData() returns false if it cannot load the messages from the file'); 
    3033 
    3134// ->save() 
  • branches/1.2/lib/i18n/sfMessageSource_XLIFF.class.php

    r13419 r19777  
    4747   * 
    4848   * @param string $filename  XLIFF file. 
    49    * @return array of messages
     49   * @return array|false An array of messages or false if there was a problem loading the file
    5050   */ 
    5151  public function &loadData($filename) 
    5252  { 
    53     $XML = simplexml_load_file($filename); 
    54  
    55     if (!$XML) 
    56     { 
    57       return false; 
    58     } 
    59  
    60     $translationUnit = $XML->xpath('//trans-unit'); 
     53    libxml_use_internal_errors(true); 
     54    if (!$xml = simplexml_load_file($filename)) 
     55    { 
     56      $error = false; 
     57 
     58      return $error; 
     59    } 
     60    libxml_use_internal_errors(false); 
     61 
     62    $translationUnit = $xml->xpath('//trans-unit'); 
    6163 
    6264    $translations = array(); 
  • branches/1.2/test/unit/i18n/sfMessageSource_XLIFFTest.php

    r9805 r19777  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(10, new lime_output_color()); 
     13$t = new lime_test(11, new lime_output_color()); 
    1414 
    1515// setup 
     
    2020// copy fixtures to tmp directory 
    2121copy(dirname(__FILE__).'/fixtures/messages.fr.xml', $temp.'/messages.fr.xml'); 
     22copy(dirname(__FILE__).'/fixtures/invalid.xml', $temp.'/invalid.xml'); 
    2223 
    2324$source = sfMessageSource::factory('XLIFF', $temp); 
     
    2829$messages = $source->loadData($source->getSource('messages.fr.xml')); 
    2930$t->is($messages['an english sentence'][0], 'une phrase en français', '->loadData() loads messages from a XLIFF file'); 
     31 
     32$t->is($source->loadData($source->getSource('invalid.xml')), false, '->loadData() returns false if it cannot load the messages from the file'); 
    3033 
    3134// ->save() 
  • branches/1.3/lib/i18n/sfMessageSource_XLIFF.class.php

    r13419 r19777  
    4747   * 
    4848   * @param string $filename  XLIFF file. 
    49    * @return array of messages
     49   * @return array|false An array of messages or false if there was a problem loading the file
    5050   */ 
    5151  public function &loadData($filename) 
    5252  { 
    53     $XML = simplexml_load_file($filename); 
    54  
    55     if (!$XML) 
    56     { 
    57       return false; 
    58     } 
    59  
    60     $translationUnit = $XML->xpath('//trans-unit'); 
     53    libxml_use_internal_errors(true); 
     54    if (!$xml = simplexml_load_file($filename)) 
     55    { 
     56      $error = false; 
     57 
     58      return $error; 
     59    } 
     60    libxml_use_internal_errors(false); 
     61 
     62    $translationUnit = $xml->xpath('//trans-unit'); 
    6163 
    6264    $translations = array(); 
  • branches/1.3/test/unit/i18n/sfMessageSource_XLIFFTest.php

    r19531 r19777  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(10); 
     13$t = new lime_test(11); 
    1414 
    1515// setup 
     
    2020// copy fixtures to tmp directory 
    2121copy(dirname(__FILE__).'/fixtures/messages.fr.xml', $temp.'/messages.fr.xml'); 
     22copy(dirname(__FILE__).'/fixtures/invalid.xml', $temp.'/invalid.xml'); 
    2223 
    2324$source = sfMessageSource::factory('XLIFF', $temp); 
     
    2829$messages = $source->loadData($source->getSource('messages.fr.xml')); 
    2930$t->is($messages['an english sentence'][0], 'une phrase en français', '->loadData() loads messages from a XLIFF file'); 
     31 
     32$t->is($source->loadData($source->getSource('invalid.xml')), false, '->loadData() returns false if it cannot load the messages from the file'); 
    3033 
    3134// ->save()