-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
[ExpressionLanguage] Making cache PSR6 compliant #19741
Conversation
*/ | ||
private $adapter; | ||
|
||
public function __construct(AdapterInterface $adapter) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes!
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 |
/** | ||
* @author Alexandre GESLIN <alexandre@gesl.in> | ||
*/ | ||
class AdapterParserCache implements ParserCacheInterface |
There was a problem hiding this comment.
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
tests are missing btw |
@nicolas-grekas you're right we should deprecate But what does this involve in EL component ? I can add This is my first PR tentative, so be indulgent ^^ hope my questions are not too boring |
yes
yes! by removing the type hint (not replacing it with CacheItemPoolInterface), then doing dynamic checks in the constructor and triggering a deprecation when required |
Thanks for your help @nicolas-grekas. I have a few other questions :
|
{ | ||
$this->cache = $cache ?: new ArrayParserCache(); | ||
if (null !== $cache && false === is_a($cache, CacheItemPoolInterface::class)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
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
👍 |
Could someone explain me why in the last build Here is the exception thrown all the time : |
@ReDnAxE Should be fixed now |
I thinkwe should try harder following @stof's advice. The tests don't decide. |
@nicolas-grekas I agree... This is why I prefer to mention him |
Can you add the trigger again so that we can see what's failing in the tests? |
@nicolas-grekas Why not ! I re-push the With the same |
Not related I guess |
I rebased my branch to 533c11c (master) |
I rebased on 418944b |
@nicolas-grekas it works better when rebasing on master's clean commit ;) |
Please also add the deprecation in the upgrade files. |
why that? that could still happen for 3.2 , who knows :) |
/** | ||
* @author Alexandre GESLIN <alexandre@gesl.in> | ||
* | ||
* @internal |
There was a problem hiding this comment.
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.
Indeed, I'd like to include that in 3.2 if possible. |
👍 from me after the remaining comments have been addressed |
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 |
The changes are done. |
ping @nicolas-grekas ;) |
Thank you @ReDnAxE. |
…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
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
Adding Cache component compatible ParserCache in ExpressionLanguage component.
I hope you will find it useful :) I would like to make tests also