Skip to content

Commit 8c859a8

Browse files
committed
namespaced constants
1 parent 911140b commit 8c859a8

File tree

10 files changed

+63
-36
lines changed

10 files changed

+63
-36
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ use Arc5\Response;
1212
use Arc5\Route;
1313
use Arc5\Service;
1414
use Arc5\View;
15-
use Mvc5\Arg;
1615
use Mvc5\Http\Request as HttpRequest;
1716
use Mvc5\Http\Response as HttpResponse;
1817
use Mvc5\View\ViewModel;
1918
use Mvc5\View\ViewLayout;
2019

20+
use const Mvc5\{ BODY, CONTROLLER, REQUEST, RESPONSE, USER };
21+
2122
Service::context(include __DIR__ . '/../config/config.php');
2223

2324
try {
@@ -30,14 +31,14 @@ try {
3031
$request = Route::error($result);
3132
$result = null;
3233

33-
Service::service()[Arg::REQUEST] = $request;
34+
Service::service()[REQUEST] = $request;
3435

35-
$controller = $request[Arg::CONTROLLER];
36+
$controller = $request[CONTROLLER];
3637

37-
$request = $request->with(Arg::USER, Service::plugin(Arg::USER));
38+
$request = $request->with(USER, Service::plugin(USER));
3839

3940
$controller && $result = Service::call(
40-
$controller, [Arg::REQUEST => $request, Arg::RESPONSE => $response]
41+
$controller, [REQUEST => $request, RESPONSE => $response]
4142
);
4243
}
4344

@@ -49,7 +50,7 @@ try {
4950
}
5051

5152
($result instanceof HttpResponse && $response = $result)
52-
|| $response = $response->with(Arg::BODY, $result);
53+
|| $response = $response->with(BODY, $result);
5354

5455
$response = Response::status($request, $response);
5556
$response = Response::version($request, $response);

functions.php

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

66
namespace Arc5;
77

8-
use Mvc5\Arg;
8+
use const Mvc5\{ CSRF_TOKEN, INDEX };
99

1010
/**
1111
* @return string
12+
* @throws \Throwable
1213
*/
1314
function csrf_token() : string
1415
{
15-
return Session::session(Arg::CSRF_TOKEN);
16+
return Session::session(CSRF_TOKEN);
1617
}
1718

1819
/**
1920
* @param string $name
2021
* @return array
22+
* @throws \Throwable
2123
*/
22-
function message($name = Arg::INDEX)
24+
function message($name = INDEX)
2325
{
2426
return Message::message($name);
2527
}
2628

2729
/**
2830
* @return \Mvc5\Session\SessionMessages
31+
* @throws \Throwable
2932
*/
3033
function messages()
3134
{
@@ -38,6 +41,7 @@ function messages()
3841
* @param string $fragment
3942
* @param array $options
4043
* @return string
44+
* @throws \Throwable
4145
*/
4246
function url($route, $query = '', $fragment = '', array $options = [])
4347
{

src/Facade/App.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
9+
use Throwable;
10+
11+
use const Mvc5\{ EXCEPTION, EXCEPTION_RESPONSE, HTTP_MIDDLEWARE, WEB };
1012

1113
trait App
1214
{
@@ -16,31 +18,32 @@ trait App
1618
use Facade;
1719

1820
/**
19-
* @param \Throwable $exception
21+
* @param Throwable $exception
2022
* @return mixed
23+
* @throws Throwable
2124
*/
22-
static function exception(\Throwable $exception)
25+
static function exception(Throwable $exception)
2326
{
24-
return static::call(Arg::EXCEPTION_RESPONSE, [Arg::EXCEPTION => $exception]);
27+
return static::call(EXCEPTION_RESPONSE, [EXCEPTION => $exception]);
2528
}
2629

2730
/**
2831
* @param array|mixed $config
2932
* @return mixed
30-
* @throws \Throwable
33+
* @throws Throwable
3134
*/
3235
static function middleware($config)
3336
{
34-
return Service::context($config)->call(Arg::HTTP_MIDDLEWARE);
37+
return Service::context($config)->call(HTTP_MIDDLEWARE);
3538
}
3639

3740
/**
3841
* @param array|mixed $config
3942
* @return mixed
40-
* @throws \Throwable
43+
* @throws Throwable
4144
*/
4245
static function web($config)
4346
{
44-
return Service::context($config)->call(Arg::WEB);
47+
return Service::context($config)->call(WEB);
4548
}
4649
}

src/Facade/Config.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
109

10+
use const Mvc5\CONFIG;
11+
1112
trait Config
1213
{
1314
/**
@@ -20,9 +21,10 @@ trait Config
2021

2122
/**
2223
* @return array|mixed
24+
* @throws \Throwable
2325
*/
2426
static function config()
2527
{
26-
return static::plugin(Arg::CONFIG);
28+
return static::plugin(CONFIG);
2729
}
2830
}

src/Facade/Log.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
109

10+
use const Mvc5\{ CONTEXT, LEVEL, LOG, MESSAGE, SEVERITY_CRITICAL };
11+
1112
trait Log
1213
{
1314
/**
@@ -20,9 +21,10 @@ trait Log
2021
* @param array $context
2122
* @param int $level
2223
* @return mixed
24+
* @throws \Throwable
2325
*/
24-
static function log($message, array $context = [], int $level = Arg::SEVERITY_CRITICAL)
26+
static function log($message, array $context = [], int $level = SEVERITY_CRITICAL)
2527
{
26-
return static::call(Arg::LOG, [Arg::LEVEL => $level, Arg::MESSAGE => $message, Arg::CONTEXT => $context]);
28+
return static::call(LOG, [LEVEL => $level, MESSAGE => $message, CONTEXT => $context]);
2729
}
2830
}

src/Facade/Message.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
109
use Mvc5\Session\SessionMessages;
1110

11+
use const Mvc5\SESSION_MESSAGES;
12+
1213
trait Message
1314
{
1415
/**
@@ -19,6 +20,7 @@ trait Message
1920
/**
2021
* @param array|string $message
2122
* @param string|null $name
23+
* @throws \Throwable
2224
*/
2325
static function danger($message, string $name = null) : void
2426
{
@@ -28,6 +30,7 @@ static function danger($message, string $name = null) : void
2830
/**
2931
* @param array|string $message
3032
* @param string|null $name
33+
* @throws \Throwable
3134
*/
3235
static function info($message, string $name = null) : void
3336
{
@@ -37,6 +40,7 @@ static function info($message, string $name = null) : void
3740
/**
3841
* @param array|string|null $name
3942
* @return array|null
43+
* @throws \Throwable
4044
*/
4145
static function message($name = null)
4246
{
@@ -45,15 +49,17 @@ static function message($name = null)
4549

4650
/**
4751
* @return SessionMessages
52+
* @throws \Throwable
4853
*/
4954
static function messages() : SessionMessages
5055
{
51-
return static::plugin(Arg::SESSION_MESSAGES);
56+
return static::plugin(SESSION_MESSAGES);
5257
}
5358

5459
/**
5560
* @param array|string $message
5661
* @param string|null $name
62+
* @throws \Throwable
5763
*/
5864
static function success($message, string $name = null) : void
5965
{
@@ -63,6 +69,7 @@ static function success($message, string $name = null) : void
6369
/**
6470
* @param array|string $message
6571
* @param string|null $name
72+
* @throws \Throwable
6673
*/
6774
static function warning($message, string $name = null) : void
6875
{

src/Facade/Request.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http;
109
use Mvc5\Route\Route;
1110
use Mvc5\Service\Facade;
1211

12+
use const Mvc5\REQUEST;
13+
1314
trait Request
1415
{
1516
/**
@@ -232,7 +233,7 @@ static function query()
232233
*/
233234
static function request() : Http\Request
234235
{
235-
return static::shared(Arg::REQUEST);
236+
return static::shared(REQUEST);
236237
}
237238

238239
/**

src/Facade/Route.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Http\Request;
109
use Mvc5\Service\Facade;
1110

11+
use const Mvc5\URL;
12+
1213
trait Route
1314
{
1415
/**
@@ -19,6 +20,7 @@ trait Route
1920
/**
2021
* @param Request $request
2122
* @return Request|mixed
23+
* @throws \Throwable
2224
*/
2325
static function dispatch(Request $request)
2426
{
@@ -28,6 +30,7 @@ static function dispatch(Request $request)
2830
/**
2931
* @param Request $request
3032
* @return Request|mixed
33+
* @throws \Throwable
3134
*/
3235
static function error(Request $request)
3336
{
@@ -40,9 +43,10 @@ static function error(Request $request)
4043
* @param string|null $fragment
4144
* @param array $options
4245
* @return string|null
46+
* @throws \Throwable
4347
*/
4448
static function url($route = null, $query = null, string $fragment = null, array $options = []) : ?string
4549
{
46-
return static::call(Arg::URL, [$route, $query, $fragment, $options]);
50+
return static::call(URL, [$route, $query, $fragment, $options]);
4751
}
4852
}

src/Facade/Session.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
109

10+
use const Mvc5\SESSION;
11+
1112
trait Session
1213
{
1314
/**
@@ -18,10 +19,11 @@ trait Session
1819
/**
1920
* @param array|string|null $name
2021
* @return \Mvc5\Session\Session|mixed
22+
* @throws \Throwable
2123
*/
2224
static function session($name = null)
2325
{
2426
/** @var \Mvc5\Session\Session $session */
25-
return !($session = static::plugin(Arg::SESSION)) || null === $name ? $session : $session->get($name);
27+
return !($session = static::plugin(SESSION)) || null === $name ? $session : $session->get($name);
2628
}
2729
}

src/Facade/View.php

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

66
namespace Arc5\Facade;
77

8-
use Mvc5\Arg;
98
use Mvc5\Service\Facade;
109
use Mvc5\Template\TemplateLayout;
1110
use Mvc5\Template\TemplateModel;
1211

12+
use const Mvc5\{ LAYOUT, RENDER, TEMPLATE_MODEL, VIEW_MODEL };
13+
1314
trait View
1415
{
1516
/**
@@ -24,7 +25,7 @@ trait View
2425
* @return TemplateLayout|mixed
2526
* @throws \Throwable
2627
*/
27-
static function layout(array $vars = [], string $template = null, string $model = Arg::LAYOUT) : TemplateLayout
28+
static function layout(array $vars = [], string $template = null, string $model = LAYOUT) : TemplateLayout
2829
{
2930
return static::model($vars, $template, $model);
3031
}
@@ -36,9 +37,9 @@ static function layout(array $vars = [], string $template = null, string $model
3637
* @return TemplateModel|mixed
3738
* @throws \Throwable
3839
*/
39-
static function model(array $vars = [], string $template = null, string $model = Arg::VIEW_MODEL) : TemplateModel
40+
static function model(array $vars = [], string $template = null, string $model = VIEW_MODEL) : TemplateModel
4041
{
41-
$template && $vars[Arg::TEMPLATE_MODEL] = $template;
42+
$template && $vars[TEMPLATE_MODEL] = $template;
4243

4344
return !$vars ? static::plugin($model) : static::plugin($model)->with($vars);
4445
}
@@ -51,7 +52,7 @@ static function model(array $vars = [], string $template = null, string $model =
5152
*/
5253
static function render($template, array $vars = []) : string
5354
{
54-
return static::call(Arg::RENDER, [$template, $vars]);
55+
return static::call(RENDER, [$template, $vars]);
5556
}
5657

5758
/**
@@ -61,7 +62,7 @@ static function render($template, array $vars = []) : string
6162
* @return TemplateModel|mixed
6263
* @throws \Throwable
6364
*/
64-
static function template(string $template = null, array $vars = [], string $model = Arg::VIEW_MODEL) : TemplateModel
65+
static function template(string $template = null, array $vars = [], string $model = VIEW_MODEL) : TemplateModel
6566
{
6667
return static::model($vars, $template, $model);
6768
}

0 commit comments

Comments
 (0)