Created
July 18, 2012 10:37
-
-
Save fsuter/3135474 to your computer and use it in GitHub Desktop.
Domain Validator
This file contains hidden or 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
<?php | |
namespace Cobweb\Monitoring\Domain\Validator; | |
/* * | |
* This script belongs to the FLOW3 package "Cobweb.Monitoring". * | |
* * | |
* It is free software; you can redistribute it and/or modify it under * | |
* the terms of the GNU General Public License, either version 3 of the * | |
* License, or (at your option) any later version. * | |
* * | |
* The TYPO3 project - inspiring people to share! * | |
* */ | |
use TYPO3\FLOW3\Annotations as FLOW3; | |
/** | |
* Validator for a complete Instance model | |
*/ | |
class InstanceValidator extends \TYPO3\FLOW3\Validation\Validator\GenericObjectValidator { | |
/** | |
* @FLOW3\Inject | |
* @var \Cobweb\Monitoring\Domain\Repository\InstanceRepository | |
*/ | |
protected $instanceRepository; | |
/** | |
* Checks if an item already uses the given unique key | |
* | |
* @param mixed $object The value that should be validated | |
* @return void | |
*/ | |
protected function isValid($object) { | |
// Try to find an object using the current object's unique key | |
$item = $this->instanceRepository->findByUniqueKey($object->getUniqueKey()); | |
// If an item was found and it's the same as the current object, | |
// the key is not unique, issue an error | |
if ($item->count() > 0 && $item->getFirst() !== $object) { | |
$this->result->forProperty('uniqueKey')->addError( | |
new \TYPO3\FLOW3\Error\Error('The key is already in use', 1342605644) | |
); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment