diff options
Diffstat (limited to 'vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php')
-rw-r--r-- | vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php new file mode 100644 index 00000000..0692d6fe --- /dev/null +++ b/vendor/symfony/intl/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php | |||
@@ -0,0 +1,96 @@ | |||
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\Transformer; | ||
13 | |||
14 | use Symfony\Component\Intl\Exception\RuntimeException; | ||
15 | use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\TransformationRuleInterface; | ||
16 | use Symfony\Component\Intl\ResourceBundle\Writer\PhpBundleWriter; | ||
17 | |||
18 | /** | ||
19 | * Compiles a number of resource bundles based on predefined compilation rules. | ||
20 | * | ||
21 | * @author Bernhard Schussek <bschussek@gmail.com> | ||
22 | */ | ||
23 | class BundleTransformer | ||
24 | { | ||
25 | /** | ||
26 | * @var TransformationRuleInterface[] | ||
27 | */ | ||
28 | private $rules = array(); | ||
29 | |||
30 | /** | ||
31 | * Adds a new compilation rule. | ||
32 | * | ||
33 | * @param TransformationRuleInterface $rule The compilation rule. | ||
34 | */ | ||
35 | public function addRule(TransformationRuleInterface $rule) | ||
36 | { | ||
37 | $this->rules[] = $rule; | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Runs the compilation with the given compilation context. | ||
42 | * | ||
43 | * @param CompilationContextInterface $context The context storing information | ||
44 | * needed to run the compilation. | ||
45 | * | ||
46 | * @throws RuntimeException If any of the files to be compiled by the loaded | ||
47 | * compilation rules does not exist. | ||
48 | */ | ||
49 | public function compileBundles(CompilationContextInterface $context) | ||
50 | { | ||
51 | $filesystem = $context->getFilesystem(); | ||
52 | $compiler = $context->getCompiler(); | ||
53 | |||
54 | $filesystem->remove($context->getBinaryDir()); | ||
55 | $filesystem->mkdir($context->getBinaryDir()); | ||
56 | |||
57 | foreach ($this->rules as $rule) { | ||
58 | $filesystem->mkdir($context->getBinaryDir() . '/' . $rule->getBundleName()); | ||
59 | |||
60 | $resources = (array) $rule->beforeCompile($context); | ||
61 | |||
62 | foreach ($resources as $resource) { | ||
63 | if (!file_exists($resource)) { | ||
64 | throw new RuntimeException(sprintf( | ||
65 | 'The file "%s" to be compiled by %s does not exist.', | ||
66 | $resource, | ||
67 | get_class($rule) | ||
68 | )); | ||
69 | } | ||
70 | |||
71 | $compiler->compile($resource, $context->getBinaryDir() . '/' . $rule->getBundleName()); | ||
72 | } | ||
73 | |||
74 | $rule->afterCompile($context); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public function createStubs(StubbingContextInterface $context) | ||
79 | { | ||
80 | $filesystem = $context->getFilesystem(); | ||
81 | $phpWriter = new PhpBundleWriter(); | ||
82 | |||
83 | $filesystem->remove($context->getStubDir()); | ||
84 | $filesystem->mkdir($context->getStubDir()); | ||
85 | |||
86 | foreach ($this->rules as $rule) { | ||
87 | $filesystem->mkdir($context->getStubDir() . '/' . $rule->getBundleName()); | ||
88 | |||
89 | $data = $rule->beforeCreateStub($context); | ||
90 | |||
91 | $phpWriter->write($context->getStubDir() . '/' . $rule->getBundleName(), 'en', $data); | ||
92 | |||
93 | $rule->afterCreateStub($context); | ||
94 | } | ||
95 | } | ||
96 | } | ||