Skip to content

Instantly share code, notes, and snippets.

@K-Phoen
Created October 14, 2013 11:55
Show Gist options
  • Save K-Phoen/6974497 to your computer and use it in GitHub Desktop.
Save K-Phoen/6974497 to your computer and use it in GitHub Desktop.
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