Skip to content

Commit

Permalink
Merge branch refs/heads/master into feature/scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed May 30, 2024
1 parent 994ffab commit ad25738
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"php": ">=8.1",
"psr/http-message": "^1.0|^2.0",
"spiral/attributes": "^2.8|^3.0",
"spiral/auth": "^3.13",
"spiral/core": "^3.13",
"spiral/hmvc": "^3.13",
"spiral/models": "^3.13",
"spiral/validation": "^3.13"
"spiral/auth": "^3.14",
"spiral/core": "^3.14",
"spiral/hmvc": "^3.14",
"spiral/models": "^3.14",
"spiral/validation": "^3.14"
},
"require-dev": {
"mockery/mockery": "^1.5",
Expand All @@ -55,7 +55,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.13.x-dev"
"dev-master": "3.14.x-dev"
}
},
"config": {
Expand Down
5 changes: 5 additions & 0 deletions src/Config/FiltersConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Spiral\Filters\Config;

use Spiral\Core\CoreInterceptorInterface;
use Spiral\Core\InjectableConfig;
use Spiral\Interceptors\InterceptorInterface;

final class FiltersConfig extends InjectableConfig
{
Expand All @@ -14,6 +16,9 @@ final class FiltersConfig extends InjectableConfig
'interceptors' => [],
];

/**
* @return array<class-string<CoreInterceptorInterface|InterceptorInterface>>
*/
public function getInterceptors(): array
{
return (array)($this->config['interceptors'] ?? []);
Expand Down
14 changes: 11 additions & 3 deletions src/Model/FilterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use Spiral\Filters\Model\Schema\Builder;
use Spiral\Filters\Model\Schema\InputMapper;
use Spiral\Filters\InputInterface;
use Spiral\Interceptors\Context\CallContext;
use Spiral\Interceptors\Context\Target;
use Spiral\Interceptors\HandlerInterface;
use Spiral\Models\SchematicEntity;

/**
Expand All @@ -19,11 +22,13 @@
*/
final class FilterProvider implements FilterProviderInterface
{
private readonly bool $isLegacy;
public function __construct(
private readonly ContainerInterface $container,
private readonly ResolverInterface $resolver,
private readonly CoreInterface $core
private readonly HandlerInterface|CoreInterface $core
) {
$this->isLegacy = !$core instanceof HandlerInterface;
}

public function createFilter(string $name, InputInterface $input): FilterInterface
Expand Down Expand Up @@ -56,9 +61,12 @@ public function createFilter(string $name, InputInterface $input): FilterInterfa
$errors = \array_merge($errors, $inputErrors);

$entity = new SchematicEntity($data, $schema);
return $this->core->callAction($name, 'handle', [
$args = [
'filterBag' => new FilterBag($filter, $entity, $schema, $errors),
]);
];
return $this->isLegacy
? $this->core->callAction($name, 'handle', $args)
: $this->core->handle(new CallContext(Target::fromPair($name, 'handle'), $args));
}

private function createFilterInstance(string $name): FilterInterface
Expand Down
12 changes: 11 additions & 1 deletion src/Model/Interceptor/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Spiral\Core\CoreInterface;
use Spiral\Filters\Model\FilterBag;
use Spiral\Filters\Model\FilterInterface;
use Spiral\Interceptors\Context\CallContext;
use Spiral\Interceptors\HandlerInterface;

/**
* @psalm-type TParameters = array{filterBag: FilterBag}
*/
final class Core implements CoreInterface
final class Core implements CoreInterface, HandlerInterface
{
/**
* @param-assert TParameters $parameters
Expand All @@ -22,4 +24,12 @@ public function callAction(string $controller, string $action, array $parameters

return $parameters['filterBag']->filter;
}

public function handle(CallContext $context): FilterInterface
{
$args = $context->getArguments();
\assert($args['filterBag'] instanceof FilterBag);

return $args['filterBag']->filter;
}
}
5 changes: 4 additions & 1 deletion tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Spiral\Core\Container;
use Spiral\Core\Options;
use Spiral\Validation\ValidationInterface;
use Spiral\Validation\ValidationProvider;

Expand All @@ -16,7 +17,9 @@ abstract class BaseTestCase extends TestCase

public function setUp(): void
{
$this->container = new Container();
$options = new Options();
$options->checkScope = false;
$this->container = new Container(options: $options);
$this->container->bindSingleton(ValidationInterface::class, ValidationProvider::class);
}
}
2 changes: 2 additions & 0 deletions tests/InputScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Spiral\Filter\InputScope;
use Spiral\Filters\InputInterface;
use Spiral\Http\Request\InputManager;

final class InputScopeTest extends BaseTestCase
{
Expand All @@ -16,6 +17,7 @@ public function setUp(): void
parent::setUp();

$this->container->bindSingleton(InputInterface::class, InputScope::class);
$this->container->bindSingleton(InputManager::class, new InputManager($this->container));
$this->container->bindSingleton(
ServerRequestInterface::class,
(new ServerRequest('POST', '/test'))->withParsedBody([
Expand Down

0 comments on commit ad25738

Please sign in to comment.