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 #182

Open
popovserhii opened this issue May 27, 2018 · 2 comments
Open

Allow merge router, controller and action configuration #182

popovserhii opened this issue May 27, 2018 · 2 comments

Comments

@popovserhii
Copy link

There is no way to use controller configuration in pair with router configuration.
For example, I develop a project which has front and admin parts.
Obviously, the project can have some default scripts for front and admin:

'routes' => [
	'front(.*)' => [
		'@front_js',
	],
	'admin(.*)' => [
		'@admin_js',
	],
]

But when I want to add a custom script for a controller the config above stop working, because AsseticBundle\Service::setupRenderer handle router configuration only when the controller configuration doesn't set.

This can be fixed with a simple change:

$controllerConfig = $this->getControllerConfig();
$actionConfig = $this->getActionConfig();
$config = array_merge($controllerConfig, $actionConfig);

if (count($config) == 0) {
	$config = $this->getRouterConfig();
}

to

$controllerConfig = $this->getControllerConfig();
$actionConfig = $this->getActionConfig();
$routerConfig = $this->getRouterConfig();
$config = array_merge($routerConfig, $controllerConfig, $actionConfig);

If you agree with this change I will do PR.

@widmogrod
Copy link
Owner

widmogrod commented Jun 1, 2018

Hi @popovserhii,

I will gladly accept this PR, in addition to it, I would suggest one change.

  • feature toggle - for merging configurations like bellow (default false - don't allow to merge for backward compatibility reasons)
$controllerConfig = $this->getControllerConfig();
$actionConfig = $this->getActionConfig();
$routerConfig = $this->getRouterConfig();

$mergeConfigs = $this->configuration->canMergeActionAndRouterConfig();
if ($mergeConfigs) {
  $config = array_merge($routerConfig, $controllerConfig, $actionConfig);
} else {
  // .. old way
}

What do you think?

@popovserhii
Copy link
Author

It is even better. I will do PR in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants