Skip to content

Commit

Permalink
addressing PROCERGS's login-cidadao issue #404
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermednt committed Jul 4, 2016
1 parent 0cf3521 commit f095c43
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
9 changes: 5 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('donato_path_well');
$rootNode = $treeBuilder->root('donato_pathwell');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.
$rootNode
->children()
->booleanNode('enabled')->end()
->end();

return $treeBuilder;
}
Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/DonatoPathWellExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('donato_pathwell.enabled', $config['enabled']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ services:
class: Donato\PathWellBundle\Validator\Constraints\PathWellValidator
arguments:
- "@pathwell.topologies"
- "%donato_pathwell.enabled%"
tags:
- { name: validator.constraint_validator, alias: pathwell_validator }
11 changes: 10 additions & 1 deletion Validator/Constraints/PathWellValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ class PathWellValidator extends ConstraintValidator
/** @var PathWellTopologiesInterface */
private $topologies;

/** @var bool */
private $enabled;

/**
* PathWellValidator constructor.
* @param PathWellTopologiesInterface $topologies
* @param bool $enabled
*/
public function __construct(PathWellTopologiesInterface $topologies)
public function __construct(PathWellTopologiesInterface $topologies, $enabled)
{
$this->topologies = $topologies;
$this->enabled = $enabled;
}

public function validate($value, Constraint $constraint)
Expand All @@ -32,6 +37,10 @@ public function validate($value, Constraint $constraint)
return;
}

if (false === $this->enabled) {
return;
}

$topology = $this->passwordToPathWellTopology($value);
foreach ($this->topologies->getBlacklist() as $rule) {
if (preg_match("#^{$rule}$#", $topology) === 1) {
Expand Down

0 comments on commit f095c43

Please sign in to comment.