This repository has been archived by the owner on Mar 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ph-ash/fix-stop-push-into-leafs
Decline pushes into leafs
- Loading branch information
Showing
7 changed files
with
85 additions
and
16 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use Symfony\Component\Validator\Constraint; | ||
|
||
class IsLeaf extends Constraint | ||
{ | ||
public $message = 'Path \'{{path}}\' includes a MonitoringData leaf, please change your path'; | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Validator\Constraints; | ||
|
||
use App\Exception\PersistenceLayerException; | ||
use App\Repository\MonitoringData as MonitoringDataRepository; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
|
||
class IsLeafValidator extends ConstraintValidator | ||
{ | ||
private $monitoringDataRepository; | ||
|
||
public function __construct(MonitoringDataRepository $monitoringDataRepository) | ||
{ | ||
$this->monitoringDataRepository = $monitoringDataRepository; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @throws PersistenceLayerException | ||
* @throws UnexpectedTypeException | ||
*/ | ||
public function validate($value, Constraint $constraint): void | ||
{ | ||
if (!$constraint instanceof IsLeaf) { | ||
throw new UnexpectedTypeException($constraint, IsLeaf::class); | ||
} | ||
|
||
if (($value !== null) && $this->monitoringDataRepository->isLeafIncludedInPath($value)) { | ||
$this->context->buildViolation($constraint->message) | ||
->setParameter('{{path}}', $value) | ||
->addViolation(); | ||
} | ||
} | ||
} |