Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow merge router, controller and action configuration #183

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configs/assets.config.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ return [
'webPath' => __DIR__ . '/../../../public/assets',
'basePath' => 'assets',


'routes' => [
'home' => [
'@base_js',
Expand Down
37 changes: 19 additions & 18 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
Below are the description of configuration options in the main `assetic_configuration` section.


| Name | Type | Default | Description |
|--------------------|------------|------------------|-------------|
| buildOnRequest | boolean | `true` | Set to `true` if you're working in a development environment and you want on every request update your assets. If set to `false` assets won't be build during http request but you can do it from console `vendor/bin/assetic build`
| debug | boolean | `false` | If set to `true` then filters prepended with question mark `?CssMinFilter` won't be used. Great option for development enviroment.
| combine | boolean | `true` | This flag is optional, by default is set to `true`. In debug mode allow you to combine all assets to one file. Setting `false` will result in loading each asset as a separate file.
| rendererToStrategy | array | - | Described in separate section
| acceptableErrors | array | - | Described in separate section
| webPath | string | `public/assets` | Here, all assets will be saved
| cachePath | string | `data/cache` | Here, cache metadata will be saved
| cacheEnabled | boolean | `true` | If, true cache will be used on assets using filters. This is very useful if we use filters like scss, closure,...
| filePermission | integer | `null` | Permission mode of `chmod` command in octal system (exampe: 0777 or 0750) for files.
| dirPermission | integer | `null` | Permission mode of `chmod` and `mkdir` command in octal system (exampe: 0777 or 0750) for directories.
| baseUrl | string | `null` | Define base URL which will prepend your resources. If `null`, then this value will be detected by ZF2
| basePath | string | `assets` | Indicate where assets are and from where will be loaded. In example where `$baseUrl = 'http://example.com/'` `$basePath = 'assets'` `$assetPath = '/main.css'` view strategy will build such resource address `<link href="$baseUrl . $basePath . $assetPath"/>`
| controllers | array | - | Described in separate section
| routes | array | - | Described in separate section
| default | array | - | Described in separate section
| modules | array | - | Described in separate section
| Name | Type | Default | Description |
|----------------------------|------------|------------------|-------------|
| buildOnRequest | boolean | `true` | Set to `true` if you're working in a development environment and you want on every request update your assets. If set to `false` assets won't be build during http request but you can do it from console `vendor/bin/assetic build`
| debug | boolean | `false` | If set to `true` then filters prepended with question mark `?CssMinFilter` won't be used. Great option for development enviroment.
| mergeActionAndRouterConfig | boolean | `false` | If set to `true` then controller, action and router config will be merged together. Otherwise, only controller and action config are merged.
| combine | boolean | `true` | This flag is optional, by default is set to `true`. In debug mode allow you to combine all assets to one file. Setting `false` will result in loading each asset as a separate file.
| rendererToStrategy | array | - | Described in separate section
| acceptableErrors | array | - | Described in separate section
| webPath | string | `public/assets` | Here, all assets will be saved
| cachePath | string | `data/cache` | Here, cache metadata will be saved
| cacheEnabled | boolean | `true` | If, true cache will be used on assets using filters. This is very useful if we use filters like scss, closure,...
| filePermission | integer | `null` | Permission mode of `chmod` command in octal system (exampe: 0777 or 0750) for files.
| dirPermission | integer | `null` | Permission mode of `chmod` and `mkdir` command in octal system (exampe: 0777 or 0750) for directories.
| baseUrl | string | `null` | Define base URL which will prepend your resources. If `null`, then this value will be detected by ZF2
| basePath | string | `assets` | Indicate where assets are and from where will be loaded. In example where `$baseUrl = 'http://example.com/'` `$basePath = 'assets'` `$assetPath = '/main.css'` view strategy will build such resource address `<link href="$baseUrl . $basePath . $assetPath"/>`
| controllers | array | - | Described in separate section
| routes | array | - | Described in separate section
| default | array | - | Described in separate section
| modules | array | - | Described in separate section

## Specific configuration
### Modules section
Expand Down
21 changes: 21 additions & 0 deletions src/AsseticBundle/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ class Configuration
*/
protected $dirPermission = null;

/**
* @var null|bool Allow merge controller, action and router config.
*/
protected $mergeActionAndRouterConfig = false;

public function __construct($config = null)
{
if (null !== $config) {
Expand Down Expand Up @@ -463,4 +468,20 @@ public function getWriteIfChanged()
{
return $this->writeIfChanged;
}

/**
* @param bool $flag
*/
public function setMergeActionAndRouterConfig($flag)
{
$this->mergeActionAndRouterConfig = (bool) $flag;
}

/**
* @return bool
*/
public function canMergeActionAndRouterConfig()
{
return $this->mergeActionAndRouterConfig;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent potential regression in future releases, I will ask you to test that default configuration is set to false.
Test class for this file can be found here:
https://github.com/widmogrod/zf2-assetic-module/blob/master/tests/AsseticBundleTest/Configuration.php

}
9 changes: 7 additions & 2 deletions src/AsseticBundle/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,15 @@ public function setupRenderer(Renderer $renderer)
{
$controllerConfig = $this->getControllerConfig();
$actionConfig = $this->getActionConfig();
$routerConfig = $this->getRouterConfig();

$config = array_merge($controllerConfig, $actionConfig);

if (count($config) == 0) {
$config = $this->getRouterConfig();
$mergeConfigs = $this->configuration->canMergeActionAndRouterConfig();
if ($mergeConfigs) {
$config = array_merge($routerConfig, $config);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you verify that merging returns the expected result?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this in my project on production and all works as expected.
If you about tests, OK, I'll add some.

} elseif (count($config) == 0) {
$config = $routerConfig;
}

// If we don't have any assets listed by now, or if we are mixing in
Expand Down