Source of file BundleTransformer.php
Size: 3,042 Bytes - Last Modified: 2013-07-17T08:22:21+02:00
/home/theseer/Downloads/Symfony/vendor/symfony/symfony/src/Symfony/Component/Intl/ResourceBundle/Transformer/BundleTransformer.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Intl\ResourceBundle\Transformer; use Symfony\Component\Intl\Exception\RuntimeException; use Symfony\Component\Intl\ResourceBundle\Transformer\Rule\TransformationRuleInterface; use Symfony\Component\Intl\ResourceBundle\Writer\PhpBundleWriter; /** * Compiles a number of resource bundles based on predefined compilation rules. * * @author Bernhard Schussek <bschussek@gmail.com> */ class BundleTransformer { /** * @var TransformationRuleInterface[] */ private $rules = array(); /** * Adds a new compilation rule. * * @param TransformationRuleInterface $rule The compilation rule. */ public function addRule(TransformationRuleInterface $rule) { $this->rules[] = $rule; } /** * Runs the compilation with the given compilation context. * * @param CompilationContextInterface $context The context storing information * needed to run the compilation. * * @throws RuntimeException If any of the files to be compiled by the loaded * compilation rules does not exist. */ public function compileBundles(CompilationContextInterface $context) { $filesystem = $context->getFilesystem(); $compiler = $context->getCompiler(); $filesystem->remove($context->getBinaryDir()); $filesystem->mkdir($context->getBinaryDir()); foreach ($this->rules as $rule) { $filesystem->mkdir($context->getBinaryDir() . '/' . $rule->getBundleName()); $resources = (array) $rule->beforeCompile($context); foreach ($resources as $resource) { if (!file_exists($resource)) { throw new RuntimeException(sprintf( 'The file "%s" to be compiled by %s does not exist.', $resource, get_class($rule) )); } $compiler->compile($resource, $context->getBinaryDir() . '/' . $rule->getBundleName()); } $rule->afterCompile($context); } } public function createStubs(StubbingContextInterface $context) { $filesystem = $context->getFilesystem(); $phpWriter = new PhpBundleWriter(); $filesystem->remove($context->getStubDir()); $filesystem->mkdir($context->getStubDir()); foreach ($this->rules as $rule) { $filesystem->mkdir($context->getStubDir() . '/' . $rule->getBundleName()); $data = $rule->beforeCreateStub($context); $phpWriter->write($context->getStubDir() . '/' . $rule->getBundleName(), 'en', $data); $rule->afterCreateStub($context); } } } |