-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Introduce MetadataValidators to test arbitrary metadata for freshness. #15692
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
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
60b4089
Introduce MetadataValidators to test arbitrary metadata for freshness.
bnw 673070b
Added trailing newline
bnw ab39129
Added new parameter to interface
bnw 9546be9
Renamed ResourceValidator to ResourceInterfaceValidator
bnw 0342b73
Added missing import
bnw 7aee891
Correcting classname after renaming
bnw df526c0
Added ConfigCachePass to framework
bnw 2555d5a
Fixed UnitTests
bnw 4145dc0
Bugfix
bnw 2e49fb2
Better name
bnw d0f1e2d
Fix test
mpdude 3f9424f
Add docblock
mpdude b8bb60a
Fix tests while keeping ConfigCacheFactory unchanged (from a client p…
mpdude 2fac8f3
Hello Fabbot
mpdude 1b62130
Forgot import statement
mpdude b16d9de
The new ConfigCachePass is required
mpdude 97a2cd0
Bump deps
mpdude aae0a78
Avoid changing the interface
mpdude 024aa8c
Also validate this method in the interface
mpdude d617943
Rename ResourceInterfaceValidator to ResourceValidator as suggested o…
mpdude 8907a21
Oh Fabbot
mpdude e471890
Add a note why the ResourceInterface::__toString method is important …
mpdude e9fd197
Remove totally broken test
mpdude 53ad659
Rewrite ConfigCacheTest because it made many assumptions about how th…
mpdude 594529c
Fix ConfigCache and improve docblock
mpdude 32426ce
If I had to pay just $0.02 for every Fabbot complaint, Fabien would b…
mpdude f3470e3
Document deprecation in the CHANGELOG file
mpdude 7739878
Some more tweaks to the ConfigCacheTest
mpdude f9c48a0
Remove unused import
mpdude c0f416d
Continue with next resource, not next validator
mpdude 00b4efb
Add a shortcut for when we don't have any validators (might be in prod)
mpdude 23a4464
Create a new ValidatorConfigCache class and pass metadata validators …
mpdude caf6bf1
Fabbot
mpdude 37c96e1
This is not relevant for this PR
mpdude 7bc5ba2
Tweaks as suggested on GH
mpdude f5add4c
Implement the plan(TM)
mpdude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix tests while keeping ConfigCacheFactory unchanged (from a client p…
…erspective)
- Loading branch information
commit b8bb60a7cdba5757c75e516b28244875acacefa3
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/Symfony/Component/Config/ValidatorConfigCacheFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Config; | ||
|
||
/** | ||
* A ConfigCacheFactory implementation that validates the | ||
* cache with an arbitrary set of metadata validators. | ||
* | ||
* @author Matthias Pigulla <mp@webfactory.de> | ||
*/ | ||
class ValidatorConfigCacheFactory implements ConfigCacheFactoryInterface | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $debug; | ||
|
||
/** | ||
* @var MetadataValidatorInterface[] | ||
*/ | ||
private $validators = array(); | ||
|
||
/** | ||
* @param bool $debug The debug flag to pass to ConfigCache | ||
*/ | ||
public function __construct($debug) | ||
{ | ||
$this->debug = $debug; | ||
} | ||
|
||
/** | ||
* @param MetadataValidatorInterface $validator | ||
*/ | ||
public function addValidator(MetadataValidatorInterface $validator) | ||
{ | ||
$this->validators[] = $validator; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function cache($file, $callback) | ||
{ | ||
if (!is_callable($callback)) { | ||
throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback))); | ||
} | ||
|
||
$cache = new ConfigCache($file, $this->debug); | ||
if (!$cache->isFresh($this->validators)) { | ||
call_user_func($callback, $cache); | ||
} | ||
|
||
return $cache; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why creating a whole new config cache factory given adding validators to the old one is doable without BC break ? (But will prevent the deprecation due to https://github.com/symfony/symfony/pull/15692/files#diff-9f40590069e1fa6582e56bcea49e09a4R77)
Will the
ConfigCacheFactory
trigger a deprecation saying to use the newValidatorConfigCacheFactory
instead ?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.
For BC reasons, the
Router
andTranslator
need to create aConfigCacheFactory
themselves if none is injected. If that factory comes without the defaultResourceInterfaceValidator
, they'd have to add one themselves and that would cause unnecessary dependencies. Having a defaultResourceInterfaceValidator
inConfigCacheFactory
would be weird as well.So this way, use a
ConfigCacheFactory
if you don't care about special validations and you'll get the same behaviour as in the past.Use a ValidatorConfigCacheFactory if you care about special validations or if you get the instance injected anyway and don't care about the hassle of setting it up.