Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[AsseticBundle] added config option to limit which bundles formulae a…
…re loaded from
- Loading branch information
1 parent
57d0d3f
commit d57c665
Showing
3 changed files
with
68 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,34 +29,6 @@ class AsseticExtension extends Extension | |
/** | ||
* Loads the configuration. | ||
* | ||
* When the debug flag is true, files in an asset collections will be | ||
* rendered individually. | ||
* | ||
* In XML: | ||
* | ||
* <assetic:config | ||
* debug="true" | ||
* use-controller="true" | ||
* read-from="/path/to/web" | ||
* write-to="s3://mybucket" | ||
* closure="/path/to/google_closure/compiler.jar" | ||
* yui="/path/to/yuicompressor.jar" | ||
* default-javascripts-output="js/build/*.js" | ||
* default-stylesheets-output="css/build/*.css" | ||
* /> | ||
* | ||
* In YAML: | ||
* | ||
* assetic: | ||
* debug: true | ||
* use_controller: true | ||
* read_from: /path/to/web | ||
* write_to: s3://mybucket | ||
* closure: /path/to/google_closure/compiler.jar | ||
* yui: /path/to/yuicompressor.jar | ||
* default_javascripts_output: js/build/*.js | ||
* default_stylesheets_output: css/build/*.css | ||
* | ||
* @param array $configs An array of configuration settings | ||
* @param ContainerBuilder $container A ContainerBuilder instance | ||
*/ | ||
|
@@ -67,9 +39,7 @@ public function load(array $configs, ContainerBuilder $container) | |
$loader->load('templating_twig.xml'); | ||
// $loader->load('templating_php.xml'); // not ready yet | ||
|
||
$configuration = new Configuration(); | ||
$processor = new Processor(); | ||
$config = $processor->process($configuration->getConfigTree($container->getParameter('kernel.debug')), $configs); | ||
$config = self::processConfigs($configs, $container->getParameter('kernel.debug'), array_keys($container->getParameter('kernel.bundles'))); | ||
|
||
$container->setParameter('assetic.debug', $config['debug']); | ||
$container->setParameter('assetic.use_controller', $config['use_controller']); | ||
|
@@ -100,20 +70,36 @@ public function load(array $configs, ContainerBuilder $container) | |
$container->getDefinition('assetic.filter.less')->addMethodCall('setCompress', array('%assetic.less.compress%')); | ||
} | ||
|
||
$this->registerFormulaResources($container); | ||
$this->registerFormulaResources($container, $container->getParameterBag()->resolveValue($config['bundles'])); | ||
} | ||
|
||
protected function registerFormulaResources(ContainerBuilder $container) | ||
static protected function processConfigs(array $configs, $debug, array $bundles) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kriswallsmith
Author
Contributor
|
||
{ | ||
// bundle views/ directories | ||
$configuration = new Configuration(); | ||
$tree = $configuration->getConfigTree($debug, $bundles); | ||
|
||
$processor = new Processor(); | ||
return $processor->process($tree, $configs); | ||
} | ||
|
||
static protected function registerFormulaResources(ContainerBuilder $container, array $bundles) | ||
{ | ||
$map = $container->getParameter('kernel.bundles'); | ||
|
||
if ($diff = array_diff($bundles, array_keys($map))) { | ||
throw new \InvalidArgumentException(sprintf('The following bundles are not registered: "%s"', implode('", "', $diff))); | ||
} | ||
|
||
$am = $container->getDefinition('assetic.asset_manager'); | ||
foreach ($container->getParameter('kernel.bundles') as $name => $class) { | ||
$rc = new \ReflectionClass($class); | ||
|
||
// bundle views/ directories | ||
foreach ($bundles as $name) { | ||
$rc = new \ReflectionClass($map[$name]); | ||
if (is_dir($dir = dirname($rc->getFileName()).'/Resources/views')) { | ||
foreach (array('twig', 'php') as $engine) { | ||
$container->setDefinition( | ||
'assetic.'.$engine.'_directory_resource.'.$name, | ||
$this->createDirectoryResourceDefinition($name, $dir, $engine) | ||
self::createDirectoryResourceDefinition($name, $dir, $engine) | ||
); | ||
} | ||
} | ||
|
@@ -124,7 +110,7 @@ protected function registerFormulaResources(ContainerBuilder $container) | |
foreach (array('twig', 'php') as $engine) { | ||
$container->setDefinition( | ||
'assetic.'.$engine.'_directory_resource.kernel', | ||
$this->createDirectoryResourceDefinition('', $dir, $engine) | ||
self::createDirectoryResourceDefinition('', $dir, $engine) | ||
); | ||
} | ||
} | ||
|
@@ -133,7 +119,7 @@ protected function registerFormulaResources(ContainerBuilder $container) | |
/** | ||
* @todo decorate an abstract xml definition | ||
*/ | ||
protected function createDirectoryResourceDefinition($bundle, $dir, $engine) | ||
static protected function createDirectoryResourceDefinition($bundle, $dir, $engine) | ||
{ | ||
$definition = new Definition('%assetic.directory_resource.class%'); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@kriswallsmith what is the reason for this method to be static?