Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 68 lines (57 sloc) 1.612 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
<?php

/**
* This file is part of the PropelBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Propel\PropelBundle\Validator\Constraint;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* Constraint for the Unique Object validator
*
* @author Maxime AILLOUD <maxime.ailloud@gmail.com>
* @author Marek Kalnik <marekk@theodo.fr>
*/
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();

    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.");
        }
    }

    /**
* {@inheritDoc}
*/
    public function getRequiredOptions()
    {
        return array('fields');
    }

    /**
* {@inheritDoc}
*/
    public function getTargets()
    {
        return self::CLASS_CONSTRAINT;
    }
}
Something went wrong with that request. Please try again.