This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Validator/Constraints/Isbn.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2013-01-12 13:38:26 +00:00
<?php
2013-04-20 14:37:23 +01:00
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2013-01-12 13:38:26 +00:00
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\MissingOptionsException;
/**
* @Annotation
2013-04-20 14:37:23 +01:00
*
2013-01-12 13:38:26 +00:00
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
*/
class Isbn extends Constraint
{
public $isbn10Message = 'This value is not a valid ISBN-10.';
public $isbn13Message = 'This value is not a valid ISBN-13.';
public $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.';
public $isbn10;
public $isbn13;
2013-04-20 14:37:23 +01:00
2013-01-12 13:38:26 +00:00
public function __construct($options = null)
{
if (null !== $options && !is_array($options)) {
$options = array(
'isbn10' => $options,
'isbn13' => $options,
);
}
2013-04-20 14:37:23 +01:00
2013-01-12 13:38:26 +00:00
parent::__construct($options);
2013-04-20 14:37:23 +01:00
2013-01-12 13:38:26 +00:00
if (null === $this->isbn10 && null === $this->isbn13) {
2013-04-20 14:37:23 +01:00
throw new MissingOptionsException(sprintf('Either option "isbn10" or "isbn13" must be given for constraint "%s".', __CLASS__), array('isbn10', 'isbn13'));
2013-01-12 13:38:26 +00:00
}
}
2013-04-20 14:37:23 +01:00
}