Skip to content

[Validator] Add a PSR-6 adapter #17440

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 4 commits into from
Closed

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Jan 19, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR todo

@dmaicher
Copy link
Contributor

Ok I did not see your PR before I started working on mine ;P
#17451

Closing mine as this looks very similar 👍

*/
public function has($class)
{
$item = $this->cacheItemPool->getItem($this->escapeClassName($class));
Copy link
Contributor

Choose a reason for hiding this comment

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

simply use return $this->cacheItemPool->hasItem($this->escapeClassName($class)); ?

Copy link
Member Author

Choose a reason for hiding this comment

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

According to the PSR-6, hasItem can in be unreliable:

     * Note: This method MAY avoid retrieving the cached value for performance reasons.
     * This could result in a race condition with CacheItemInterface::get(). To avoid
     * such situation use CacheItemInterface::isHit() instead.

It looks better to me to keep it as is.

Copy link
Member Author

Choose a reason for hiding this comment

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

Performance doesn't matter here, the metadata caching occurs at "compile" time.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dunglas that PSR-6 quote is correct but in this context here it is prone to race conditions anyway if used incorrectly as read() and has() are seperate methods working independently. So your code to retrieve the cache data first for no reason makes no sense and @dmaicher proposal is valid.

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

@dunglas Can you finish this one?

@dunglas
Copy link
Member Author

dunglas commented Jan 26, 2016

Should be ok now.

@fabpot
Copy link
Member

fabpot commented Jan 26, 2016

Thank you @dunglas.

@fabpot fabpot closed this in 37f5264 Jan 26, 2016
@fabpot fabpot reopened this Jan 26, 2016
@fabpot fabpot closed this Jan 26, 2016
*/
private function escapeClassName($class)
{
return strtr($class, '\\', '_');
Copy link
Contributor

Choose a reason for hiding this comment

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

we normalized this sort of operations to str_replace before

@dunglas dunglas deleted the validator_psr6 branch January 26, 2016 18:04
fabpot added a commit that referenced this pull request Jan 27, 2016
This PR was merged into the 3.1-dev branch.

Discussion
----------

[Validator] Minor fixes for the PSR-6 adapter

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | todo

Follows #17440. Take into account comments of @Tobion.

Commits
-------

aa60d5b [Validator] Minor fixes for the PSR-6 adapter
@fabpot fabpot mentioned this pull request May 13, 2016
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.

5 participants