]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Compiler/BundleCompiler.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / intl / Symfony / Component / Intl / ResourceBundle / Compiler / BundleCompiler.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Intl\ResourceBundle\Compiler;
13
14 use Symfony\Component\Intl\Exception\RuntimeException;
15
16 /**
17 * Compiles .txt resource bundles to binary .res files.
18 *
19 * @author Bernhard Schussek <bschussek@gmail.com>
20 */
21 class BundleCompiler implements BundleCompilerInterface
22 {
23 /**
24 * @var string The path to the "genrb" executable.
25 */
26 private $genrb;
27
28 /**
29 * Creates a new compiler based on the "genrb" executable.
30 *
31 * @param string $genrb Optional. The path to the "genrb" executable.
32 * @param string $envVars Optional. Environment variables to be loaded when
33 * running "genrb".
34 *
35 * @throws RuntimeException If the "genrb" cannot be found.
36 */
37 public function __construct($genrb = 'genrb', $envVars = '')
38 {
39 exec('which ' . $genrb, $output, $status);
40
41 if (0 !== $status) {
42 throw new RuntimeException(sprintf(
43 'The command "%s" is not installed',
44 $genrb
45 ));
46 }
47
48 $this->genrb = ($envVars ? $envVars . ' ' : '') . $genrb;
49 }
50
51 /**
52 * {@inheritdoc}
53 */
54 public function compile($sourcePath, $targetDir)
55 {
56 if (is_dir($sourcePath)) {
57 $sourcePath .= '/*.txt';
58 }
59
60 exec($this->genrb.' --quiet -e UTF-8 -d '.$targetDir.' '.$sourcePath, $output, $status);
61
62 if ($status !== 0) {
63 throw new RuntimeException(sprintf(
64 'genrb failed with status %d while compiling %s to %s.',
65 $status,
66 $sourcePath,
67 $targetDir
68 ));
69 }
70 }
71 }