Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the support of the validation in the Builder
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Symfony/Component/DependencyInjection/Configuration/Builder/ValidationBuilder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\DependencyInjection\Configuration\Builder; | ||
|
||
/** | ||
* This class builds validation conditions. | ||
* | ||
* @author Christophe Coevoet <stof@notk.org> | ||
*/ | ||
class ValidationBuilder | ||
{ | ||
public $parent; | ||
public $rules; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Symfony\Component\DependencyInjection\Configuration\Builder\NodeBuilder $parent | ||
*/ | ||
public function __construct($parent) | ||
{ | ||
$this->parent = $parent; | ||
|
||
$this->rules = array(); | ||
} | ||
|
||
/** | ||
* Registers a closure to run as normalization or an expression builder to build it if null is provided. | ||
* | ||
* @param \Closure $closure | ||
* | ||
* @return Symfony\Component\DependencyInjection\Configuration\Builder\ExprBuilder|Symfony\Component\DependencyInjection\Configuration\Builder\ValidationBuilder | ||
*/ | ||
public function rule(\Closure $closure = null) | ||
{ | ||
if (null !== $closure) { | ||
$this->rules[] = $closure; | ||
|
||
return $this; | ||
} | ||
|
||
return $this->rules[] = new ExprBuilder($this->parent); | ||
} | ||
} |