Skip to content

[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

Merged
merged 1 commit into from
Jan 23, 2017

Conversation

davewwww
Copy link
Contributor

@davewwww davewwww commented Jun 17, 2016

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.

#config.yml
framework:
  validation:
    mapping:
      paths:
        - "path/to/file/validation.yml"
        - "path/to/file/validation.xml"
        - "path/to/another/directory"

@GromNaN
Copy link
Member

GromNaN commented Jun 17, 2016

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"

@linaori
Copy link
Contributor

linaori commented Jun 17, 2016

Check out how the translation does it, would be nice if it's got a similar configuration implementation.

@davewwww
Copy link
Contributor Author

davewwww commented Jun 17, 2016

if you guys prefer to combine files and dirs, then I can do that.

@linaori
Copy link
Contributor

linaori commented Jun 17, 2016

@davewwww
Copy link
Contributor Author

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) {
Copy link
Contributor

@GuilhemN GuilhemN Jun 23, 2016

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 ?

Copy link
Member

Choose a reason for hiding this comment

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

indeed

Copy link
Contributor

@ogizanagi ogizanagi Jun 24, 2016

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.

Copy link
Contributor

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

@GuilhemN
Copy link
Contributor

@iltar the translations are meant to be put in a folder as there are at least two versions of the same file but the validation files can be in the root of a config folder so imo we should support files and dirs.

@davewwww isn't it possible to merge the two config options under paths ?

@davewwww
Copy link
Contributor Author

davewwww commented Jun 30, 2016

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" />
Copy link
Member

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)

@xabbuh
Copy link
Member

xabbuh commented Jul 4, 2016

Status: Needs work

@davewwww
Copy link
Contributor Author

davewwww commented Jul 6, 2016

@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);
Copy link
Member

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.

Copy link
Contributor Author

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.

@lunetics
Copy link

This sounds like a good solution when not using bundles at all. Anything against merging that?

@davewwww
Copy link
Contributor Author

@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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Gets

@fabpot
Copy link
Member

fabpot commented Jan 10, 2017

Can you add a note about this new feature in the CHANGELOG?

Copy link
Contributor

@HeahDude HeahDude left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Gets

Copy link
Member

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).

Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Jan 20, 2017

Tests do not pass on Windows

@davewwww
Copy link
Contributor Author

Yes, because
TestBundle\Resources\config\validation.xml
is not:
TestBundle/Resources/config/validation.xml

$this->assertStringEndsWith('TestBundle/Resources/config/validation.xml', $xmlMappings[1]);

appears the error because of my changes?

@fabpot
Copy link
Member

fabpot commented Jan 20, 2017

@davewwww Apparently, yes

@davewwww
Copy link
Contributor Author

The problem is solved when I remove the realpath()

if (is_file($file = $dirname.'/Resources/config/validation.xml')) {
   $files['xml'][] = realpath($file);
 }

@fabpot
Copy link
Member

fabpot commented Jan 22, 2017

@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

@davewwww
Copy link
Contributor Author

spuashed, pr updated and doc pr submitted

@fabpot
Copy link
Member

fabpot commented Jan 23, 2017

Thank you @davewwww.

@fabpot fabpot merged commit d696cfb into symfony:master Jan 23, 2017
fabpot added a commit that referenced this pull request Jan 23, 2017
…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
xabbuh added a commit to symfony/symfony-docs that referenced this pull request Feb 3, 2017
…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)) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

indeed, see #21927

nicolas-grekas added a commit that referenced this pull request Mar 9, 2017
…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
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Mar 9, 2017
…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
fabpot added a commit that referenced this pull request Mar 22, 2017
…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
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Mar 22, 2017
…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
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
@fabpot fabpot mentioned this pull request May 1, 2017
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.