Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

60 Commits

Repository files navigation

Arc5

https://mvc5.github.io

Arc5 provides a set of static classes for the Mvc5 Framework.

Example web application.

useArc5\App;
useArc5\Request;
useArc5\Response;
useArc5\Route;
useArc5\Service;
useArc5\View;
useMvc5\Http\RequestasHttpRequest;
useMvc5\Http\ResponseasHttpResponse;
useMvc5\View\ViewModel;
useMvc5\View\ViewLayout;
useconstMvc5\{ BODY, CONTROLLER, REQUEST, RESPONSE, USER };
Service::context(include__DIR__ . '/../config/config.php');
try {
$request = Request::request();
$response = Response::response();
$result = Route::dispatch($request);
if ($resultinstanceof HttpRequest) {
$request = Route::error($result);
$result = null;
Service::service()[REQUEST] = $request;
$controller = $request[CONTROLLER];
$request = $request->with(USER, Service::plugin(USER));
$controller && $result = Service::call(
$controller, [REQUEST => $request, RESPONSE => $response]
);
}
if ($resultinstanceof ViewModel) {
!$resultinstanceof ViewLayout && ($layout = View::layout())
&& $result = $layout->withModel($result);
$result = View::render($result);
}
($resultinstanceof HttpResponse && $response = $result)
|| $response = $response->with(BODY, $result);
$response = Response::status($request, $response);
$response = Response::version($request, $response);
Response::send($response);
} catch(\Throwable$exception) {
App::exception($exception);
}

Aliases

Short names can be used to alias class names by registering an alias autoload function and providing an alias configuration.

spl_autoload_register(newMvc5\Service\Alias(include__DIR__ . '/config/alias.php'));

When a class cannot be found by the default autoloader (i.e. composer) and it has an alias, the PHP class_alias method is called; which will call the autoload mechanism again if the aliased class does not already exist. Below is an example alias configuration.

return [
'Config' => Arc5\Config::class,
'Log' => Arc5\Log::class,
'Message' => Arc5\Message::class,
'Request' => Arc5\Request::class,
'Response' => Arc5\Response::class,
'Route' => Arc5\Route::class,
'Service' => Arc5\Service::class,
'Session' => Arc5\Session::class,
'View' => Arc5\View::class,
];

Example using aliases.

useResponse;
useView;
return Response::response(View::render('about/more'));

Mvc5 Framework Configuration

To use static classes within the Mvc5 Framework, the service context needs to be initialized during the web event or middleware stack. Each of the following should be added to their respective configurations.

'service\context', //web event'web\context', //middleware

The corresponding service configurations already exist in the Mvc5 service config.

'service\context' => newInvoke(Mvc5\Service\Context::class, ['service' => newLink]),
'web\context' => [Mvc5\Web\Context::class, newLink],

Arc5 automatically provides functions that can be imported into the View5 Template Engine. The following service configuration automatically imports these functions into each template.

'view5\template' => [ViewTemplate::class, ['import' => ['arc5']]],

The functions currently provided are message, messages and url.

About

Static classes for the Mvc5 Framework

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages