Skip to content

Commit 08e5d0f

Browse files
committed
namespaced constants
1 parent 9381a43 commit 08e5d0f

File tree

11 files changed

+51
-36
lines changed

11 files changed

+51
-36
lines changed

src/Plugin/AcceptsJson.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugin\ScopedCall;
109
use Mvc5\Plugin\Shared;
1110
use Symfony\Component\HttpFoundation\AcceptHeader;
1211

1312
use function array_keys;
1413
use function strpos;
1514

15+
use const Mvc5\HEADERS;
16+
1617
class AcceptsJson
1718
extends Shared
1819
{
@@ -47,6 +48,6 @@ static function match(?string $accept) : bool
4748
*/
4849
function __invoke() : \Closure
4950
{
50-
return fn() => AcceptsJson::match(AcceptsJson::header($this[Arg::HEADERS]['accept']));
51+
return fn() => AcceptsJson::match(AcceptsJson::header($this[HEADERS]['accept']));
5152
}
5253
}

src/Plugin/Authenticated.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
8+
use Closure;
99
use Mvc5\Plugin\ScopedCall;
1010
use Mvc5\Plugin\Shared;
1111

12+
use const Mvc5\{ AUTHENTICATED, USER };
13+
1214
class Authenticated
1315
extends Shared
1416
{
@@ -21,10 +23,10 @@ function __construct(string $name = 'authenticated')
2123
}
2224

2325
/**
24-
* @return \Closure
26+
* @return Closure
2527
*/
26-
function __invoke() : \Closure
28+
function __invoke() : Closure
2729
{
28-
return fn() => $this[Arg::USER][Arg::AUTHENTICATED] ?? false;
30+
return fn() => $this[USER][AUTHENTICATED] ?? false;
2931
}
3032
}

src/Plugin/ClientAddress.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugin\ScopedCall;
109
use Mvc5\Plugin\Shared;
1110

11+
use const Mvc5\SERVER;
12+
1213
class ClientAddress
1314
extends Shared
1415
{
@@ -34,6 +35,6 @@ static function ipAddress(array $server) : string
3435
*/
3536
function __invoke() : \Closure
3637
{
37-
return fn() => ClientAddress::ipAddress($this[Arg::SERVER]);
38+
return fn() => ClientAddress::ipAddress($this[SERVER]);
3839
}
3940
}

src/Plugin/Cookies.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Cookie\HttpCookies;
109
use Mvc5\Plugin\ScopedCall;
1110
use Mvc5\Plugin\Shared;
1211

1312
use function Laminas\Diactoros\parseCookieHeader;
1413

14+
use const Mvc5\HEADERS;
15+
1516
class Cookies
1617
extends Shared
1718
{
@@ -29,7 +30,7 @@ function __construct(string $name = 'cookies')
2930
function __invoke() : \Closure
3031
{
3132
return fn() => new HttpCookies(
32-
isset($this[Arg::HEADERS]['cookie']) ? parseCookieHeader($this[Arg::HEADERS]['cookie']) : $_COOKIE
33+
isset($this[HEADERS]['cookie']) ? parseCookieHeader($this[HEADERS]['cookie']) : $_COOKIE
3334
);
3435
}
3536
}

src/Plugin/Data.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Exception;
109
use Mvc5\Plugin\GlobalVar;
1110
use Mvc5\Plugin\ScopedCall;
@@ -16,6 +15,8 @@
1615
use function json_last_error_msg;
1716
use function strpos;
1817

18+
use const Mvc5\{ BODY, HEADERS };
19+
1920
class Data
2021
extends Shared
2122
{
@@ -62,7 +63,7 @@ static function result($result) : array
6263
*/
6364
function __invoke() : \Closure
6465
{
65-
return fn() => Data::isJson($this[Arg::HEADERS]['content-type']) ?
66-
Data::decode((string) $this[Arg::BODY]) : new GlobalVar('_POST');
66+
return fn() => Data::isJson($this[HEADERS]['content-type']) ?
67+
Data::decode((string) $this[BODY]) : new GlobalVar('_POST');
6768
}
6869
}

src/Plugin/Headers.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
8+
use Closure;
99
use Mvc5\Http\HttpHeaders;
1010
use Mvc5\Plugin\ScopedCall;
1111
use Mvc5\Plugin\Shared;
@@ -15,13 +15,15 @@
1515
marshalUriFromSapi
1616
};
1717

