ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Extractor.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Gettext\Extractors;
4 
5 use Exception;
8 
9 abstract class Extractor
10 {
19  public static function fromFile($file, Translations $translations = null)
20  {
21  if ($translations === null) {
22  $translations = new Translations();
23  }
24 
25  foreach (self::getFiles($file) as $file) {
26  static::fromString(self::readFile($file), $translations, $file);
27  }
28 
29  return $translations;
30  }
31 
39  protected static function getFiles($file)
40  {
41  if (empty($file)) {
42  throw new InvalidArgumentException('There is not any file defined');
43  }
44 
45  if (is_string($file)) {
46  if (!is_file($file)) {
47  throw new InvalidArgumentException("'$file' is not a valid file");
48  }
49 
50  if (!is_readable($file)) {
51  throw new InvalidArgumentException("'$file' is not a readable file");
52  }
53 
54  return array($file);
55  }
56 
57  if (is_array($file)) {
58  $files = array();
59 
60  foreach ($file as $f) {
61  $files = array_merge($files, self::getFiles($f));
62  }
63 
64  return $files;
65  }
66 
67  throw new InvalidArgumentException('The first argumet must be string or array');
68  }
69 
77  protected static function readFile($file)
78  {
79  $length = filesize($file);
80 
81  if (!($fd = fopen($file, 'rb'))) {
82  throw new Exception("Cannot read the file '$file', probably permissions");
83  }
84 
85  $content = $length ? fread($fd, $length) : '';
86  fclose($fd);
87 
88  return $content;
89  }
90 }
$files
Definition: add-vimline.php:18
static fromFile($file, Translations $translations=null)
Extract the translations from a file.
Definition: Extractor.php:19
static getFiles($file)
Checks and returns all files.
Definition: Extractor.php:39
Class to manage a collection of translations.
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static readFile($file)
Reads and returns the content of a file.
Definition: Extractor.php:77