Skip to content

Commit

Permalink
Merge pull request #9 from ray-di/named-args
Browse files Browse the repository at this point in the history
 Implements NamedArgumentConstructorAnnotation
  • Loading branch information
koriym authored Jan 18, 2021
2 parents 1cbf443 + 4d38dc7 commit 2b8e1ae
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 23 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"annotation"
],
"require": {
"php": "^5.4 || ^7.0 || ^8.0"
"php": "^5.4 || ^7.0 || ^8.0",
"doctrine/annotations": "^1.11"
},
"license": "MIT",
"autoload":{
Expand Down
24 changes: 8 additions & 16 deletions src/Annotation/AbstractWebContextParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace Ray\WebContextParam\Annotation;

use function is_array;
use function is_string;
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;

abstract class AbstractWebContextParam
abstract class AbstractWebContextParam implements NamedArgumentConstructorAnnotation
{
/**
* Key of Super global value
Expand All @@ -22,23 +21,16 @@ abstract class AbstractWebContextParam
/**
* Parameter(Variable) name
*
* This parameter is used to specify a parameter from a method in PHP7,
* and is not needed when attributing to a parameter in PHP8.
*
* @var string
*/
public $param;

/**
* @param string|array{key?: string, param?: string} $values
*/
public function __construct($key)
public function __construct(string $key, string $param = '')
{
if (is_array($key)) {
$this->key = $key['key'];
$this->param = $key['param'];

return;
}
if (is_string($key)) {
$this->key = $key;
}
$this->key = $key;
$this->param = $param;
}
}
2 changes: 1 addition & 1 deletion src/Annotation/CookieParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class CookieParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_COOKIE';
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/EnvParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class EnvParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_ENV';
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/FilesParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class FilesParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_FILES';
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/FormParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class FormParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_POST';
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/QueryParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class QueryParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_GET';
Expand Down
2 changes: 1 addition & 1 deletion src/Annotation/ServerParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @Annotation
* @Target("METHOD")
*/
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final class ServerParam extends AbstractWebContextParam
{
const GLOBAL_KEY = '_SERVER';
Expand Down

0 comments on commit 2b8e1ae

Please sign in to comment.