Skip to content

Commit 3a6d53a

Browse files
committed
namespaced constants
1 parent d9d64be commit 3a6d53a

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

src/About/Explore/Controller.php

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

66
namespace About\Explore;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http\Request;
109
use Mvc5\Http\Response;
1110
use Mvc5\Plugins;
1211

12+
use const Mvc5\{ BODY, CHILD_MODEL };
13+
1314
class Controller
1415
{
1516
/**
@@ -27,8 +28,8 @@ class Controller
2728
*/
2829
function __invoke(Request $request, Response $response, callable $next) : Response
2930
{
30-
$layout = $this->layout([Arg::CHILD_MODEL => $this->view('about/explore')]);
31+
$layout = $this->layout([CHILD_MODEL => $this->view('about/explore')]);
3132

32-
return $next($request, $response->with(Arg::BODY, $this->render($layout)));
33+
return $next($request, $response->with(BODY, $this->render($layout)));
3334
}
3435
}

src/Login/Controller.php

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

66
namespace Login;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugins;
109
use Mvc5\Request\Request;
1110
use Mvc5\Response\HttpResponse;
@@ -14,6 +13,8 @@
1413
use Mvc5\User\User;
1514
use Mvc5\View;
1615

16+
use const Mvc5\{ SESSION, USER };
17+
1718
class Controller
1819
{
1920
/**
@@ -78,6 +79,6 @@ protected function login(Request $request, Session $session, User $user)
7879
*/
7980
function __invoke(Request $request)
8081
{
81-
return $this->login($request, $request[Arg::SESSION], $request[Arg::USER]);
82+
return $this->login($request, $request[SESSION], $request[USER]);
8283
}
8384
}

src/Middleware/Authenticate.php

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

66
namespace Middleware;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugins;
109
use Mvc5\Http\Request;
1110
use Psr\Http\Message\ResponseInterface as Response;
1211

12+
use const Mvc5\USER;
13+
1314
class Authenticate
1415
{
1516
/**
@@ -27,7 +28,7 @@ class Authenticate
2728
*/
2829
function __invoke(Request $request, Response $response, callable $next) : Response
2930
{
30-
return $request[Arg::USER]->authenticated()
31+
return $request[USER]->authenticated()
3132
? $next($request, $response) : $this->redirect($this->url(['app', 'controller' => 'login']));
3233
}
3334
}

src/Middleware/Authorize.php

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

66
namespace Middleware;
77

8-
use Mvc5\Arg;
98
use Mvc5\Plugins;
109
use Mvc5\Http\Request;
1110
use Psr\Http\Message\ResponseInterface as Response;
1211

12+
use const Mvc5\USER;
13+
1314
class Authorize
1415
{
1516
/**
@@ -37,6 +38,6 @@ protected function error() : Response
3738
*/
3839
function __invoke(Request $request, Response $response, callable $next) : Response
3940
{
40-
return 'phpdev' === $request[Arg::USER]->username() ? $next($request, $response) : $this->error();
41+
return 'phpdev' === $request[USER]->username() ? $next($request, $response) : $this->error();
4142
}
4243
}

src/Plugin/Page.php

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

66
namespace Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http\Request;
109
use Mvc5\Plugin\Call;
1110
use Mvc5\Plugin\Invoke;
1211
use Mvc5\Plugin\Plugin;
1312

13+
use const Mvc5\{ REQUEST, VIEW_MODEL };
14+
1415
class Page
1516
extends Call
1617
{
@@ -31,6 +32,6 @@ function __construct(string $template, array $vars = [])
3132
function __invoke(string $template, array $vars) : Invoke
3233
{
3334
return new Invoke(fn(Request $request) =>
34-
new Plugin(Arg::VIEW_MODEL, [$template, $vars + [Arg::REQUEST => $request]]));
35+
new Plugin(VIEW_MODEL, [$template, $vars + [REQUEST => $request]]));
3536
}
3637
}

src/Plugin/Redirect.php

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

66
namespace Plugin;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http\Request;
109
use Mvc5\Plugin\Call;
1110
use Mvc5\Plugin\Invoke;
1211
use Mvc5\Plugin\Plugin;
1312

13+
use const Mvc5\RESPONSE_REDIRECT;
14+
1415
class Redirect
1516
extends Call
1617
{
@@ -32,7 +33,6 @@ function __construct(string $url, int $status = 302, array $headers = [])
3233
*/
3334
function __invoke(string $url, int $status, array $headers) : Invoke
3435
{
35-
return new Invoke(fn(Request $request) =>
36-
new Plugin(Arg::RESPONSE_REDIRECT, [$url, $status, $headers]));
36+
return new Invoke(fn(Request $request) => new Plugin(RESPONSE_REDIRECT, [$url, $status, $headers]));
3737
}
3838
}

0 commit comments

Comments
 (0)