Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
xgettextCommon.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5 */
6 
7 abstract class xgettextCommon
8 {
9  protected $outputFile = "message.pot";
10  protected $inputFiles = array();
11 
12  public static function mySystem($cmd)
13  {
14  //print "$cmd\n";
15  exec($cmd, $out, $var);
16  if ($var != 0) {
17  throw new Exception("Exec : $cmd - " . print_r($out, true));
18  }
19  }
20 
21  public static function getUsage()
22  {
23  global $argv;
24  return sprintf("%s extract tranlation from layout files\n
25  %s -o <output pot file> <input file> [<input file>...]\n
26  If option has '-f-', '-', files from stdin are used\n", $argv[0], $argv[0]);
27  }
28 
29  abstract public function extract();
30 
31  protected function getXOptions()
32  {
33  return implode(" ", $this->options);
34  }
35 
36  function __construct()
37  {
38  global $argv;
39  $this->options = array_slice($argv, 1);
40  $options = getopt("o:f:x:", array(
41  "output:",
42  "files-from:",
43  "exclude-file:"
44  ));
45  if (isset($options["o"]) || isset($options["output"])) {
46  if (!empty($options["o"])) {
47  $this->outputFile = $options["o"];
48  } else {
49  $this->outputFile = $options["output"];
50  }
51  }
52 
53  if ((isset($options["f"]) && $options["f"] == "-") || (isset($options["files-from"]) && $options["files-from"] == "-")) {
54  $sFiles = file_get_contents('php://stdin');
55  $this->inputFiles = preg_split('/[\s,]+/', $sFiles);
56  foreach ($this->inputFiles as $k => $file) {
57  if (trim($file) == "") {
58  unset($this->inputFiles[$k]);
59  }
60  }
61  //@todo delete -f options
62  $this->options = explode(' ', preg_replace('/\s+(-f\s*-)/', '', implode(' ', $this->options)));
63  $this->options = explode(' ', preg_replace('/\s+(--files-from\s*=\s*-)/', '', implode(' ', $this->options)));
64  } else {
65  $lastIndex = count($argv) - 1;
66  $lastOptionIndex = $lastIndex;
67  while ($lastIndex > 0) {
68  if (substr($argv[$lastIndex], 0, 1) == '-') {
69  $lastOptionIndex = $lastIndex;
70  break;
71  }
72  $lastIndex--;
73  }
74  $lastOpt = $argv[$lastOptionIndex];
75  if ($lastOpt == "-o" || $lastOpt == "-x" || $lastOpt == "-output" || $lastOpt == "-exclude-file") {
76  $this->inputFiles = array_slice($argv, $lastOptionIndex + 2);
77  $this->options = array_slice($argv, 1, $lastOptionIndex + 1);
78  } else {
79  $this->inputFiles = array_slice($argv, $lastOptionIndex + 1);
80  $this->options = array_slice($argv, 1, $lastOptionIndex);
81  }
82  }
83  }
84  public function getOutputFile()
85  {
86  return $this->outputFile;
87  }
88 }
89 
$file
static mySystem($cmd)
foreach($argv as $arg) $cmd
← centre documentaire © anakeen