Commit 6dfc390b authored by Fabien Potencier's avatar Fabien Potencier

added an extension for the Symfony2 Validator component

parent 628714a2
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex\Extension;
use Silex\Application;
use Silex\ExtensionInterface;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
use Symfony\Component\Validator\ConstraintValidatorFactory;
class ValidationExtension implements ExtensionInterface
{
public function register(Application $app)
{
$app['validator'] = $app->share(function () use ($app) {
return new Validator(
$app['validator.mapping.class_metadata_factory'],
$app['validator.validator_factory']
);
});
$app['validator.mapping.class_metadata_factory'] = $app->share(function () use ($app) {
return new ClassMetadataFactory(new StaticMethodLoader());
});
$app['validator.validator_factory'] = $app->share(function () {
return new ConstraintValidatorFactory();
});
if (isset($app['validation.class_path'])) {
$app['autoloader']->registerNamespace('Symfony\\Component\\Validation', $app['validation.class_path']);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment