Skip to content

Commit

Permalink
Use PHP ISO Codes in the "LanguageCode" rule
Browse files Browse the repository at this point in the history
Since we now have PHP ISO Codes as a dependency[1], it doesn't make
sense to keep dealing with this data ourselves.

[1]: 04b2722

Signed-off-by: Henrique Moody <[email protected]>
  • Loading branch information
henriquemoody committed Feb 22, 2024
1 parent 27d7db5 commit a45a0a2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 563 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/update-regionals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
with:
ref: ${{ secrets.LAST_MINOR_VERSION }}

- name: Update language codes
run: bin/update-language-codes

- name: Update top level domains
run: bin/update-domain-toplevel

Expand Down
29 changes: 0 additions & 29 deletions bin/update-language-codes

This file was deleted.

16 changes: 13 additions & 3 deletions docs/rules/LanguageCode.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# LanguageCode

- `LanguageCode()`
- `LanguageCode(string $set)`
- `LanguageCode("alpha-2"|"alpha-3" $set)`

Validates whether the input is language code based on ISO 639.
Validates whether the input is language code based on [ISO 639][].

**This rule requires [sokil/php-isocodes][] and [sokil/php-isocodes-db-only][] to be installed.**

```php
v::languageCode()->validate('pt'); // true
Expand All @@ -13,7 +15,10 @@ v::languageCode('alpha-3')->validate('ita'); // true
v::languageCode('alpha-3')->validate('eng'); // true
```

You can choose between `alpha-2` and `alpha-3`; `alpha-2` is set by default set.
This rule supports the two[ISO 639][] sets:

- `alpha-2`
- `alpha-3`

## Categorization

Expand All @@ -24,9 +29,14 @@ You can choose between `alpha-2` and `alpha-3`; `alpha-2` is set by default set.

Version | Description
--------|-------------
3.0.0 | Require [sokil/php-isocodes][] and [sokil/php-isocodes-db-only][]
1.1.0 | Created

***
See also:

- [CountryCode](CountryCode.md)

[ISO 639]: https://en.wikipedia.org/wiki/ISO_639-3
[sokil/php-isocodes]: https://github.com/sokil/php-isocodes
[sokil/php-isocodes-db-only]: https://github.com/sokil/php-isocodes-db-only
3 changes: 2 additions & 1 deletion library/ChainedValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public function keySet(Key ...$rule): ChainedValidator;

public function keyValue(string $comparedKey, string $ruleName, string $baseKey): ChainedValidator;

public function languageCode(?string $set = null): ChainedValidator;
/** @param "alpha-2"|"alpha-3" $set */
public function languageCode(string $set = 'alpha-2'): ChainedValidator;

public function leapDate(string $format): ChainedValidator;

Expand Down
Loading

0 comments on commit a45a0a2

Please sign in to comment.