ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Gettext\Extractors\Extractor Class Reference
+ Inheritance diagram for Gettext\Extractors\Extractor:
+ Collaboration diagram for Gettext\Extractors\Extractor:

Static Public Member Functions

static fromFile ($file, Translations $translations=null)
 Extract the translations from a file. More...
 

Static Protected Member Functions

static getFiles ($file)
 Checks and returns all files. More...
 
static readFile ($file)
 Reads and returns the content of a file. More...
 

Detailed Description

Definition at line 9 of file Extractor.php.

Member Function Documentation

◆ fromFile()

static Gettext\Extractors\Extractor::fromFile (   $file,
Translations  $translations = null 
)
static

Extract the translations from a file.

Parameters
array | string$fileA path of a file or files
null | Translations$translationsThe translations instance to append the new translations.
Returns
Translations

Definition at line 19 of file Extractor.php.

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  }

◆ getFiles()

static Gettext\Extractors\Extractor::getFiles (   $file)
staticprotected

Checks and returns all files.

Parameters
string | array$fileThe file/s
Returns
array The file paths

Definition at line 39 of file Extractor.php.

References $f, and $files.

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  }
$files
Definition: metarefresh.php:49

◆ readFile()

static Gettext\Extractors\Extractor::readFile (   $file)
staticprotected

Reads and returns the content of a file.

Parameters
string$file
Returns
string

Definition at line 77 of file Extractor.php.

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  }

The documentation for this class was generated from the following file: