Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 20 additions & 18 deletions bin/create-mixin
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,31 @@ require __DIR__ . '/../vendor/autoload.php';
use Nette\PhpGenerator\InterfaceType;
use Nette\PhpGenerator\PhpNamespace;
use Nette\PhpGenerator\Printer;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Mixins\KeyChain;
use Respect\Validation\Mixins\LengthChain;
use Respect\Validation\Mixins\MaxChain;
use Respect\Validation\Mixins\MinChain;
use Respect\Validation\Mixins\NotChain;
use Respect\Validation\Mixins\NullOrChain;
use Respect\Validation\Mixins\PropertyChain;
use Respect\Validation\Mixins\UndefOrChain;
use Respect\Validation\Mixins\Chain;
use Respect\Validation\Mixins\KeyBuilder;
use Respect\Validation\Mixins\KeyChain;
use Respect\Validation\Mixins\LengthBuilder;
use Respect\Validation\Mixins\LengthChain;
use Respect\Validation\Mixins\MaxBuilder;
use Respect\Validation\Mixins\MaxChain;
use Respect\Validation\Mixins\MinBuilder;
use Respect\Validation\Mixins\MinChain;
use Respect\Validation\Mixins\NotBuilder;
use Respect\Validation\Mixins\NotChain;
use Respect\Validation\Mixins\NullOrBuilder;
use Respect\Validation\Mixins\NullOrChain;
use Respect\Validation\Mixins\PropertyBuilder;
use Respect\Validation\Mixins\PropertyChain;
use Respect\Validation\Mixins\UndefOrBuilder;
use Respect\Validation\Rules\Undef;
use Respect\Validation\Rules\NullOr;
use Respect\Validation\Rules\UndefOr;
use Respect\Validation\Mixins\UndefOrChain;
use Respect\Validation\Rule;
use Respect\Validation\Validator;

function addMethodToInterface(
string $originalName,
InterfaceType $interfaceType,
ReflectionClass $reflection,
?string $prefix,
string|null $prefix,
array $allowList,
array $denyList,
): void {
Expand Down Expand Up @@ -65,6 +62,7 @@ function addMethodToInterface(
if ($reflrectionConstructor === null) {
return;
}

$commend = $reflrectionConstructor->getDocComment();
if ($commend) {
$method->addComment(preg_replace('@(/\*\* *| +\* +| +\*/)@', '', $commend));
Expand All @@ -83,13 +81,15 @@ function addMethodToInterface(
}
} elseif ($type instanceof ReflectionNamedType) {
$types[] = $type->getName();
if ( str_starts_with($type->getName(), 'Sokil')
if (
str_starts_with($type->getName(), 'Sokil')
|| str_starts_with($type->getName(), 'Egulias')
|| $type->getName() === 'finfo'
) {
continue;
}
}

$parameter = $method->addParameter($reflectionParameter->getName());
$parameter->setType(implode('|', $types));

Expand Down Expand Up @@ -121,7 +121,7 @@ function overwriteFile(string $content, string $basename): void
{
file_put_contents(sprintf('%s/../library/Mixins/%s.php', __DIR__, $basename), implode(PHP_EOL . PHP_EOL, [
'<?php',
file_get_contents(__DIR__.'/../.docheader'),
file_get_contents(__DIR__ . '/../.docheader'),
'declare(strict_types=1);',
preg_replace('/extends (.+, )+/', 'extends' . PHP_EOL . '\1', $content),
]));
Expand Down Expand Up @@ -172,7 +172,7 @@ function overwriteFile(string $content, string $basename): void
['Length', 'length', $numberRelatedRules, []],
['Max', 'max', $numberRelatedRules, []],
['Min', 'min', $numberRelatedRules, []],
['Not', 'not', [], ['Not', 'NotEmpty', 'NotEmoji', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['Not', 'not', [], ['Not', 'NotEmpty', 'NullOr', 'UndefOr', 'Attributes', 'Templated', 'Named']],
['NullOr', 'nullOr', [], ['NullOr', 'Blank', 'Undef', 'UndefOr', 'Templated', 'Named']],
['Property', 'property', [], $structureRelatedRules],
['UndefOr', 'undefOr', [], ['NullOr', 'Blank', 'Undef', 'UndefOr', 'Attributes', 'Templated', 'Named']],
Expand All @@ -190,8 +190,10 @@ function overwriteFile(string $content, string $basename): void
if ($reflection->isAbstract()) {
continue;
}

$names[$reflection->getShortName()] = $reflection;
}

ksort($names);

foreach ($mixins as [$name, $prefix, $allowList, $denyList]) {
Expand All @@ -213,7 +215,7 @@ function overwriteFile(string $content, string $basename): void
$chainedInterface->addExtend(NullOrChain::class);
$chainedInterface->addExtend(PropertyChain::class);
$chainedInterface->addExtend(UndefOrChain::class);
$chainedInterface->addComment('@mixin \\' . \Respect\Validation\Validator::class);
$chainedInterface->addComment('@mixin \\' . Validator::class);

$staticInterface->addExtend(KeyBuilder::class);
$staticInterface->addExtend(LengthBuilder::class);
Expand All @@ -237,5 +239,5 @@ function overwriteFile(string $content, string $basename): void
overwriteFile($printer->printNamespace($chainedNamespace), $chainedInterface->getName());
}

shell_exec(__DIR__.'/../vendor/bin/phpcbf');
shell_exec(__DIR__ . '/../vendor/bin/phpcbf ' . __DIR__ . '/../library/Mixins');
})();
4 changes: 2 additions & 2 deletions docs/09-list-of-rules-by-category.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@
- [ContainsAny](rules/ContainsAny.md)
- [Control](rules/Control.md)
- [Digit](rules/Digit.md)
- [Emoji](rules/Emoji.md)
- [EndsWith](rules/EndsWith.md)
- [Graph](rules/Graph.md)
- [HexRgbColor](rules/HexRgbColor.md)
- [In](rules/In.md)
- [Json](rules/Json.md)
- [Lowercase](rules/Lowercase.md)
- [NotEmoji](rules/NotEmoji.md)
- [Phone](rules/Phone.md)
- [PhpLabel](rules/PhpLabel.md)
- [PostalCode](rules/PostalCode.md)
Expand Down Expand Up @@ -344,6 +344,7 @@
- [Domain](rules/Domain.md)
- [Each](rules/Each.md)
- [Email](rules/Email.md)
- [Emoji](rules/Emoji.md)
- [EndsWith](rules/EndsWith.md)
- [Equals](rules/Equals.md)
- [Equivalent](rules/Equivalent.md)
Expand Down Expand Up @@ -404,7 +405,6 @@
- [No](rules/No.md)
- [NoneOf](rules/NoneOf.md)
- [Not](rules/Not.md)
- [NotEmoji](rules/NotEmoji.md)
- [NotEmpty](rules/NotEmpty.md)
- [NullOr](rules/NullOr.md)
- [NullType](rules/NullType.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Alnum.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ See also:
- [Control](Control.md)
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Emoji](Emoji.md)
- [Lowercase](Lowercase.md)
- [NotEmoji](NotEmoji.md)
- [Regex](Regex.md)
- [Spaced](Spaced.md)
- [StringType](StringType.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ See also:
- [Consonant](Consonant.md)
- [Decimal](Decimal.md)
- [Digit](Digit.md)
- [Emoji](Emoji.md)
- [Lowercase](Lowercase.md)
- [NotEmoji](NotEmoji.md)
- [Regex](Regex.md)
- [Spaced](Spaced.md)
- [Uppercase](Uppercase.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Decimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ See also:
- [Alpha](Alpha.md)
- [Consonant](Consonant.md)
- [CreditCard](CreditCard.md)
- [Emoji](Emoji.md)
- [Factor](Factor.md)
- [Finite](Finite.md)
- [Infinite](Infinite.md)
- [IntType](IntType.md)
- [IntVal](IntVal.md)
- [NotEmoji](NotEmoji.md)
- [NumericVal](NumericVal.md)
- [Regex](Regex.md)
- [Uuid](Uuid.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/Digit.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ See also:
- [Alpha](Alpha.md)
- [Consonant](Consonant.md)
- [CreditCard](CreditCard.md)
- [Emoji](Emoji.md)
- [Factor](Factor.md)
- [Finite](Finite.md)
- [Infinite](Infinite.md)
- [IntType](IntType.md)
- [IntVal](IntVal.md)
- [NotEmoji](NotEmoji.md)
- [NumericVal](NumericVal.md)
- [Regex](Regex.md)
- [Uuid](Uuid.md)
Expand Down
63 changes: 63 additions & 0 deletions docs/rules/Emoji.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Emoji

- `v::emoji()`

Validates if the input is an emoji or a sequence of emojis.

```php
v::emoji()->isValid('🍕'); // true
v::emoji()->isValid('🎈'); // true
v::emoji()->isValid('⚡'); // true
v::emoji()->isValid('🌊🌊🌊🌊🌊🏄🌊🌊🌊🏖🌴'); // true
v::emoji()->isValid('🇧🇷'); // true (country flag)
v::emoji()->isValid('👨‍👩‍👧‍👦'); // true (ZWJ sequence)
v::emoji()->isValid('👩🏽'); // true (skin tone modifier)
v::emoji()->isValid('1️⃣'); // true (keycap sequence)
v::emoji()->isValid('Hello World'); // false
v::emoji()->isValid('this is a spark ⚡'); // false (mixed content)
```

This validator supports:

- Basic emojis and pictographs
- Skin tone modifiers (Fitzpatrick scale)
- Country flags (regional indicator sequences)
- Subdivision flags (tag sequences like 🏴󠁧󠁢󠁥󠁮󠁧󠁿)
- Keycap sequences (0️⃣-9️⃣, #️⃣, \*️⃣)
- ZWJ (Zero Width Joiner) sequences for families, professions, and combined emojis
- Emojis up to Unicode 17.0 / Emoji 16.0

## Templates

### `Emoji::TEMPLATE_STANDARD`

| Mode | Template |
| ---------- | -------------------------------- |
| `default` | {{subject}} must be an emoji |
| `inverted` | {{subject}} must not be an emoji |

## Template placeholders

| Placeholder | Description |
| ----------- | ---------------------------------------------------------------- |
| `subject` | The validated input or the custom validator name (if specified). |

## Categorization

- Strings

## Changelog

| Version | Description |
| ------: | --------------------------------------------------------------------------- |
| 3.0.0 | Renamed to `Emoji`, changed the behavior, and added support for more emojis |
| 2.0.0 | Created as `NotEmoji` |

---

See also:

- [Alnum](Alnum.md)
- [Alpha](Alpha.md)
- [Decimal](Decimal.md)
- [Digit](Digit.md)
57 changes: 0 additions & 57 deletions docs/rules/NotEmoji.md

This file was deleted.

2 changes: 1 addition & 1 deletion library/Mixins/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static function noneOf(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;

public static function not(Rule $rule): Chain;

public static function notEmoji(): Chain;
public static function emoji(): Chain;

public static function notEmpty(): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/Chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function noneOf(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;

public function not(Rule $rule): Chain;

public function notEmoji(): Chain;
public function emoji(): Chain;

public function notEmpty(): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/KeyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public static function keyNoneOf(int|string $key, Rule $rule1, Rule $rule2, Rule

public static function keyNot(int|string $key, Rule $rule): Chain;

public static function keyNotEmoji(int|string $key): Chain;
public static function keyEmoji(int|string $key): Chain;

public static function keyNotEmpty(int|string $key): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/KeyChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function keyNoneOf(int|string $key, Rule $rule1, Rule $rule2, Rule ...$ru

public function keyNot(int|string $key, Rule $rule): Chain;

public function keyNotEmoji(int|string $key): Chain;
public function keyEmoji(int|string $key): Chain;

public function keyNotEmpty(int|string $key): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/NullOrBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public static function nullOrNoneOf(Rule $rule1, Rule $rule2, Rule ...$rules): C

public static function nullOrNot(Rule $rule): Chain;

public static function nullOrNotEmoji(): Chain;
public static function nullOrEmoji(): Chain;

public static function nullOrNotEmpty(): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/NullOrChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function nullOrNoneOf(Rule $rule1, Rule $rule2, Rule ...$rules): Chain;

public function nullOrNot(Rule $rule): Chain;

public function nullOrNotEmoji(): Chain;
public function nullOrEmoji(): Chain;

public function nullOrNotEmpty(): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/PropertyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static function propertyNoneOf(string $propertyName, Rule $rule1, Rule $r

public static function propertyNot(string $propertyName, Rule $rule): Chain;

public static function propertyNotEmoji(string $propertyName): Chain;
public static function propertyEmoji(string $propertyName): Chain;

public static function propertyNotEmpty(string $propertyName): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/PropertyChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function propertyNoneOf(string $propertyName, Rule $rule1, Rule $rule2, R

public function propertyNot(string $propertyName, Rule $rule): Chain;

public function propertyNotEmoji(string $propertyName): Chain;
public function propertyEmoji(string $propertyName): Chain;

public function propertyNotEmpty(string $propertyName): Chain;

Expand Down
2 changes: 1 addition & 1 deletion library/Mixins/UndefOrBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static function undefOrNoneOf(Rule $rule1, Rule $rule2, Rule ...$rules):

public static function undefOrNot(Rule $rule): Chain;

public static function undefOrNotEmoji(): Chain;
public static function undefOrEmoji(): Chain;

public static function undefOrNotEmpty(): Chain;

Expand Down
Loading