Skip to content

Commit 2b8e1ae

Browse files
authored
Merge pull request #9 from ray-di/named-args
Implements NamedArgumentConstructorAnnotation
2 parents 1cbf443 + 4d38dc7 commit 2b8e1ae

File tree

8 files changed

+16
-23
lines changed

8 files changed

+16
-23
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"annotation"
66
],
77
"require": {
8-
"php": "^5.4 || ^7.0 || ^8.0"
8+
"php": "^5.4 || ^7.0 || ^8.0",
9+
"doctrine/annotations": "^1.11"
910
},
1011
"license": "MIT",
1112
"autoload":{

src/Annotation/AbstractWebContextParam.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace Ray\WebContextParam\Annotation;
44

5-
use function is_array;
6-
use function is_string;
5+
use Doctrine\Common\Annotations\NamedArgumentConstructorAnnotation;
76

8-
abstract class AbstractWebContextParam
7+
abstract class AbstractWebContextParam implements NamedArgumentConstructorAnnotation
98
{
109
/**
1110
* Key of Super global value
@@ -22,23 +21,16 @@ abstract class AbstractWebContextParam
2221
/**
2322
* Parameter(Variable) name
2423
*
24+
* This parameter is used to specify a parameter from a method in PHP7,
25+
* and is not needed when attributing to a parameter in PHP8.
26+
*
2527
* @var string
2628
*/
2729
public $param;
2830

29-
/**
30-
* @param string|array{key?: string, param?: string} $values
31-
*/
32-
public function __construct($key)
31+
public function __construct(string $key, string $param = '')
3332
{
34-
if (is_array($key)) {
35-
$this->key = $key['key'];
36-
$this->param = $key['param'];
37-
38-
return;
39-
}
40-
if (is_string($key)) {
41-
$this->key = $key;
42-
}
33+
$this->key = $key;
34+
$this->param = $param;
4335
}
4436
}

src/Annotation/CookieParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class CookieParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_COOKIE';

src/Annotation/EnvParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class EnvParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_ENV';

src/Annotation/FilesParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class FilesParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_FILES';

src/Annotation/FormParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class FormParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_POST';

src/Annotation/QueryParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class QueryParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_GET';

src/Annotation/ServerParam.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @Annotation
99
* @Target("METHOD")
1010
*/
11-
#[Attribute(Attribute::TARGET_PARAMETER)]
11+
#[Attribute(Attribute::TARGET_PARAMETER | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
1212
final class ServerParam extends AbstractWebContextParam
1313
{
1414
const GLOBAL_KEY = '_SERVER';

0 commit comments

Comments
 (0)