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

[ResourceBundle][WIP] Global settings #1168

Merged
merged 1 commit into from
Aug 6, 2014

Conversation

arnolanglade
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Fixed tickets -
License MIT
Doc PR No yet

Related RFC #1126

The configuration of each route is used in several places (controller and twig extension for example), so we needed to parse it and merge the default settings several time. But I wanted to it only one time and inject it in the container. It is done in the KernelControllerSubscriber. I created a new class named Parameter which extends ParameterBag. This class is declared as a service and use by ResourceExtension and Configuration.

@@ -38,6 +38,8 @@ public function load(array $config, ContainerBuilder $container)

$classes = isset($config['resources']) ? $config['resources'] : array();

$container->setParameter('sylius.defaultsettings', $config['settings']);
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultsettings => default_settings

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even: sylius.settings.default

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like sylius.settings.default

Copy link
Contributor

Choose a reason for hiding this comment

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

@Arn0d But I guess this could be confusing, so I would recommend to call it: sylius.settings.pagination or sylius.resource.settings

Mostly because we use sylius.settings.xxx for SettingsBundle stuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sylius.resource.settings sounds good !

*
* @var array
*/
protected $defaultSettings;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this name $defaultSettings... These are the settings we can configure right via config.yml right ? Default sounds like we can not override them. What about $crudSettings ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not $resourcesSettings ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like both proposal :D! What about settings?

Copy link
Contributor

Choose a reason for hiding this comment

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

$settings is good enough IMO.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same for all other variables with $default in names.

@arnolanglade
Copy link
Contributor Author

I am back guys !

->arrayNode('paginate')
->addDefaultsIfNotSet()
->children()
->booleanNode('active')->defaultTrue()->end()
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of active, you should IMO use: canBeEnabled()/canBeDisabled().

Copy link
Contributor

Choose a reason for hiding this comment

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

@Arn0d ping =)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will check it out !

@arnolanglade
Copy link
Contributor Author

@Sylius/core-team / @stloyd , the build is green. What do you think ?

*
* @return array
*/
private function mergeDefaultSettings(array $parameters, array $settings, $reset)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this method? Passing a boolean parameter here, just to do something or do nothing does not seem right...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I merge the settings with the route parameters. The both configuration have not the same structure. It is not the best place for this, perhaps you should play the kernel event.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like :

class KernelControllerSubscriber {
    public function onKernelRequest(GetResponseEvent $event)
    {
        // If resquest has _sylius attribute, we parse it and create a Configuration object and put it  the container. 
    }

Like that, we can get the Configuration object everywhere (controller, twig extension, etc...).

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski Do you prefer it?

*/
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using replace()?

@arnolanglade
Copy link
Contributor Author

ping @stloyd / @Sylius/core-team

@arnolanglade
Copy link
Contributor Author

"your test run exceeded 50.0 minutes" for PHP 5.3 and 5.5, Green for 5.4. ping @pjedrzejewski

{
$limit = $this->get('limit', 10);
return (boolean) $this->parameters->get('limit', $this->settings['limit']['enabled']);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you should use has() here, as you force to boolean anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heuuu, no I just tested. I don't want to check if the parameter exists but I want to check its value because limit is always set to false or true.

@arnolanglade
Copy link
Contributor Author

I restarted the build, now it is green !

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski I need to rebase it but can you give me feedback, please?

->arrayNode('sorting')
->canBeEnabled()
->children()
->scalarNode('parameter_name')->defaultNull()->end()
Copy link
Member

Choose a reason for hiding this comment

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

What is parameter_name?

@pjedrzejewski
Copy link
Member

I just don't get why this has to be that complex... Isn't defining configuration and merging 2 arrays enough to have defaults? This is huge...

@arnolanglade
Copy link
Contributor Author

Yes you're right I will simplify the configuration definition. Did you have a look at the rest of PR ?

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski and now? Do you prefer it ?

@arnolanglade
Copy link
Contributor Author

ping @Sylius/core-team

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski : Can you give me feedback plz? If you don't like it we can close it ! I explain it a bit more (in my first post).

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski friendly ping ?

@arnolanglade
Copy link
Contributor Author

ping @pjedrzejewski! Do I rebase it? Is there any chances to get this PR merged?

@ghost
Copy link

ghost commented Aug 5, 2014

whoo. i'd like something like this :)

@sstok
Copy link
Contributor

sstok commented Aug 6, 2014

👍

1 similar comment
@amenophis
Copy link
Contributor

👍

@pjedrzejewski
Copy link
Member

@Arn0d Yes, looks good to me, I will merge as soon as you rebase. Thanks!

@arnolanglade
Copy link
Contributor Author

@pjedrzejewski done :) !

pjedrzejewski pushed a commit that referenced this pull request Aug 6, 2014
[ResourceBundle][WIP] Global settings
@pjedrzejewski pjedrzejewski merged commit a621880 into Sylius:master Aug 6, 2014
@pjedrzejewski
Copy link
Member

Thanks Arnaud!

arnolanglade added a commit to arnolanglade/Sylius that referenced this pull request Aug 7, 2014
foopang pushed a commit to foopang/Sylius that referenced this pull request Aug 13, 2014
kayue pushed a commit to kayue/Sylius that referenced this pull request Aug 14, 2014
pjedrzejewski pushed a commit that referenced this pull request Aug 15, 2014
Fixing the parameter parser (see #1168)
@arnolanglade arnolanglade deleted the resource-config branch December 16, 2014 12:55
pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants