Skip to content
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

Add Singleton attribute instead of SingletonInterface #15

Merged
merged 1 commit into from
Jan 11, 2024
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
2 changes: 0 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ jobs:
with:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
stability: >-
['prefer-lowest', 'prefer-stable']
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"require": {
"php": ">=8.1",
"ext-json": "*",
"spiral/core": "^3.1",
"spiral/core": "^3.6",
"spiral/files": "^3.1",
"spiral/streams": "^3.1",
"spiral/translator": "^3.1",
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/AddressChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;

final class AddressChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class AddressChecker extends AbstractChecker
{
public const MESSAGES = [
'email' => '[[Must be a valid email address.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/BooleanChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;

final class BooleanChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class BooleanChecker extends AbstractChecker
{
public const MESSAGES = [
'isTrue' => '[[Should be true.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/DatetimeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;
use Spiral\Validator\Checker\DatetimeChecker\ThresholdChecker;

final class DatetimeChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class DatetimeChecker extends AbstractChecker
{
public const MESSAGES = [
'future' => '[[Should be a date in the future.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/FileChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Spiral\Validator\Checker;

use Psr\Http\Message\UploadedFileInterface;
use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Files\FilesInterface;
use Spiral\Validator\AbstractChecker;
use Spiral\Validator\Checker\Traits\FileTrait;

final class FileChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class FileChecker extends AbstractChecker
{
use FileTrait;

Expand Down
5 changes: 3 additions & 2 deletions src/Checker/ImageChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
namespace Spiral\Validator\Checker;

use Psr\Http\Message\UploadedFileInterface;
use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Files\FilesInterface;
use Spiral\Streams\StreamableInterface;
use Spiral\Validator\AbstractChecker;
use Spiral\Validator\Checker\Traits\FileTrait;

final class ImageChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class ImageChecker extends AbstractChecker
{
use FileTrait;

Expand Down
5 changes: 3 additions & 2 deletions src/Checker/MixedChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;

final class MixedChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class MixedChecker extends AbstractChecker
{
public const MESSAGES = [
'cardNumber' => '[[Please enter valid card number.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/NumberChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;

final class NumberChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class NumberChecker extends AbstractChecker
{
public const MESSAGES = [
'range' => '[[Your value should be in range of {1}-{2}.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/StringChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;

final class StringChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class StringChecker extends AbstractChecker
{
public const MESSAGES = [
'regexp' => '[[Value does not match required pattern.]]',
Expand Down
5 changes: 3 additions & 2 deletions src/Checker/TypeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

namespace Spiral\Validator\Checker;

use Spiral\Core\Container\SingletonInterface;
use Spiral\Core\Attribute\Singleton;
use Spiral\Validator\AbstractChecker;
use Spiral\Validator\Checker\Traits\NotEmptyTrait;

final class TypeChecker extends AbstractChecker implements SingletonInterface
#[Singleton]
final class TypeChecker extends AbstractChecker
{
use NotEmptyTrait;

Expand Down
14 changes: 13 additions & 1 deletion tests/app/Bootloader/FiltersBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Append;
use Spiral\Core\Attribute\Singleton;
use Spiral\Core\BinderInterface;
use Spiral\Core\Container;
use Spiral\Core\InterceptableCore;
Expand All @@ -21,13 +22,19 @@
use Spiral\Filters\Model\Interceptor\PopulateDataFromEntityInterceptor;
use Spiral\Filters\Model\Interceptor\ValidateFilterInterceptor;
use Spiral\Filters\InputInterface;
use Spiral\Filters\Model\Mapper\CasterRegistry;
use Spiral\Filters\Model\Mapper\CasterRegistryInterface;
use Spiral\Filters\Model\Mapper\EnumCaster;
use Spiral\Filters\Model\Mapper\UuidCaster;
use Spiral\Validator\App\InputScope;

final class FiltersBootloader extends Bootloader implements Container\InjectorInterface, Container\SingletonInterface
#[Singleton]
final class FiltersBootloader extends Bootloader implements Container\InjectorInterface
{
protected const SINGLETONS = [
FilterProviderInterface::class => [self::class, 'initFilterProvider'],
InputInterface::class => InputScope::class,
CasterRegistryInterface::class => [self::class, 'initCasterRegistry'],
];

public function __construct(
Expand Down Expand Up @@ -85,4 +92,9 @@ private function initFilterProvider(

return new FilterProvider($container, $container, $core);
}

private function initCasterRegistry(): CasterRegistryInterface
{
return new CasterRegistry([new EnumCaster(), new UuidCaster()]);
}
}
Loading