* @author Marek Kalnik */ class UniqueObject extends Constraint { /** * @var string */ public $message = 'A {{ object_class }} object already exists with {{ fields }}'; /** * @var string Used to merge multiple fields in the message */ public $messageFieldSeparator = ' and '; /** * @var array */ public $fields = array(); /** * @var string Used to set the path where the error will be attached, default is global. */ public $errorPath; public function __construct($options = null) { parent::__construct($options); if (!is_array($this->fields) && !is_string($this->fields)) { throw new UnexpectedTypeException($this->fields, 'array'); } if (0 === count($this->fields)) { throw new ConstraintDefinitionException("At least one field must be specified."); } if (null !== $this->errorPath && !is_string($this->errorPath)) { throw new UnexpectedTypeException($this->errorPath, 'string or null'); } } /** * {@inheritDoc} */ public function getRequiredOptions() { return array('fields'); } /** * {@inheritDoc} */ public function getTargets() { return self::CLASS_CONSTRAINT; } }