Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
eaf0af2a
Commit
eaf0af2a
authored
Feb 10, 2013
by
alexkappa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ported ConstraintValidatorFactory.php to Silex/Pimple
parent
a23c221e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
src/Silex/ConstraintValidatorFactory.php
src/Silex/ConstraintValidatorFactory.php
+73
-0
No files found.
src/Silex/ConstraintValidatorFactory.php
0 → 100644
View file @
eaf0af2a
<?php
/*
* This file is part of the Symfony package.
*
* (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
;
use
Symfony\Component\Validator\Constraint
;
use
Symfony\Component\Validator\ConstraintValidatorFactoryInterface
;
use
Symfony\Component\Validator\ConstraintValidator
;
/**
* Uses a service container to create constraint validators.
*
* A constraint validator should be tagged as "validator.constraint_validator"
* in the service container and include an "alias" attribute:
*
* <service id="some_doctrine_validator">
* <argument type="service" id="doctrine.orm.some_entity_manager" />
* <tag name="validator.constraint_validator" alias="some_alias" />
* </service>
*
* A constraint may then return this alias in its validatedBy() method:
*
* public function validatedBy()
* {
* return 'some_alias';
* }
*
* @author Kris Wallsmith <kris@symfony.com>
*/
class
ConstraintValidatorFactory
implements
ConstraintValidatorFactoryInterface
{
protected
$container
;
protected
$validators
;
/**
* Constructor.
*
* @param array $validators An array of validators
*/
public
function
__construct
(
$container
,
array
$validators
=
array
())
{
$this
->
container
=
$container
;
$this
->
validators
=
$validators
;
}
/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
*
* @return ConstraintValidator A validator for the supplied constraint
*/
public
function
getInstance
(
Constraint
$constraint
)
{
$name
=
$constraint
->
validatedBy
();
if
(
!
isset
(
$this
->
validators
[
$name
]))
{
$this
->
validators
[
$name
]
=
new
$name
();
}
elseif
(
is_string
(
$this
->
validators
[
$name
]))
{
$this
->
validators
[
$name
]
=
$this
->
container
[
$this
->
validators
[
$name
]];
}
return
$this
->
validators
[
$name
];
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment