Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to split the validation.yml file
<?php
namespace Acme\BlogBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
class AcmeBlogExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
$loader->load('listeners.yml');
$this->loadValidationConfiguration($container);
}
protected function loadValidationConfiguration(ContainerBuilder $container)
{
$yamlMappingFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$yamlMappingFiles[] = __DIR__.'/../Resources/config/validation/Post.yml';
$yamlMappingFiles[] = __DIR__.'/../Resources/config/validation/Comment.yml';
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $yamlMappingFiles);
}
}
Acme\BlogBundle\Entity\Comment
properties:
username:
- NotBlank: ~
- MaxLength: 50
email:
- Email: ~
comment:
- NotBlank: ~
- MinLength: 50
Acme\BlogBundle\Entity\Post:
properties:
title:
- NotBlank: ~
body:
- MinLength: 50
Acme\BlogBundle\Entity\Comment
properties:
username:
- NotBlank: ~
- MaxLength: 50
email:
- Email: ~
comment:
- NotBlank: ~
- MinLength: 50
Acme\BlogBundle\Entity\Post:
properties:
title:
- NotBlank: ~
body:
- MinLength: 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.