Skip to content

[ExpressionLanguage] Making cache PSR6 compliant #19741

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

Merged
merged 1 commit into from
Oct 17, 2016
Merged

[ExpressionLanguage] Making cache PSR6 compliant #19741

merged 1 commit into from
Oct 17, 2016

Conversation

ReDnAxE
Copy link

@ReDnAxE ReDnAxE commented Aug 26, 2016

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR #7064

Adding Cache component compatible ParserCache in ExpressionLanguage component.
I hope you will find it useful :) I would like to make tests also

*/
private $adapter;

public function __construct(AdapterInterface $adapter)
Copy link
Member

Choose a reason for hiding this comment

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

Should be type hinted against Psr\Cache\CacheItemInterface

Copy link
Author

@ReDnAxE ReDnAxE Aug 26, 2016

Choose a reason for hiding this comment

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

You mean Psr\Cache\CacheItemPoolInterface, right ?

Copy link
Member

Choose a reason for hiding this comment

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

yes!

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Aug 26, 2016

New features should be submitted on master (but no need to close this PR: you can either rebase then change the base branch yourself in the github UI, or we can do it while merging).

Btw, shouldn't we deprecate ParserCacheInterface in favor of Psr\Cache\CacheItemPoolInterface?

/**
* @author Alexandre GESLIN <alexandre@gesl.in>
*/
class AdapterParserCache implements ParserCacheInterface
Copy link
Member

Choose a reason for hiding this comment

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

this is not an AdapterParserCache. It is a PSR6ParserCache

@stof
Copy link
Member

stof commented Aug 26, 2016

tests are missing btw

@ReDnAxE
Copy link
Author

ReDnAxE commented Aug 26, 2016

@nicolas-grekas you're right we should deprecate ParserCacheInterface in favor of Psr\Cache\CacheItemPoolInterface.

But what does this involve in EL component ?

I can add @deprecated tag on ParserCacheInterface ? And then, how to stop use of ParserCacheInterface in ExpressionLanguage without creating BC break ? I mean, changing type hint on ExpressionLanguage::__construct is not conceivable, right ?

This is my first PR tentative, so be indulgent ^^ hope my questions are not too boring

@nicolas-grekas
Copy link
Member

add @deprecated tag on ParserCacheInterface

yes

changing type hint on ExpressionLanguage::__construct

yes! by removing the type hint (not replacing it with CacheItemPoolInterface), then doing dynamic checks in the constructor and triggering a deprecation when required

@ReDnAxE ReDnAxE changed the title [ExpressionLanguage] adding cache component compatible ParserCache [ExpressionLanguage] Making cache PSR6 compliant Aug 28, 2016
@ReDnAxE
Copy link
Author

ReDnAxE commented Aug 28, 2016

Thanks for your help @nicolas-grekas.
I've made some changes in order to make cache PSR6 compliant, using adapter pattern.

I have a few other questions :

  • I use Symfony\Component\Cache\Adapter\ArrayAdapter by default in ExpressionLanguage.php. Is it a bad thing to hard coupling with Cache component ? Perhaps it's better to use the existing ArrayParserCache with the adapter.
  • With PSR6 specifications, some characters are forbidden in keys declarations. For now my sanitize method is not sufficient, but I don't know exactly how to assure unique keys with expressions. Replacing with a hash ?

