Rename library/ to src/

We've always considered renaming this directory, as it's not a common
standard to name `library` the directory where the source code of a
library it. Having it as `src/` is a common pattern we find in several
PHP libraries these days.

Acked-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
This commit is contained in:
Henrique Moody 2026-01-22 13:13:15 +01:00
commit 140bd36aa3
No known key found for this signature in database
GPG key ID: 221E9281655813A6
273 changed files with 17 additions and 17 deletions

View file

@ -0,0 +1,72 @@
<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Validation\Validators;
use Attribute;
use Respect\Validation\Exceptions\InvalidValidatorException;
use Respect\Validation\Exceptions\MissingComposerDependencyException;
use Respect\Validation\Helpers\CanValidateUndefined;
use Respect\Validation\Message\Template;
use Respect\Validation\Result;
use Respect\Validation\Validator;
use Sokil\IsoCodes\Database\Countries;
use Sokil\IsoCodes\Database\Subdivisions;
use function class_exists;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
#[Template(
'{{subject}} must be a subdivision code of {{countryName|trans}}',
'{{subject}} must not be a subdivision code of {{countryName|trans}}',
)]
final readonly class SubdivisionCode implements Validator
{
use CanValidateUndefined;
private Countries\Country $country;
private Subdivisions $subdivisions;
public function __construct(
string $countryCode,
Countries|null $countries = null,
Subdivisions|null $subdivisions = null,
) {
if (!class_exists(Countries::class) || !class_exists(Subdivisions::class)) {
throw new MissingComposerDependencyException(
'SubdivisionCode rule requires PHP ISO Codes',
'sokil/php-isocodes',
'sokil/php-isocodes-db-only',
);
}
$countries ??= new Countries();
$country = $countries->getByAlpha2($countryCode);
if ($country === null) {
throw new InvalidValidatorException('"%s" is not a supported country code', $countryCode);
}
$this->country = $country;
$this->subdivisions = $subdivisions ?? new Subdivisions();
}
public function evaluate(mixed $input): Result
{
$parameters = ['countryName' => $this->country->getName()];
$subdivision = $this->subdivisions->getByCode($this->country->getAlpha2() . '-' . $input);
if ($this->isUndefined($input) && $subdivision === null) {
return Result::passed($input, $this, $parameters);
}
return Result::of($subdivision !== null, $input, $this, $parameters);
}
}