Add Router to core.
This commit is contained in:
parent
246bbed148
commit
69c761c3b1
58 changed files with 6451 additions and 157 deletions
|
@ -1,7 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Runtime\Bootstrap;
|
||||
use Runtime\Http\Views\Factory as ViewFactory;
|
||||
use Runtime\Contracts\Container\Container;
|
||||
use Runtime\Http\Input\InputHandler;
|
||||
use Runtime\Http\Request;
|
||||
use Runtime\Http\Response;
|
||||
use Runtime\Http\Url;
|
||||
use Runtime\Http\View\Factory as ViewFactory;
|
||||
use Runtime\Router\Route as Router;
|
||||
|
||||
if(!function_exists('app'))
|
||||
{
|
||||
|
@ -19,6 +25,104 @@ if(!function_exists('app'))
|
|||
}
|
||||
}
|
||||
|
||||
if(!function_exists('csrf_token'))
|
||||
{
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
function csrf_token(): ?string
|
||||
{
|
||||
$baseVerifier = Router::router()->getCsrfVerifier();
|
||||
if ($baseVerifier !== null) {
|
||||
return $baseVerifier->getTokenProvider()->getToken();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('dump'))
|
||||
{
|
||||
function dump(...$params)
|
||||
{
|
||||
echo '<pre>';
|
||||
foreach ($params as $param) {
|
||||
var_dump($param);
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('input'))
|
||||
{
|
||||
/**
|
||||
* @param string|null $index Parameter index name
|
||||
* @param string|null $defaultValue Default return value
|
||||
* @param array ...$methods Default methods
|
||||
* @return InputHandler|array|string|null
|
||||
*/
|
||||
function input($index = null, $defaultValue = null, ...$methods)
|
||||
{
|
||||
if ($index !== null) {
|
||||
return request()->getInputHandler()->value($index, $defaultValue, ...$methods);
|
||||
}
|
||||
|
||||
return request()->getInputHandler();
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('redirect'))
|
||||
{
|
||||
/**
|
||||
* @param string $url
|
||||
* @param int|null $code
|
||||
*/
|
||||
function redirect(string $url, ?int $code = null): void
|
||||
{
|
||||
if ($code !== null) {
|
||||
response()->httpCode($code);
|
||||
}
|
||||
|
||||
response()->redirect($url);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('response'))
|
||||
{
|
||||
/**
|
||||
* @return Response
|
||||
*/
|
||||
function response(): Response
|
||||
{
|
||||
return Router::response();
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('request'))
|
||||
{
|
||||
/**
|
||||
* @return Request
|
||||
*/
|
||||
function request(): Request
|
||||
{
|
||||
return Router::request();
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('route'))
|
||||
{
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @param string|array|null $parameters
|
||||
* @param array|null $getParams
|
||||
* @return Url
|
||||
*/
|
||||
function route(?string $name = null, $parameters = null, ?array $getParams = null): Url
|
||||
{
|
||||
return Router::getUrl($name, $parameters, $getParams);
|
||||
}
|
||||
}
|
||||
|
||||
if(!function_exists('view'))
|
||||
{
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue