Skip to content

[FrameworkBundle] add configuration for the Property Accessor #7978

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

Closed
wants to merge 1 commit into from

Conversation

jaugustin
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets none
License MIT
Doc PR not yet done

This allow to configure the property accessor to enable magic __call feature

# config.yml
framework:
    property_accessor:
        magic_call: true #default is false

@bschussek

@wouterj
Copy link
Member

wouterj commented May 8, 2013

Hmm, I think I'm -1 for this one. Configuration is meaned for global objects imo, PropertyAccessor is not a global object.

@webmozart
Copy link
Contributor

@wouterj How do you come to this conclusion? Of course this object is global.

@wouterj
Copy link
Member

wouterj commented May 8, 2013

@bschussek imo, PropertyAccessor is the same as the Finder object. You will instantiate a new object when using it.

@jaugustin
Copy link
Contributor Author

@wouterj yes but when you use it as a service it has to be configured or you should do that :
https://gist.github.com/jaugustin/5541041#file-footballertype-php-L22

@webmozart
Copy link
Contributor

@wouterj That's not a very good practice. In future versions of Symfony, we will support code generation in the PropertyAccessor to optimize its performance. So you will have something like this:

$accessor = PropertyAccess::getPropertyAccessorBuilder()
    ->setCacheDir('/path/to/cache')
    ->enableMagicCall()
    ->disableMagicGetSet()
    ->getPropertyAccessor();

once in your application and then reuse this object. Of course you can also instantiate it when you need it, but then you need to configure it anew everytime (or lose the performance benefit).

@@ -100,6 +100,13 @@ private function addFormSection(ArrayNodeDefinition $rootNode)
->scalarNode('field_name')->defaultValue('_token')->end()
->end()
->end()
->arrayNode('property_accessor')
->info('property accessor configuration')
->canBeEnabled()
Copy link
Member

Choose a reason for hiding this comment

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

canBeEnabled is not needed here. The property_accessor service is not a service that you can remove by disabling it in the config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof ok how to make it optionnal ?

Copy link
Member

Choose a reason for hiding this comment

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

->arrayNode('property_accessor') 
    ->info('property accessor configuration') 
    ->addDefaultsIfNotSet()
    ->children() 
         ->booleanNode('magic_call')->defaultFalse()->end() 
    ->end()
->end()

Copy link
Member

Choose a reason for hiding this comment

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

and then simply $container->setParameter('property_accessor.magic_call.enabled', $config['property_accessor']['magic_call']);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stof thanks, fixed

@jaugustin
Copy link
Contributor Author

@bschussek @fabpot any news on this ?

@@ -128,7 +131,7 @@ protected static function getBundleDefaultConfig()
'debug' => '%kernel.debug%',
),
'serializer' => array(
'enabled' => false
'enabled' => false
Copy link
Contributor

Choose a reason for hiding this comment

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

better also to put a comma at the end

@fabpot
Copy link
Member

fabpot commented Sep 23, 2014

Closing this PR as it landed in 2.6 via #11731

@fabpot fabpot closed this Sep 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants