Skip to content

[FrameworkBundle] "mappings" for validation #13878

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

Conversation

davewwww
Copy link
Contributor

@davewwww davewwww commented Mar 9, 2015

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #15655
License MIT
Doc PR

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:
      files:
        - "path/to/file/validation.yml"
        - "path/to/file/validation.xml"
      dirs: 
        - "path/to/another/directory"

@davewwww davewwww changed the title "mappings" for validation [FrameworkBundle] "mappings" for validation Mar 9, 2015
@GromNaN
Copy link
Member

GromNaN commented Mar 9, 2015

You shouldn't have to specify the file type in the config. This is already specified by the file extension.

@davewwww
Copy link
Contributor Author

davewwww commented Mar 9, 2015

Ok, for the "$container->addResource()" statement I dont need the file extension.
But at the switch between "$yamlMappings[]" & "$xmlMappings[]" I need a indicator, otherwise i have to guess and that's a little bit magicly ...

@davewwww
Copy link
Contributor Author

davewwww commented Mar 9, 2015

locks better?

if (preg_match('/\.(yml|xml)$/', $file, $matches)) {
    if ('yml' === $matches[1]) {
        $yamlMappings[] = $file;
    } elseif ('xml' === $matches[1]) {
        $xmlMappings[] = $file;
    }
}

@GromNaN
Copy link
Member

GromNaN commented Mar 9, 2015

Yes. That's the idea.

@webmozart
Copy link
Contributor

I think the proper solution would be to rely on Puli in 3.0, if it gets included.

@ZeeCoder
Copy link

ZeeCoder commented Sep 3, 2015

I would be glad to have a feature something like this. 👍
I like to separate my PHP code from basically everything else. (usually the yml conf files)
Right now I have to have the Resources/config folder in my AppBundle just to load the validation rules from there.

I would just drop that in the app/config folder, where all the other configurations reside already.

->arrayNode('mappings')
->prototype('array')
->children()
->scalarNode('file')->end()
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason to have an extra file key here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in preparation for the "dir" key to include all mapping files automatically from this directory.

Copy link
Member

Choose a reason for hiding this comment

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

Why not allow to mix files and directories and make the distinction in the extension?

Copy link
Member

Choose a reason for hiding this comment

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

Or if you want to keep them separated, I would use mappings.files and mappings.dirs or something like that as different lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could be a solution, like is_file($path) and is_dir($path)?

Copy link
Member

Choose a reason for hiding this comment

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

mapping would become a singular in such case though, as you would have a single node for it though.

I agree with @xabbuh though. The prototyped node should not be mappings if you only configure either file or dir in it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you think:

framework:
  validation:
    mapping:
      files:
        - ".../validation.yml"
      dirs:
        - ".../config/validations"

@fabpot
Copy link
Member

fabpot commented Oct 5, 2015

Looks like a good idea to me, @davewwww Can you take the comments into account?

@davewwww
Copy link
Contributor Author

davewwww commented Oct 5, 2015

I've changed the configuration and added the directory feature.
What do you say?

$files[$ext][] = $file;
}

if (count($files['xml']) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO !empty($files['xml']) will be faster and more memory efficient.

…on to define extra validation files or directories which are not in the 'Bundle*/Resources/config' directory.
@davewwww
Copy link
Contributor Author

davewwww commented Oct 6, 2015

ok, i've separated the framework-defined files from the user-defined files and removed the addResource().

@xabbuh
Copy link
Member

xabbuh commented Oct 6, 2015

Can you also update the XSD file of the FrameworkBundle config?

@davewwww
Copy link
Contributor Author

davewwww commented Oct 6, 2015

i've never used this xsd feature.
Maybe like this:

   ...
    <xsd:complexType name="validation">
        ...
        <xsd:attribute name="mapping" type="validation_mapping" />
    </xsd:complexType>

    <xsd:complexType name="validation_mapping">
        <xsd:sequence>
            <xsd:element name="file" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
            <xsd:element name="dir" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
    </xsd:complexType>
   ...

@wouterj
Copy link
Member

wouterj commented Apr 16, 2016

@davewwww yes, that looks correct.

@ogizanagi
Copy link
Contributor

Any update about this feature ?

@fabpot
Copy link
Member

fabpot commented Jun 16, 2016

@davewwww Do you have time to finish this feature? It looks like we are almost there. Thanks. It would also need to be resubmitted on current master, but that should not be too difficult.

@davewwww
Copy link
Contributor Author

@fabpot i created a merge request on the current master: #19086

@fabpot
Copy link
Member

fabpot commented Jun 17, 2016

Thanks!

@fabpot fabpot closed this Jun 17, 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.