4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Intl\ResourceBundle\Compiler
;
14 use Symfony\Component\Intl\Exception\RuntimeException
;
17 * Compiles .txt resource bundles to binary .res files.
19 * @author Bernhard Schussek <bschussek@gmail.com>
21 class BundleCompiler
implements BundleCompilerInterface
24 * @var string The path to the "genrb" executable.
29 * Creates a new compiler based on the "genrb" executable.
31 * @param string $genrb Optional. The path to the "genrb" executable.
32 * @param string $envVars Optional. Environment variables to be loaded when
35 * @throws RuntimeException If the "genrb" cannot be found.
37 public function __construct($genrb = 'genrb', $envVars = '')
39 exec('which ' . $genrb, $output, $status);
42 throw new RuntimeException(sprintf(
43 'The command "%s" is not installed',
48 $this->genrb
= ($envVars ? $envVars . ' ' : '') . $genrb;
54 public function compile($sourcePath, $targetDir)
56 if (is_dir($sourcePath)) {
57 $sourcePath .= '/*.txt';
60 exec($this->genrb
.' --quiet -e UTF-8 -d '.$targetDir.' '.$sourcePath, $output, $status);
63 throw new RuntimeException(sprintf(
64 'genrb failed with status %d while compiling %s to %s.',