18+
use const Mvc5\{ HEADERS, HOST, SERVER };
19+
1820
class Headers
1921
extends Shared
2022
{
2123
/**
2224
* @param string $name
2325
*/
24-
function __construct(string $name = 'headers')
26+
function __construct(string $name = HEADERS)
2527
{
2628
parent::__construct($name, new ScopedCall($this));
2729
}
@@ -34,8 +36,8 @@ static function headersFromServer(array $server) : HttpHeaders
3436
{
3537
$headers = marshalHeadersFromSapi($server);
3638

37-
!isset($headers[Arg::HOST]) && ($host = static::hostAndPortFromServer($server)) &&
38-
$headers[Arg::HOST] = $host;
39+
!isset($headers[HOST]) && ($host = static::hostAndPortFromServer($server)) &&
40+
$headers[HOST] = $host;
3941

4042
return new HttpHeaders($headers);
4143
}
@@ -51,10 +53,10 @@ protected static function hostAndPortFromServer(array $server) : string
5153
}
5254

5355
/**
54-
* @return \Closure
56+
* @return Closure
5557
*/
56-
function __invoke() : \Closure
58+
function __invoke() : Closure
5759
{
58-
return fn() => Headers::headersFromServer($this[Arg::SERVER]);
60+
return fn() => Headers::headersFromServer($this[SERVER]);
5961
}
6062
}

src/Plugin/Method.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugin\ScopedCall;
109
use Mvc5\Plugin\Shared;
1110

1211
use function strtoupper;
1312

13+
use const Mvc5\{ HEADERS, SERVER };
14+
1415
class Method
1516
extends Shared
1617
{
@@ -28,7 +29,7 @@ function __construct(string $name = 'method')
2829
function __invoke() : \Closure
2930
{
3031
return fn() => strtoupper(
31-
$this[Arg::HEADERS]['X-HTTP-METHOD-OVERRIDE'] ?? ($this[Arg::SERVER]['REQUEST_METHOD'] ?? 'GET')
32+
$this[HEADERS]['X-HTTP-METHOD-OVERRIDE'] ?? ($this[SERVER]['REQUEST_METHOD'] ?? 'GET')
3233
);
3334
}
3435
}

src/Plugin/RequestTarget.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
8+
use Closure;
99
use Mvc5\Plugin\ScopedCall;
1010
use Mvc5\Plugin\Shared;
1111

12+
use const Mvc5\{ PATH, QUERY, URI };
13+
1214
class RequestTarget
1315
extends Shared
1416
{
@@ -21,15 +23,15 @@ function __construct(string $name = 'target')
2123
}
2224

2325
/**
24-
* @return \Closure
26+
* @return Closure
2527
*/
26-
function __invoke() : \Closure
28+
function __invoke() : Closure
2729
{
2830
return function() {
2931
/** @var \Valar\ServerRequest $this */
30-
$uri = $this[Arg::URI];
31-
$query = $uri[Arg::QUERY] ?? '';
32-
$path = $uri[Arg::PATH] ?? '';
32+
$uri = $this[URI];
33+
$query = $uri[QUERY] ?? '';
34+
$path = $uri[PATH] ?? '';
3335
return ($path ?: '/') . ($query ? '?' . $query : '');
3436
};
3537
}

src/Plugin/Uri.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http\Headers;
109
use Mvc5\Plugin\ScopedCall;
1110
use Mvc5\Plugin\Shared;
@@ -15,6 +14,8 @@
1514
use function urldecode;
1615
use function Laminas\Diactoros\marshalUriFromSapi;
1716

17+
use const Mvc5\{ HEADERS, SERVER };
18+
1819
class Uri
1920
extends Shared
2021
{
@@ -51,6 +52,6 @@ static function uri(array $server, Headers $headers) : HttpUri
5152
*/
5253
function __invoke() : \Closure
5354
{
54-
return fn() => Uri::uri($this[Arg::SERVER], $this[Arg::HEADERS]);
55+
return fn() => Uri::uri($this[SERVER], $this[HEADERS]);
5556
}
5657
}

src/Plugin/UserAgent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace Valar\Plugin;
77

8-
use Mvc5\Arg;
8+
use Closure;
99
use Mvc5\Plugin\ScopedCall;
1010
use Mvc5\Plugin\Shared;
1111

12+
use const Mvc5\SERVER;
13+
1214
class UserAgent
1315
extends Shared
1416
{
@@ -21,10 +23,10 @@ function __construct(string $name = 'user_agent')
2123
}
2224

2325
/**
24-
* @return \Closure
26+
* @return Closure
2527
*/
26-
function __invoke() : \Closure
28+
function __invoke() : Closure
2729
{
28-
return fn() => $this[Arg::SERVER]['HTTP_USER_AGENT'] ?? '';
30+
return fn() => $this[SERVER]['HTTP_USER_AGENT'] ?? '';
2931
}
3032
}

0 commit comments

Comments
 (0)