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

Add configureSettings to block service #204

Merged
merged 1 commit into from
Jun 14, 2015
Merged

Add configureSettings to block service #204

merged 1 commit into from
Jun 14, 2015

Conversation

soullivaneuh
Copy link
Member

AbstractBlockService::configureSettings fixes Symfony deprecation issue.
BlockServiceInterface::setDefaultSettings is now deprecated.

Fixes #201

@rande Please don't merge it now! :-)

@soullivaneuh soullivaneuh self-assigned this Jun 11, 2015
@soullivaneuh soullivaneuh changed the title [WIP] Add configureSettings to block service Add configureSettings to block service Jun 11, 2015
@soullivaneuh
Copy link
Member Author

I have to check against built-in services.

@soullivaneuh soullivaneuh changed the title Add configureSettings to block service [WIP] Add configureSettings to block service Jun 11, 2015
@soullivaneuh soullivaneuh changed the title [WIP] Add configureSettings to block service Add configureSettings to block service Jun 11, 2015
$service = $this->blockService->get($block);
$service->setDefaultSettings($optionsResolver, $block);

$reflector = new \ReflectionMethod($service, 'setDefaultSettings');
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be compute once with a CompilerPass to avoid performance impact on using the reflection API.

Copy link
Member Author

Choose a reason for hiding this comment

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

How a CompilerPass will help to detect and throw deprecation errors?

I did the same method as Symfony. Please see: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/ResolvedFormType.php#L201-L207

Copy link
Member

Choose a reason for hiding this comment

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

You can store an array with the result of the reflection and still send a trigger. Or at least store the result for one service to avoid doing the same over and over if a Page is composed of the same block.

Copy link
Member Author

Choose a reason for hiding this comment

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

To be honest, I have some difficulties to see what you want.

Can you maybe propose a PR on this one to show me?

Copy link
Member

Choose a reason for hiding this comment

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

Something like this.

$this->reflectionCache = [
 'class\path' => ['isOldOverwritten' => true|false, 'isNewOverwritten' => true|false
];


$class = get_class($service);
if ($this->reflectionCache[$class]['isOldOverwritten'] && !$this->reflectionCache[$class]['isNewOverwritten']) {
        trigger_error('The Sonata\BlockBundle\Block\BlockServiceInterface::setDefaultSettings() method is deprecated since version 2.3 and will be removed in 3.0. Use configureSettings() instead. This method will be added to the BlockServiceInterface with SonataBlockBundle 3.0.', E_USER_DEPRECATED);
 }

Copy link
Member

Choose a reason for hiding this comment

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

The reflectionCache cache attribute can either be compute once at with a CompilerPass or at runtime.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I'll try. 👍

@soullivaneuh
Copy link
Member Author

@rande Reflection cache is on the place. 👍

@rande
Copy link
Member

rande commented Jun 12, 2015

Did you plan to add unit test ?

@soullivaneuh
Copy link
Member Author

@rande Unit tests are already here for those classes.

I'm missing something?

AbstractBlockService::configureSettings fixes Symfony deprecation issue.
BlockServiceInterface::setDefaultSettings is now deprecated.
@soullivaneuh
Copy link
Member Author

Tests updated to fix deprecation notice errors.

AFAIK, the coverage still the same.

soullivaneuh added a commit that referenced this pull request Jun 14, 2015
Add configureSettings to block service
@soullivaneuh soullivaneuh merged commit 31886b2 into sonata-project:master Jun 14, 2015
@soullivaneuh soullivaneuh deleted the block-service-settings branch June 14, 2015 12:20
*
* @var array
*/
private $reflectionCache;

Choose a reason for hiding this comment

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

There is no need to cache reflection objects. See this benchmark: https://gist.github.com/mindplay-dk/3359812

@sagikazarmark
Copy link

@soullivaneuh PR sent for all the remaining open issues

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

Successfully merging this pull request may close these issues.

None yet

3 participants