More loader
This commit is contained in:
parent
0951285ff8
commit
7461a42586
@ -1,11 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Api\Login;
|
|
||||||
|
|
||||||
class Login
|
|
||||||
{
|
|
||||||
public function get()
|
|
||||||
{
|
|
||||||
echo "LOGIN HANDLER GET";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
11
exam/api/Login/Login.php
Normal file
11
exam/api/Login/Login.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Api\Login;
|
||||||
|
|
||||||
|
class Login
|
||||||
|
{
|
||||||
|
public function post()
|
||||||
|
{
|
||||||
|
echo "LOGIN HANDLER post";
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,8 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Api\\": "Api/"
|
"Api\\": "api/",
|
||||||
|
"Pages\\": "pages/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,8 @@ ini_set('session.use_only_cookies', 1);
|
|||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
// Load composer Autoloader
|
// Load composer Autoloader
|
||||||
require_once __DIR__ . "/vendor/autoload.php";
|
require_once __DIR__ . "/vendor/autoload.php";
|
||||||
|
// Helpers
|
||||||
|
require_once __DIR__ . "/utils/helpers.php";
|
||||||
// Namespaces
|
// Namespaces
|
||||||
use Pecee\SimpleRouter\SimpleRouter;
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
use Pecee\SimpleRouter\Handlers\EventHandler;
|
use Pecee\SimpleRouter\Handlers\EventHandler;
|
||||||
|
|||||||
13
exam/pages/NotFound/NotFound.php
Normal file
13
exam/pages/NotFound/NotFound.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pages\NotFound;
|
||||||
|
|
||||||
|
class NotFound
|
||||||
|
{
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
echo <<<END
|
||||||
|
<h1>Not Found</h1>
|
||||||
|
END;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Namespaces
|
||||||
use Pecee\SimpleRouter\SimpleRouter;
|
use Pecee\SimpleRouter\SimpleRouter;
|
||||||
use Api\Login\Login;
|
use Pecee\Http\Request;
|
||||||
|
/*
|
||||||
|
SimpleRouter::error(function (Request $request, \Exception $exception) {
|
||||||
|
switch ($exception->getCode()) {
|
||||||
|
// Page not found
|
||||||
|
case 404:
|
||||||
|
redirect('/phpCourse/exam/not-found', 404);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
//404
|
||||||
|
SimpleRouter::get('/not-found', [Pages\NotFound\NotFound::class, "render"]);
|
||||||
|
//Index
|
||||||
SimpleRouter::get('/', function () {
|
SimpleRouter::get('/', function () {
|
||||||
return 'Hello world';
|
return 'Hello world';
|
||||||
});
|
});
|
||||||
|
//API
|
||||||
$l = new Login();
|
SimpleRouter::get("/api/login", [Api\Login\Login::class, 'post']);
|
||||||
|
|
||||||
SimpleRouter::get("/api/login", [Login::class, 'get']);
|
|
||||||
|
|||||||
3
exam/utils/.htaccess
Normal file
3
exam/utils/.htaccess
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Order deny,allow
|
||||||
|
Deny from all
|
||||||
|
Allow from 127.0.0.1
|
||||||
88
exam/utils/helpers.php
Normal file
88
exam/utils/helpers.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pecee\SimpleRouter\SimpleRouter as Router;
|
||||||
|
use Pecee\Http\Url;
|
||||||
|
use Pecee\Http\Response;
|
||||||
|
use Pecee\Http\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get url for a route by using either name/alias, class or method name.
|
||||||
|
*
|
||||||
|
* The name parameter supports the following values:
|
||||||
|
* - Route name
|
||||||
|
* - Controller/resource name (with or without method)
|
||||||
|
* - Controller class name
|
||||||
|
*
|
||||||
|
* When searching for controller/resource by name, you can use this syntax "route.name@method".
|
||||||
|
* You can also use the same syntax when searching for a specific controller-class "MyController@home".
|
||||||
|
* If no arguments is specified, it will return the url for the current loaded route.
|
||||||
|
*
|
||||||
|
* @param string|null $name
|
||||||
|
* @param string|array|null $parameters
|
||||||
|
* @param array|null $getParams
|
||||||
|
* @return \Pecee\Http\Url
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*/
|
||||||
|
function url(?string $name = null, $parameters = null, ?array $getParams = null): Url
|
||||||
|
{
|
||||||
|
return Router::getUrl($name, $parameters, $getParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Pecee\Http\Response
|
||||||
|
*/
|
||||||
|
function response(): Response
|
||||||
|
{
|
||||||
|
return Router::response();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Pecee\Http\Request
|
||||||
|
*/
|
||||||
|
function request(): Request
|
||||||
|
{
|
||||||
|
return Router::request();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get input class
|
||||||
|
* @param string|null $index Parameter index name
|
||||||
|
* @param string|mixed|null $defaultValue Default return value
|
||||||
|
* @param array ...$methods Default methods
|
||||||
|
* @return \Pecee\Http\Input\InputHandler|array|string|null
|
||||||
|
*/
|
||||||
|
function input($index = null, $defaultValue = null, ...$methods)
|
||||||
|
{
|
||||||
|
if ($index !== null) {
|
||||||
|
return request()->getInputHandler()->value($index, $defaultValue, ...$methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
return request()->getInputHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $url
|
||||||
|
* @param int|null $code
|
||||||
|
*/
|
||||||
|
function redirect(string $url, ?int $code = null): void
|
||||||
|
{
|
||||||
|
if ($code !== null) {
|
||||||
|
response()->httpCode($code);
|
||||||
|
}
|
||||||
|
|
||||||
|
response()->redirect($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current csrf-token
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
function csrf_token(): ?string
|
||||||
|
{
|
||||||
|
$baseVerifier = Router::router()->getCsrfVerifier();
|
||||||
|
if ($baseVerifier !== null) {
|
||||||
|
return $baseVerifier->getTokenProvider()->getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
3
exam/vendor/composer/autoload_psr4.php
vendored
3
exam/vendor/composer/autoload_psr4.php
vendored
@ -7,5 +7,6 @@ $baseDir = dirname($vendorDir);
|
|||||||
|
|
||||||
return array(
|
return array(
|
||||||
'Pecee\\' => array($vendorDir . '/pecee/simple-router/src/Pecee'),
|
'Pecee\\' => array($vendorDir . '/pecee/simple-router/src/Pecee'),
|
||||||
'Api\\' => array($baseDir . '/Api'),
|
'Api\\' => array($baseDir . '/api'),
|
||||||
|
'Pages\\' => array($baseDir . '/pages'),
|
||||||
);
|
);
|
||||||
|
|||||||
10
exam/vendor/composer/autoload_static.php
vendored
10
exam/vendor/composer/autoload_static.php
vendored
@ -9,22 +9,27 @@ class ComposerStaticInitd067465d9a99de373ba3093d61eda1d8
|
|||||||
public static $prefixLengthsPsr4 = array(
|
public static $prefixLengthsPsr4 = array(
|
||||||
'P' =>
|
'P' =>
|
||||||
array(
|
array(
|
||||||
|
'Pages\\' => 6,
|
||||||
'Pecee\\' => 6,
|
'Pecee\\' => 6,
|
||||||
),
|
),
|
||||||
'A' =>
|
'A' =>
|
||||||
array(
|
array(
|
||||||
'Api\\' => 4,
|
'api\\' => 4,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
public static $prefixDirsPsr4 = array(
|
public static $prefixDirsPsr4 = array(
|
||||||
|
'Pages\\' =>
|
||||||
|
array(
|
||||||
|
0 => __DIR__ . '/..' . '/pages',
|
||||||
|
),
|
||||||
'Pecee\\' =>
|
'Pecee\\' =>
|
||||||
array(
|
array(
|
||||||
0 => __DIR__ . '/..' . '/pecee/simple-router/src/Pecee',
|
0 => __DIR__ . '/..' . '/pecee/simple-router/src/Pecee',
|
||||||
),
|
),
|
||||||
'Api\\' =>
|
'Api\\' =>
|
||||||
array(
|
array(
|
||||||
0 => __DIR__ . '/../..' . '/Api',
|
0 => __DIR__ . '/../..' . '/api',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -38,7 +43,6 @@ class ComposerStaticInitd067465d9a99de373ba3093d61eda1d8
|
|||||||
$loader->prefixLengthsPsr4 = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$classMap;
|
$loader->classMap = ComposerStaticInitd067465d9a99de373ba3093d61eda1d8::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user