mirror of
https://github.com/getnamingo/registry.git
synced 2025-08-05 01:01:30 +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';
|
28
cp/bootstrap/database.php
Normal file
28
cp/bootstrap/database.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
$config = config('connections');
|
||||
// MySQL Connection
|
||||
if (config('default') == 'mysql') {
|
||||
$pdo = new \PDO($config['mysql']['driver'].':dbname='.$config['mysql']['database'].';host='.$config['mysql']['host'].';charset='.$config['mysql']['charset'].'', $config['mysql']['username'], $config['mysql']['password']);
|
||||
$db = \Pinga\Db\PdoDatabase::fromPdo($pdo);
|
||||
}
|
||||
// SQLite Connection
|
||||
elseif (config('default') == 'sqlite') {
|
||||
$pdo = new PDO($config['sqlite']['driver'].":".$config['sqlite']['driver']);
|
||||
$db = \Pinga\Db\PdoDatabase::fromPdo($pdo);
|
||||
}
|
||||
// PostgreSQL Connection
|
||||
elseif (config('default') == 'pgsql') {
|
||||
$pdo = new \PDO($config['pgsql']['driver'].':dbname='.$config['pgsql']['database'].';host='.$config['pgsql']['host'].';charset='.$config['pgsql']['charset'].'', $config['pgsql']['username'], $config['pgsql']['password']);
|
||||
$db = \Pinga\Db\PdoDatabase::fromPdo($pdo);
|
||||
}
|
||||
// SQL Server Connection
|
||||
elseif (config('default') == 'sqlsrv') {
|
||||
$pdo = new PDO($config['sqlsrv']['driver']."sqlsrv:server=".$config['sqlsrv']['host'].";".$config['sqlsrv']['database'], $config['sqlsrv']['username'], $config['sqlsrv']['password']);
|
||||
$db = \Pinga\Db\PdoDatabase::fromPdo($pdo);
|
||||
}
|
||||
// MySQL Connection as default
|
||||
else{
|
||||
$pdo = new \PDO($config['mysql']['driver'].':dbname='.$config['mysql']['database'].';host='.$config['mysql']['host'].';charset='.$config['mysql']['charset'].'', $config['mysql']['username'], $config['mysql']['password']);
|
||||
$db = \Pinga\Db\PdoDatabase::fromPdo($pdo);
|
||||
}
|
169
cp/bootstrap/helper.php
Normal file
169
cp/bootstrap/helper.php
Normal file
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper functions
|
||||
* @author Hezekiah O. <support@hezecom.com>
|
||||
*/
|
||||
|
||||
use Pinga\Auth\Auth;
|
||||
|
||||
/**
|
||||
* @return mixed|string|string[]
|
||||
*/
|
||||
function routePath() {
|
||||
if (isset($_SERVER['REQUEST_URI'])) {
|
||||
$scriptDir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
|
||||
$uri = (string) parse_url('http://a' . $_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
|
||||
if (stripos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
|
||||
return $_SERVER['SCRIPT_NAME'];
|
||||
}
|
||||
if ($scriptDir !== '/' && stripos($uri, $scriptDir) === 0) {
|
||||
return $scriptDir;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @return mixed|null
|
||||
*/
|
||||
function config($key, $default=null){
|
||||
return \App\Lib\Config::get($key, $default);
|
||||
}
|
||||
/**
|
||||
* @param $var
|
||||
* @return mixed
|
||||
*/
|
||||
function envi($var, $default=null)
|
||||
{
|
||||
if(isset($_ENV[$var])){
|
||||
return $_ENV[$var];
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start session
|
||||
*/
|
||||
function startSession(){
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $var
|
||||
* @return mixed
|
||||
*/
|
||||
function session($var){
|
||||
if (isset($_SESSION[$var])) {
|
||||
return $_SESSION[$var];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global PDO connection
|
||||
* @return \DI\|mixed|PDO
|
||||
* @throws \DI\DependencyException
|
||||
* @throws \DI\NotFoundException
|
||||
*/
|
||||
function pdo(){
|
||||
global $container;
|
||||
return $container->get('pdo');
|
||||
|
||||
}
|
||||
/**
|
||||
* @return Auth
|
||||
*/
|
||||
function auth(){
|
||||
$db = pdo();
|
||||
$auth = new Auth($db);
|
||||
return $auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param array $params1
|
||||
* @param array $params2
|
||||
* @return mixed
|
||||
* @throws \DI\DependencyException
|
||||
* @throws \DI\NotFoundException
|
||||
*/
|
||||
function route($name, $params1 =[], $params2=[]){
|
||||
global $container;
|
||||
return $container->get('router')->urlFor($name,$params1,$params2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dir
|
||||
* @return string
|
||||
*/
|
||||
function baseUrl(){
|
||||
$root = "";
|
||||
$root .= !empty($_SERVER['HTTPS']) ? 'https' : 'http';
|
||||
$root .= '://' . $_SERVER['HTTP_HOST'];
|
||||
return $root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $name
|
||||
* @return string
|
||||
*/
|
||||
function url($url=null, $params1 =[], $params2=[]){
|
||||
if($url){
|
||||
return baseUrl().route($url,$params1,$params2);
|
||||
}
|
||||
return baseUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resp
|
||||
* @param $page
|
||||
* @param array $arr
|
||||
* @return mixed
|
||||
* @throws \DI\DependencyException
|
||||
* @throws \DI\NotFoundException
|
||||
*/
|
||||
function view($resp, $page, $arr=[]){
|
||||
global $container;
|
||||
return $container->get('view')->render($resp, $page, $arr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param $message
|
||||
* @return mixed
|
||||
* @throws \DI\DependencyException
|
||||
* @throws \DI\NotFoundException
|
||||
*/
|
||||
function flash($type, $message){
|
||||
global $container;
|
||||
return $container->get('flash')->addMessage($type, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \App\Lib\Redirect
|
||||
*/
|
||||
function redirect()
|
||||
{
|
||||
return new \App\Lib\Redirect();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $location
|
||||
* @return string
|
||||
*/
|
||||
function assets($location){
|
||||
return url().dirname($_SERVER["REQUEST_URI"]).'/'.$location;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
function toArray($data){
|
||||
return json_decode(json_encode($data), true);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue