Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Add PHPDoc to Isbn attribute class and properties #53424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion 41 src/Symfony/Component/Validator/Constraints/Isbn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Symfony\Component\Validator\Constraint;

/**
* The Isbn constraint is used to validate that a given value conforms to the structure of an ISBN (International Standard Book Number).
* This class supports both ISBN-10 and ISBN-13 formats. It can be applied to properties or methods within your Symfony application
* to ensure that values assigned to these elements are valid ISBNs. This validation is particularly useful in applications dealing
* with books, publications, libraries, or any context where standardized book identification is required.
*
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
* @author Manuel Reinhard <manu@sprain.ch>
* @author Bernhard Schussek <bschussek@gmail.com>
Expand All @@ -38,12 +43,41 @@ class Isbn extends Constraint
self::TYPE_NOT_RECOGNIZED_ERROR => 'TYPE_NOT_RECOGNIZED_ERROR',
];

/**
* @var string Message to display when an invalid ISBN-10 is provided.
*/
public string $isbn10Message = 'This value is not a valid ISBN-10.';

/**
* @var string Message to display when an invalid ISBN-13 is provided.
*/
public string $isbn13Message = 'This value is not a valid ISBN-13.';

/**
* @var string Message to display when the value is neither a valid ISBN-10 nor a valid ISBN-13.
*/
public string $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.';
public ?string $type = null;

/**
* @var string|array|null The type of ISBN validation to apply ('isbn10', 'isbn13', or both). Default is null, which means both types are validated.
*/
public string|array|null $type = null;

/**
* @var string The default message to display when the value is not a valid ISBN.
*/
public ?string $message = null;

/**
* @param string|array|null $type The type of ISBN validation (ISBN_10, ISBN_13, or both).
* @param string|null $message The error message to use if validation fails.
* @param string|null $isbn10Message Custom message for invalid ISBN-10.
* @param string|null $isbn13Message Custom message for invalid ISBN-13.
* @param string|null $bothIsbnMessage Custom message when value is neither valid ISBN-10 nor ISBN-13.
* @param array|null $groups The groups this constraint belongs to.
* @param mixed $payload A payload that can be used by the validator.
* @param array $options Additional options for the constraint.
*/
public function __construct(
string|array $type = null,
string $message = null,
Expand All @@ -68,6 +102,11 @@ public function __construct(
$this->bothIsbnMessage = $bothIsbnMessage ?? $this->bothIsbnMessage;
}

/**
* Returns the default option name.
*
* @return string|null
*/
public function getDefaultOption(): ?string
{
return 'type';
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.