{
$this->cache = $cache ?: new ArrayParserCache();
if (null !== $cache && false === is_a($cache, CacheItemPoolInterface::class)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be:

if (null !== $cache && !$cache instanceof CacheItemPoolInterface) {

Since 5.0.0 :P

This function became deprecated in favour of the instanceof operator. Calling this function will result in an E_STRICT warning.

Copy link
Member

Choose a reason for hiding this comment

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

even shorter: if ($cache instanceof ParserCacheInterface) {

@trigger_error(sprintf('Passing an instance of %s as constructor argument for %s is deprecated as of 3.2 and will be removed in 4.0. Pass an instance of %s instead.', ParserCacheInterface::class, self::class, CacheItemPoolInterface::class), E_USER_DEPRECATED);
$cache = new ParserCacheAdapter($cache);
} elseif (!$cache instanceof CacheItemPoolInterface) {
throw new \InvalidArgumentException(sprintf('Cache argument has to implements %s.', CacheItemPoolInterface::class));
Copy link
Member

Choose a reason for hiding this comment

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

implement

public function getItem($key)
{
$value = $this->pool->fetch($key);
$f = $this->createCacheItem;
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary?

Copy link
Author

@ReDnAxE ReDnAxE Sep 30, 2016

Choose a reason for hiding this comment

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

Yes, not working with $this->createCacheItem($key, $value, $isHit);
picked up here https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php#L75

@xabbuh
Copy link
Member

xabbuh commented Sep 30, 2016

👍

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

Could someone explain me why in the last build PHP:7 deph=high, I have 54 errors in Symfony\Bundle\SecurityBundle\Tests\Functional ?

Here is the exception thrown all the time :
Symfony\Component\DependencyInjection\Exception\LogicException: Asset support cannot be enabled as the Asset component is not installed.

@fabpot
Copy link
Member

fabpot commented Sep 30, 2016

@ReDnAxE Should be fixed now

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

@stof with a @trigger_error in ParserCache\ParserCacheInterface.php as you asked, PHP:7 deph=high was broken as explained above, I could not explain why.
@fabpot Builds are ok.

@nicolas-grekas
Copy link
Member

I thinkwe should try harder following @stof's advice. The tests don't decide.

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

@nicolas-grekas I agree... This is why I prefer to mention him

@nicolas-grekas
Copy link
Member

Can you add the trigger again so that we can see what's failing in the tests?

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

@nicolas-grekas Why not ! I re-push the @trigger_error.
I confess I do not understand. Now, it's no more the same errors : we have fails in PHP7 dep=high|low in TwigBundle Test Suite

With the same Symfony\Component\DependencyInjection\Exception\LogicException exception type thrown as before

@nicolas-grekas
Copy link
Member

Not related I guess

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

I rebased my branch to 533c11c (master)
I will rebase one more time

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

I rebased on 418944b
same errors... uh no, worst, 1 error in appVeyor o_O :
Symfony\Component\HttpKernel\Tests\ClientTest::testGetScript RuntimeException: OUTPUT: ERROR OUTPUT:

@ReDnAxE
Copy link
Author

ReDnAxE commented Sep 30, 2016

I know we are in 1 october, so it's probably too late ^^, but I saw master is not stable on the last 418944b commit. Perhaps I would rebase on a older stable master commit ?

EDIT: I'm on c2d8356 now. Appveyor recovered..! good night ;)

@ReDnAxE
Copy link
Author

ReDnAxE commented Oct 3, 2016

@nicolas-grekas it works better when rebasing on master's clean commit ;)
I changed deprecation notices versions from "3.2" to "3.3"

@xabbuh
Copy link
Member

xabbuh commented Oct 3, 2016

Please also add the deprecation in the upgrade files.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 5, 2016

I changed deprecation notices versions from "3.2" to "3.3"

why that? that could still happen for 3.2 , who knows :)
also please add a note in the upgrade files as suggested by @xabbuh

/**
* @author Alexandre GESLIN <alexandre@gesl.in>
*
* @internal
Copy link
Member

Choose a reason for hiding this comment

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

You add a comment to indicate that this class should be removed in 4.0.

@fabpot
Copy link
Member

fabpot commented Oct 6, 2016

Indeed, I'd like to include that in 3.2 if possible.

@xabbuh
Copy link
Member

xabbuh commented Oct 6, 2016

👍 from me after the remaining comments have been addressed

@ReDnAxE
Copy link
Author

ReDnAxE commented Oct 6, 2016

Thank's ! I'll make thoses changes this afternoon :) I learned that features was freezed for 3.2. This is why I changed to 3.3

@ReDnAxE
Copy link
Author

ReDnAxE commented Oct 6, 2016

The changes are done.

@ReDnAxE
Copy link
Author

ReDnAxE commented Oct 17, 2016

ping @nicolas-grekas ;)

@fabpot
Copy link
Member

fabpot commented Oct 17, 2016

Thank you @ReDnAxE.

@fabpot fabpot merged commit a7352ff into symfony:master Oct 17, 2016
fabpot added a commit that referenced this pull request Oct 17, 2016
…andre GESLIN)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[ExpressionLanguage] Making cache PSR6 compliant

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | [#7064](symfony/symfony-docs#7064)

Adding Cache component compatible ParserCache in ExpressionLanguage component.
I hope you will find it useful :) I would like to make tests also

Commits
-------

a7352ff [ExpressionLanguage] Making cache PSR6 compliant
@fabpot fabpot mentioned this pull request Oct 27, 2016
wouterj added a commit to symfony/symfony-docs that referenced this pull request Nov 10, 2016
This PR was merged into the master branch.

Discussion
----------

Update caching.rst

Updating doc for this PR Making cache PSR6 compliant : [#19741](symfony/symfony#19741)

Commits
-------

f03f2f3 Update caching.rst
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.

10 participants