Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Feb 10, 2024
2 parents a1f8547 + 9b6eb9a commit 33a1d94
Show file tree
Hide file tree
Showing 35 changed files with 348 additions and 213 deletions.
1 change: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
| Is bugfix? | ✔️/❌
| New feature? | ✔️/❌
| Breaks BC? | ✔️/❌
| Fixed issues | <!-- comma-separated list of tickets # fixed by the PR, if any -->
23 changes: 21 additions & 2 deletions .github/workflows/bc.yml_
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
on:
- pull_request
- push
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'
push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'
- 'infection.json.dist'
- 'phpunit.xml.dist'
- 'psalm.xml'

name: backwards compatibility

Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -25,7 +26,8 @@ jobs:
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
with:
ini-values: pcov.directory=$GITHUB_WORKSPACE, pcov.exclude=#^(?!($GITHUB_WORKSPACE/config/|$GITHUB_WORKSPACE/src/)).*#
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['8.1', '8.2']
['8.0', '8.1', '8.2', '8.3']
3 changes: 2 additions & 1 deletion .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -30,4 +31,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
['8.0', '8.1', '8.2', '8.3']
2 changes: 2 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'psalm.xml'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -23,6 +24,7 @@ jobs:
mutation:
uses: yiisoft/actions/.github/workflows/roave-infection.yml@master
with:
min-covered-msi: 100
os: >-
['ubuntu-latest']
php: >-
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ name: rector
jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
['8.3']
3 changes: 2 additions & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: ['master']
paths-ignore:
- 'docs/**'
- 'README.md'
Expand All @@ -28,4 +29,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
['8.0', '8.1', '8.2', '8.3']
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"yiisoft/arrays": "^3.0",
"yiisoft/hydrator": "dev-master",
"yiisoft/hydrator-validator": "dev-master",
"yiisoft/hydrator": "^1.0",
"yiisoft/hydrator-validator": "^1.0",
"yiisoft/middleware-dispatcher": "^5.1",
"yiisoft/validator": "^1.1"
},
"require-dev": {
"maglnet/composer-require-checker": "^4.4",
"phpunit/phpunit": "^9.5",
"rector/rector": "^0.16.0",
"rector/rector": "^1.0.0",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.30|^5.7",
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<coverage>
<include>
<directory>./src</directory>
<directory>./config</directory>
</include>
</coverage>
</phpunit>
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;

Expand All @@ -23,5 +24,6 @@

$rectorConfig->skip([
ClosureToArrowFunctionRector::class,
JsonThrowOnErrorRector::class,
]);
};
7 changes: 3 additions & 4 deletions src/Attribute/Data/FromBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Yiisoft\Input\Http\Attribute\Data;

use Attribute;
use Yiisoft\Hydrator\DataAttributeInterface;
use Yiisoft\Hydrator\HydratorInterface;
use Yiisoft\Hydrator\ArrayData;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface;

/**
* Take data for the input DTO from the request body.
*
* @psalm-import-type MapType from HydratorInterface
* @psalm-import-type MapType from ArrayData
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class FromBody implements DataAttributeInterface
Expand Down
24 changes: 13 additions & 11 deletions src/Attribute/Data/FromBodyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Yiisoft\Input\Http\Attribute\Data;

use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Hydrator\Data;
use Yiisoft\Hydrator\DataAttributeInterface;
use Yiisoft\Hydrator\DataAttributeResolverInterface;
use Yiisoft\Hydrator\UnexpectedAttributeException;
use Yiisoft\Hydrator\ArrayData;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeResolverInterface;
use Yiisoft\Hydrator\AttributeHandling\Exception\UnexpectedAttributeException;
use Yiisoft\Hydrator\DataInterface;
use Yiisoft\Input\Http\Request\RequestProviderInterface;

use function is_array;
Expand All @@ -26,26 +27,27 @@ public function __construct(
) {
}

public function prepareData(DataAttributeInterface $attribute, Data $data): void
public function prepareData(DataAttributeInterface $attribute, DataInterface $data): DataInterface
{
if (!$attribute instanceof FromBody) {
throw new UnexpectedAttributeException(FromBody::class, $attribute);
}

$array = [];

$parsedBody = $this->requestProvider->get()->getParsedBody();
if (is_array($parsedBody)) {
$name = $attribute->getName();
if ($name === null) {
$data->setData($parsedBody);
$array = $parsedBody;
} else {
$value = ArrayHelper::getValueByPath($parsedBody, $name);
$data->setData(is_array($value) ? $value : []);
if (is_array($value)) {
$array = $value;
}
}
} else {
$data->setData([]);
}

$data->setMap($attribute->getMap());
$data->setStrict($attribute->isStrict());
return new ArrayData($array, $attribute->getMap(), $attribute->isStrict());
}
}
6 changes: 3 additions & 3 deletions src/Attribute/Data/FromQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace Yiisoft\Input\Http\Attribute\Data;

use Attribute;
use Yiisoft\Hydrator\DataAttributeInterface;
use Yiisoft\Hydrator\HydratorInterface;
use Yiisoft\Hydrator\ArrayData;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface;

/**
* Take data for the input DTO from the query string.
*
* @psalm-import-type MapType from HydratorInterface
* @psalm-import-type MapType from ArrayData
*/
#[Attribute(Attribute::TARGET_CLASS)]
final class FromQuery implements DataAttributeInterface
Expand Down
22 changes: 13 additions & 9 deletions src/Attribute/Data/FromQueryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Yiisoft\Input\Http\Attribute\Data;

