-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] add "mapping" configuration key at validation secti… #19086
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
Conversation
Supporting files and directories in the same list would be a better developer experience: #config.yml
framework:
validation:
mapping:
- "path/to/file/validation.yml"
- "path/to/file/validation.xml"
- "path/to/another/directory" |
Check out how the translation does it, would be nice if it's got a similar configuration implementation. |
if you guys prefer to combine files and dirs, then I can do that. |
https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L454 At the translator part it called |
Is there anything I can do to finish this ticket? |
*/ | ||
private function getValidatorMappingFilesFromDir($dir, array &$files) | ||
{ | ||
foreach (Finder::create()->files()->in($dir)->name('/\.xml|yml$/') as $file) { |
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.
.yaml
should be supported I guess ?
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.
indeed
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.
Shouldn't it rather be '/\.(xml|yml)$/'
?
(so '/\.(xml|yml|yaml)$/'
with the .yaml
extension)
EDIT: Then \.(xml|ya?ml)$
according to the comment below.
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 can use ya?ml
too
i've merged the two "files" and "dirs" options to a single "paths" option. |
@@ -180,6 +180,13 @@ | |||
<xsd:attribute name="cache" type="xsd:string" /> | |||
<xsd:attribute name="enable-annotations" type="xsd:boolean" /> | |||
<xsd:attribute name="static-method" type="xsd:boolean" /> | |||
<xsd:attribute name="mapping" type="validation_mapping" /> |
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.
mapping
is no attribute (it must be an element)
Status: Needs work |
@xabbuh can I do anything else? |
$this->getValidatorMappingFilesFromDir($path, $files); | ||
} elseif (is_file($path)) { | ||
if (preg_match('/\.(xml|ya?ml)$/', $path, $matches)) { | ||
$files[$matches[0]][] = realpath($path); |
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.
$matches[0]
will contain the string yaml
when the file extension is .yaml
which would now be ignored.
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 are right. i added a .yaml file extension support and added additional tests.
This sounds like a good solution when not using bundles at all. Anything against merging that? |
@xabbuh: I would like to move on here, what can I do next? |
* Search for validation files in directory. | ||
* | ||
* @param string $dir The directory that contains the validation files | ||
* @param array $files A array reference of validation files |
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.
An array
* Get all validation files. | ||
* | ||
* @param ContainerBuilder $container A ContainerBuilder instance | ||
* @param array $files A array reference of validation files |
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.
An array
* Get all validation files from config. | ||
* | ||
* @param array $config A validation configuration array | ||
* @param array $files A array reference of validation files |
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.
an array
|
||
return $files; | ||
/** | ||
* Search for validation files in directory. |
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.
Searches
} | ||
|
||
/** | ||
* Get all validation files from config. |
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.
Gets
Can you add a note about this new feature in the CHANGELOG? |
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.
👍
@@ -979,41 +982,76 @@ private function registerValidationConfiguration(array $config, ContainerBuilder | |||
} | |||
} | |||
|
|||
private function getValidatorMappingFiles(ContainerBuilder $container) | |||
/** | |||
* Get all validation files. |
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.
Gets
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.
I think the whole phpdoc block can be removed. It does not add that much value (and is for a private method anyway).
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.
Same for the other ones.
Tests do not pass on Windows |
Yes, because $this->assertStringEndsWith('TestBundle/Resources/config/validation.xml', $xmlMappings[1]); appears the error because of my changes? |
@davewwww Apparently, yes |
The problem is solved when I remove the realpath() if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
$files['xml'][] = realpath($file);
} |
@davewwww This now looks good to me. But before I can merge, can you squash your commit or at least rebase on current master (to get rid of the merge commit which prevents me to merge this PR cleanly). Also, can you submit a PR to update the Symfony docs? Between, can you also change the description of this PR to reflect the latest version of this PR? Thanks |
spuashed, pr updated and doc pr submitted |
Thank you @davewwww. |
…alidation secti… (davewwww) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] add "mapping" configuration key at validation secti… | Q | A | | --- | --- | | Bug fix? | no | | New feature? | yes | | BC breaks? | no | | Deprecations? | no | | Tests pass? | yes | | Fixed tickets | #15655 | | License | MIT | | Doc PR | symfony/symfony-docs#7407 | This feature allows you, to define additional validation files or directories which are not in the 'Bundle*/Resources/config/' directory. ``` yaml #config.yml framework: validation: mapping: paths: - "path/to/file/validation.yml" - "path/to/file/validation.xml" - "path/to/another/directory" ``` Commits ------- d696cfb [FrameworkBundle] Configurable paths for validation files 60d7d43 fix merge 61475b5 Merge branch '3.2' ba41e70 Merge branch '3.1' into 3.2 4268aba Merge branch '2.8' into 3.1 3faf655 Merge branch '2.7' into 2.8 e95fc09 fix getMock usage 482828c fix merge ed5eb6d bug #21372 [DependencyInjection] Fixed variadic method parameter in autowired classes (brainexe) a7f63de [DependencyInjection] Fixed variadic method parameter in autowired classes 9ef4271 minor #21371 [Validator] update German translation (xabbuh) f920e61 update German translation 41c72ab minor #21335 [Validator] Improved error message for missing upload_tmp_dir (Breuls) afbf227 [Validator] Improved error message for missing upload_tmp_dir
…es (davewwww) This PR was merged into the master branch. Discussion ---------- [FrameworkBundle] Configurable paths for validation files add doc for symfony/symfony#19086 Commits ------- 793e9e5 [FrameworkBundle] Configurable paths for validation files
foreach ($config['mapping']['paths'] as $path) { | ||
if (is_dir($path)) { | ||
$this->getValidatorMappingFilesFromDir($path, $files); | ||
} elseif (is_file($path)) { |
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 must use the ContainerBuilder API to register resources to invalidate the cache when files are changing in debug mode
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.
indeed, see #21927
…tion mapping (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Add missing resource tracking for validation mapping | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19086 (comment) | License | MIT | Doc PR | n/a https://github.com/symfony/symfony/pull/21927/files?w=1 Commits ------- 0a19cbe Add missing resource tracking for validation mapping
…tion mapping (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Add missing resource tracking for validation mapping | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/symfony#19086 (comment) | License | MIT | Doc PR | n/a https://github.com/symfony/symfony/pull/21927/files?w=1 Commits ------- 0a19cbe Add missing resource tracking for validation mapping
…g paths (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Allow to configure Serializer mapping paths | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21187 | License | MIT | Doc PR | todo Follows #19086 for the Serializer Commits ------- 5446903 [FrameworkBundle] Allow configuring serializer mapping paths
…g paths (chalasr) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Allow to configure Serializer mapping paths | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21187 | License | MIT | Doc PR | todo Follows symfony/symfony#19086 for the Serializer Commits ------- 5446903296 [FrameworkBundle] Allow configuring serializer mapping paths
This feature allows you, to define additional validation files or directories which are not in the 'Bundle*/Resources/config/' directory.