This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
generated from yiisoft/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
491 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
final class BodyResolver implements HandlerParameterResolverInterface | ||
{ | ||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed | ||
{ | ||
if ($attribute::class !== Body::class) { | ||
throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Body::class, $attribute::class)); | ||
} | ||
|
||
if ($attribute->getName() !== null) { | ||
return $request->getParsedBody()[$attribute->getName()] ?? null; | ||
} | ||
|
||
return $request->getParsedBody(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
/** | ||
* Represents action handler parameter [attribute](https://www.php.net/manual/en/language.attributes.php). | ||
*/ | ||
interface HandlerParameterResolverInterface | ||
{ | ||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
final class QueryResolver implements HandlerParameterResolverInterface | ||
{ | ||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed | ||
{ | ||
if ($attribute::class !== Query::class) { | ||
throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Query::class, $attribute::class)); | ||
} | ||
|
||
if ($attribute->getName() !== null) { | ||
return $request->getQueryParams()[$attribute->getName()] ?? null; | ||
} | ||
|
||
return $request->getQueryParams(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
final class RequestResolver implements HandlerParameterResolverInterface | ||
{ | ||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed | ||
{ | ||
if ($attribute::class !== Request::class) { | ||
throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Request::class, $attribute::class)); | ||
} | ||
|
||
return $request->getAttribute($attribute->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Yiisoft\Router\CurrentRoute; | ||
|
||
final class RouteResolver implements HandlerParameterResolverInterface | ||
{ | ||
public function __construct(private CurrentRoute $currentRoute) | ||
{ | ||
} | ||
|
||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): mixed | ||
{ | ||
if ($attribute::class !== Route::class) { | ||
throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', Route::class, $attribute::class)); | ||
} | ||
|
||
return $this->currentRoute->getArgument($attribute->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\RequestModel\Attribute; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
final class UploadedFilesResolver implements HandlerParameterResolverInterface | ||
{ | ||
public function resolve(HandlerParameterAttributeInterface $attribute, ServerRequestInterface $request): array | ||
{ | ||
if ($attribute::class !== UploadedFiles::class) { | ||
throw new \InvalidArgumentException(sprintf('Expected "%s", got "%s".', UploadedFiles::class, $attribute::class)); | ||
} | ||
|
||
return $request->getUploadedFiles(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.