use Yiisoft\Arrays\ArrayHelper;
use Yiisoft\Hydrator\Data;
use Yiisoft\Hydrator\DataAttributeInterface;
use Yiisoft\Hydrator\DataAttributeResolverInterface;
use Yiisoft\Hydrator\UnexpectedAttributeException;
use Yiisoft\Hydrator\ArrayData;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeInterface;
use Yiisoft\Hydrator\Attribute\Data\DataAttributeResolverInterface;
use Yiisoft\Hydrator\AttributeHandling\Exception\UnexpectedAttributeException;
use Yiisoft\Hydrator\DataInterface;
use Yiisoft\Input\Http\Request\RequestProviderInterface;

use function is_array;
Expand All @@ -26,23 +27,26 @@ public function __construct(
) {
}

public function prepareData(DataAttributeInterface $attribute, Data $data): void
public function prepareData(DataAttributeInterface $attribute, DataInterface $data): DataInterface
{
if (!$attribute instanceof FromQuery) {
throw new UnexpectedAttributeException(FromQuery::class, $attribute);
}

$array = [];

$params = $this->requestProvider->get()->getQueryParams();
$name = $attribute->getName();

if ($name === null) {
$data->setData($params);
$array = $params;
} else {
$value = ArrayHelper::getValueByPath($params, $name);
$data->setData(is_array($value) ? $value : []);
if (is_array($value)) {
$array = $value;
}
}

$data->setMap($attribute->getMap());
$data->setStrict($attribute->isStrict());
return new ArrayData($array, $attribute->getMap(), $attribute->isStrict());
}
}
2 changes: 1 addition & 1 deletion src/Attribute/Parameter/Body.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Yiisoft\Input\Http\Attribute\Parameter;

use Attribute;
use Yiisoft\Hydrator\ParameterAttributeInterface;
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface;

/**
* Take data for the property or attribute from the request body.
Expand Down
28 changes: 13 additions & 15 deletions src/Attribute/Parameter/BodyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
namespace Yiisoft\Input\Http\Attribute\Parameter;

use Yiisoft\Arrays\ArrayHelper;

use Yiisoft\Hydrator\Context;
use Yiisoft\Hydrator\NotResolvedException;
use Yiisoft\Hydrator\ParameterAttributeInterface;
use Yiisoft\Hydrator\ParameterAttributeResolverInterface;
use Yiisoft\Hydrator\UnexpectedAttributeException;
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface;
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeResolverInterface;
use Yiisoft\Hydrator\AttributeHandling\Exception\UnexpectedAttributeException;
use Yiisoft\Hydrator\AttributeHandling\ParameterAttributeResolveContext;
use Yiisoft\Hydrator\Result;
use Yiisoft\Input\Http\Request\RequestProviderInterface;

use function is_array;
Expand All @@ -28,27 +27,26 @@ public function __construct(
) {
}

public function getParameterValue(ParameterAttributeInterface $attribute, Context $context): mixed
{
public function getParameterValue(
ParameterAttributeInterface $attribute,
ParameterAttributeResolveContext $context,
): Result {
if (!$attribute instanceof Body) {
throw new UnexpectedAttributeException(Body::class, $attribute);
}

$parsedBody = $this->requestProvider->get()->getParsedBody();

$name = $attribute->getName();
if ($name === null) {
return $parsedBody;
}
$name = $attribute->getName() ?? $context->getParameter()->getName();

if (!is_array($parsedBody)) {
throw new NotResolvedException();
return Result::fail();
}

if (!ArrayHelper::pathExists($parsedBody, $name)) {
throw new NotResolvedException();
return Result::fail();
}

return ArrayHelper::getValueByPath($parsedBody, $name);
return Result::success(ArrayHelper::getValueByPath($parsedBody, $name));
}
}
2 changes: 1 addition & 1 deletion src/Attribute/Parameter/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Yiisoft\Input\Http\Attribute\Parameter;

use Attribute;
use Yiisoft\Hydrator\ParameterAttributeInterface;
use Yiisoft\Hydrator\Attribute\Parameter\ParameterAttributeInterface;

/**
* Take data for the property or attribute from the query string.
Expand Down
Loading

0 comments on commit 33a1d94

Please sign in to comment.