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

Filters refactoring #663

Merged
merged 30 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2cc3cef
Filters refactoring
butschster Apr 19, 2022
e5670a0
Apply fixes from StyleCI
StyleCIBot Apr 19, 2022
9d5b8f7
Filters refactoring
butschster Apr 19, 2022
1d49b43
Merge remote-tracking branch 'origin/feature/379-filters' into featur…
butschster Apr 19, 2022
735a5ae
Apply fixes from StyleCI
StyleCIBot Apr 19, 2022
261d976
Fixes problem with resolving not exist AuthContextInterface
butschster Apr 26, 2022
c4b2bf0
Fixes problem with cyclic filter resolving.
butschster Apr 26, 2022
f85cecb
Fixes problems with filter validation
butschster Apr 26, 2022
b431b8e
Apply fixes from StyleCI
StyleCIBot Apr 26, 2022
5f6bc62
Adds filter input attributes
butschster Apr 28, 2022
2f1fad2
Merge remote-tracking branch 'origin/feature/379-filters' into featur…
butschster Apr 28, 2022
683e9ec
Apply fixes from StyleCI
StyleCIBot Apr 28, 2022
27db756
Merge branch '3.0' into feature/379-filters
butschster Apr 29, 2022
2afed7e
- Removes validation implementation
butschster May 4, 2022
23b2dce
Apply fixes from StyleCI
StyleCIBot May 4, 2022
f7c8278
Cleanup
butschster May 4, 2022
752e30b
Apply fixes from StyleCI
StyleCIBot May 4, 2022
ffc2a7b
Adds unit tests for attributes
butschster May 5, 2022
ef701e1
Adds unit tests for interceptors
butschster May 11, 2022
fd34790
Apply fixes from StyleCI
StyleCIBot May 11, 2022
e65885c
Covers with tests Interceptors and schema mappers
butschster May 12, 2022
6af0720
Merge branch 'feature/379-filters' of github.com:spiral/framework int…
butschster May 12, 2022
f50ef45
Apply fixes from StyleCI
StyleCIBot May 12, 2022
8791215
Merge branch '3.0' into feature/379-filters
butschster May 16, 2022
6e762ba
- Add pdp docs for attributes
butschster May 16, 2022
044b226
- Adds attributes phpdocs
butschster May 16, 2022
3ee3059
Merge branch '3.0' into feature/379-filters
butschster May 16, 2022
c123271
- Adds attributes phpdocs
butschster May 17, 2022
b25929b
Fixes unit tests
butschster May 17, 2022
3d92f57
Fixes unit tests
butschster May 17, 2022
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
9 changes: 5 additions & 4 deletions src/Filters/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
],
"require": {
"php": ">=8.1",
"spiral/core": "^2.14",
"spiral/models": "^2.14",
"spiral/translator": "^2.14",
"spiral/validation": "^2.14"
"spiral/auth": "^2.13",
"spiral/attributes": "^2.13",
"spiral/core": "^2.13",
"spiral/models": "^2.13",
"spiral/validation": "^2.13"
butschster marked this conversation as resolved.
Show resolved Hide resolved
},
"require-dev": {
"phpunit/phpunit": "^9.5.5",
Expand Down
81 changes: 0 additions & 81 deletions src/Filters/src/ArrayInput.php

This file was deleted.

19 changes: 19 additions & 0 deletions src/Filters/src/Attribute/Input/AbstractInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Filters\InputInterface;

abstract class AbstractInput
{
abstract public function getValue(InputInterface $input, \ReflectionProperty $property): mixed;

abstract public function getSchema(\ReflectionProperty $property): string;

protected function getKey(\ReflectionProperty $property): string
{
return $this->key ?? $property->getName();
}
}
36 changes: 36 additions & 0 deletions src/Filters/src/Attribute/Input/Attribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [attributes] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class Attribute extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::attribute() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue('attribute', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'attribute:' . $this->getKey($property);
}
}
28 changes: 28 additions & 0 deletions src/Filters/src/Attribute/Input/BearerToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [headers] bag with key [Authorization].
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class BearerToken extends AbstractInput
{
/**
* @see \Spiral\Http\Request\InputManager::bearerToken() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue($this->getSchema($property));
roxblnfk marked this conversation as resolved.
Show resolved Hide resolved
}

public function getSchema(\ReflectionProperty $property): string
{
return 'bearerToken';
}
}
36 changes: 36 additions & 0 deletions src/Filters/src/Attribute/Input/Cookie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [cookies] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class Cookie extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::cookie() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue('cookie', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'cookie:' . $this->getKey($property);
}
}
36 changes: 36 additions & 0 deletions src/Filters/src/Attribute/Input/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [data] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class Data extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::data() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue('data', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'data:' . $this->getKey($property);
}
}
37 changes: 37 additions & 0 deletions src/Filters/src/Attribute/Input/File.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Psr\Http\Message\UploadedFileInterface;
use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [files] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
class File extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::file() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): ?UploadedFileInterface
{
return $input->getValue('file', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'file:' . $this->getKey($property);
}
}
36 changes: 36 additions & 0 deletions src/Filters/src/Attribute/Input/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [headers] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class Header extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::header() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue('header', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'header:' . $this->getKey($property);
}
}
36 changes: 36 additions & 0 deletions src/Filters/src/Attribute/Input/Input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value from the request [data + query] bag.
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class Input extends AbstractInput
{
/**
* @param non-empty-string|null $key
*/
public function __construct(
public readonly ?string $key = null,
) {
}

/**
* @see \Spiral\Http\Request\InputManager::input() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): mixed
{
return $input->getValue('input', $this->getKey($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'input:' . $this->getKey($property);
}
}
28 changes: 28 additions & 0 deletions src/Filters/src/Attribute/Input/IsAjax.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Spiral\Filters\Attribute\Input;

use Spiral\Attributes\NamedArgumentConstructor;
use Spiral\Filters\InputInterface;

/**
* Sets property value true/false if X-Requested-With set as xmlhttprequest
*/
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor]
final class IsAjax extends AbstractInput
{
/**
* @see \Spiral\Http\Request\InputManager::isAjax() from {@link https://github.com/spiral/http}
*/
public function getValue(InputInterface $input, \ReflectionProperty $property): bool
{
return $input->getValue($this->getSchema($property));
}

public function getSchema(\ReflectionProperty $property): string
{
return 'isAjax';
}
}
Loading