class Isbn
Validates that a value is a valid ISBN according to ISBN-10 or ISBN-13 formats.
@author The Whole Life To Learn <thewholelifetolearn@gmail.com> @author Manuel Reinhard <manu@sprain.ch> @author Bernhard Schussek <bschussek@gmail.com>
Hierarchy
- class \Symfony\Component\Validator\Constraint
- class \Symfony\Component\Validator\Constraints\Isbn extends \Symfony\Component\Validator\Constraint
Expanded class hierarchy of Isbn
See also
https://en.wikipedia.org/wiki/ISBN
File
-
vendor/
symfony/ validator/ Constraints/ Isbn.php, line 25
Namespace
Symfony\Component\Validator\ConstraintsView source
class Isbn extends Constraint {
public const ISBN_10 = 'isbn10';
public const ISBN_13 = 'isbn13';
public const TOO_SHORT_ERROR = '949acbb0-8ef5-43ed-a0e9-032dfd08ae45';
public const TOO_LONG_ERROR = '3171387d-f80a-47b3-bd6e-60598545316a';
public const INVALID_CHARACTERS_ERROR = '23d21cea-da99-453d-98b1-a7d916fbb339';
public const CHECKSUM_FAILED_ERROR = '2881c032-660f-46b6-8153-d352d9706640';
public const TYPE_NOT_RECOGNIZED_ERROR = 'fa54a457-f042-441f-89c4-066ee5bdd3e1';
protected const ERROR_NAMES = [
self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
self::CHECKSUM_FAILED_ERROR => 'CHECKSUM_FAILED_ERROR',
self::TYPE_NOT_RECOGNIZED_ERROR => 'TYPE_NOT_RECOGNIZED_ERROR',
];
public string $isbn10Message = 'This value is not a valid ISBN-10.';
public string $isbn13Message = 'This value is not a valid ISBN-13.';
public string $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.';
public ?string $type = null;
public ?string $message = null;
/**
* @param self::ISBN_*|array<string,mixed>|null $type The type of ISBN to validate (i.e. {@see Isbn::ISBN_10}, {@see Isbn::ISBN_13} or null to accept both, defaults to null)
* @param string|null $message If defined, this message has priority over the others
* @param string[]|null $groups
* @param array<string,mixed> $options
*/
public function __construct(string|array|null $type = null, ?string $message = null, ?string $isbn10Message = null, ?string $isbn13Message = null, ?string $bothIsbnMessage = null, ?array $groups = null, mixed $payload = null, array $options = []) {
if (\is_array($type)) {
$options = array_merge($type, $options);
}
elseif (null !== $type) {
$options['value'] = $type;
}
parent::__construct($options, $groups, $payload);
$this->message = $message ?? $this->message;
$this->isbn10Message = $isbn10Message ?? $this->isbn10Message;
$this->isbn13Message = $isbn13Message ?? $this->isbn13Message;
$this->bothIsbnMessage = $bothIsbnMessage ?? $this->bothIsbnMessage;
}
public function getDefaultOption() : ?string {
return 'type';
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Constraint::$groups | public | property | The groups that the constraint belongs to. | ||
Constraint::$payload | public | property | Domain-specific data attached to a constraint. | ||
Constraint::addImplicitGroupName | public | function | Adds the given group if this constraint is in the Default group. | 2 | |
Constraint::CLASS_CONSTRAINT | public | constant | Marks a constraint that can be put onto classes. | ||
Constraint::DEFAULT_GROUP | public | constant | The name of the group given to all constraints with no explicit group. | ||
Constraint::getErrorName | public static | function | Returns the name of the given error code. | ||
Constraint::getRequiredOptions | public | function | Returns the name of the required options. | 22 | |
Constraint::getTargets | public | function | Returns whether the constraint can be put onto classes, properties or both. |
8 | |
Constraint::normalizeOptions | protected | function | |||
Constraint::PROPERTY_CONSTRAINT | public | constant | Marks a constraint that can be put onto properties. | ||
Constraint::validatedBy | public | function | Returns the name of the class that validates this constraint. | 9 | |
Constraint::__get | public | function | Returns the value of a lazily initialized option. | 2 | |
Constraint::__isset | public | function | 1 | ||
Constraint::__set | public | function | Sets the value of a lazily initialized option. | 1 | |
Constraint::__sleep | public | function | Optimizes the serialized value to minimize storage space. | ||
Isbn::$bothIsbnMessage | public | property | |||
Isbn::$isbn10Message | public | property | |||
Isbn::$isbn13Message | public | property | |||
Isbn::$message | public | property | |||
Isbn::$type | public | property | |||
Isbn::CHECKSUM_FAILED_ERROR | public | constant | |||
Isbn::ERROR_NAMES | protected | constant | Maps error codes to the names of their constants. | Overrides Constraint::ERROR_NAMES | |
Isbn::getDefaultOption | public | function | Returns the name of the default option. | Overrides Constraint::getDefaultOption | |
Isbn::INVALID_CHARACTERS_ERROR | public | constant | |||
Isbn::ISBN_10 | public | constant | |||
Isbn::ISBN_13 | public | constant | |||
Isbn::TOO_LONG_ERROR | public | constant | |||
Isbn::TOO_SHORT_ERROR | public | constant | |||
Isbn::TYPE_NOT_RECOGNIZED_ERROR | public | constant | |||
Isbn::__construct | public | function | Overrides Constraint::__construct |