mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-03 16:21:50 +02:00
Initial upload of the control panel
This commit is contained in:
parent
f21bd93fbc
commit
7eab26586c
791 changed files with 312718 additions and 0 deletions
123
cp/bootstrap/app.php
Normal file
123
cp/bootstrap/app.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
|
||||
use App\Lib\Logger;
|
||||
use DI\Container;
|
||||
use Slim\Csrf\Guard;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\Handlers\Strategies\RequestResponseArgs;
|
||||
use Slim\Views\Twig;
|
||||
use Slim\Views\TwigMiddleware;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
require __DIR__ . '/helper.php';
|
||||
|
||||
try {
|
||||
Dotenv\Dotenv::createImmutable(__DIR__. '/../')->load();
|
||||
} catch (\Dotenv\Exception\InvalidPathException $e) {
|
||||
//
|
||||
}
|
||||
//Enable error display in details when APP_ENV=local
|
||||
if(envi('APP_ENV')=='local') {
|
||||
Logger::systemLogs(true);
|
||||
}else{
|
||||
Logger::systemLogs(false);
|
||||
}
|
||||
|
||||
$container = new Container();
|
||||
// Set container to create App with on AppFactory
|
||||
AppFactory::setContainer($container);
|
||||
|
||||
$app = AppFactory::create();
|
||||
|
||||
$responseFactory = $app->getResponseFactory();
|
||||
|
||||
$routeCollector = $app->getRouteCollector();
|
||||
$routeCollector->setDefaultInvocationStrategy(new RequestResponseArgs());
|
||||
$routeParser = $app->getRouteCollector()->getRouteParser();
|
||||
|
||||
require_once __DIR__ . '/database.php';
|
||||
|
||||
$container->set('router', function () use ($routeParser) {
|
||||
return $routeParser;
|
||||
});
|
||||
|
||||
$container->set('db', function () use ($db) {
|
||||
return $db;
|
||||
});
|
||||
|
||||
$container->set('pdo', function () use ($pdo) {
|
||||
return $pdo;
|
||||
});
|
||||
|
||||
$container->set('auth', function() {
|
||||
return new \App\Auth\Auth;
|
||||
});
|
||||
|
||||
$container->set('flash', function() {
|
||||
return new \Slim\Flash\Messages;
|
||||
});
|
||||
|
||||
$container->set('view', function ($container) {
|
||||
$view = Twig::create(__DIR__ . '/../resources/views', [
|
||||
'cache' => false,
|
||||
]);
|
||||
$view->getEnvironment()->addGlobal('auth', [
|
||||
'isLogin' => $container->get('auth')->isLogin(),
|
||||
'user' => $container->get('auth')->user(),
|
||||
]);
|
||||
$view->getEnvironment()->addGlobal('flash', $container->get('flash'));
|
||||
if (isset($_SESSION['_screen_mode'])) {
|
||||
$view->getEnvironment()->addGlobal('screen_mode', $_SESSION['_screen_mode']);
|
||||
} else {
|
||||
$view->getEnvironment()->addGlobal('screen_mode', 'light');
|
||||
}
|
||||
|
||||
//route
|
||||
$route = new TwigFunction('route', function ($name) {
|
||||
return route($name);
|
||||
});
|
||||
$view->getEnvironment()->addFunction($route);
|
||||
|
||||
// Define the route_is function
|
||||
$routeIs = new \Twig\TwigFunction('route_is', function ($routeName) {
|
||||
return strpos($_SERVER['REQUEST_URI'], $routeName) !== false;
|
||||
});
|
||||
$view->getEnvironment()->addFunction($routeIs);
|
||||
|
||||
//assets
|
||||
$assets = new TwigFunction('assets', function ($location) {
|
||||
return assets($location);
|
||||
});
|
||||
$view->getEnvironment()->addFunction($assets);
|
||||
|
||||
//Pagination
|
||||
$pagination = new TwigFunction("links", function ($object) {
|
||||
|
||||
});
|
||||
$view->getEnvironment()->addFunction($pagination);
|
||||
|
||||
return $view;
|
||||
});
|
||||
$app->add(TwigMiddleware::createFromContainer($app));
|
||||
|
||||
$container->set('validator', function ($container) {
|
||||
return new App\Lib\Validator;
|
||||
});
|
||||
|
||||
$container->set('csrf', function($container) use ($responseFactory) {
|
||||
return new Guard($responseFactory);
|
||||
});
|
||||
|
||||
$app->add(new \App\Middleware\ValidationErrorsMiddleware($container));
|
||||
$app->add(new \App\Middleware\OldInputMiddleware($container));
|
||||
$app->add(new \App\Middleware\CsrfViewMiddleware($container));
|
||||
|
||||
$app->add('csrf');
|
||||
$app->setBasePath(routePath());
|
||||
|
||||
require __DIR__ . '/../routes/web.php';
|
Loading…
Add table
Add a link
Reference in a new issue