remove src folder

This commit is contained in:
Gregory Letellier
2023-11-14 12:03:02 +01:00
parent db32b2e046
commit 8bd8e86748
12 changed files with 416 additions and 628 deletions

View File

@@ -1,6 +1,6 @@
<?php
namespace Kletellier\MiniWeb\Commands;
namespace App\Commands;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;

View File

@@ -1,8 +1,8 @@
<?php
namespace Kletellier\MiniWeb\Controllers;
namespace App\Controllers;
use Kletellier\MiniWeb\Core\Controllers\Controller;
use Kletellier\Framework\Core\Controllers\Controller;
use DateTimeZone;
class Home extends Controller

View File

@@ -5,18 +5,17 @@
"license": "MIT",
"require": {
"php": "~8.1",
"kletellier/pdowrapper": "dev-master",
"symfony/http-kernel": "^6.3",
"bramus/router": "~1.6",
"filp/whoops": "^2.15",
"symfony/var-dumper": "^6.3",
"eftec/bladeone": "^4.9",
"symfony/console": "^6.3"
"greg/framework": "dev-master",
"kletellier/pdowrapper": "dev-master"
},
"repositories": [
{
"type": "git",
"url": "https://git.kletellier.xyz/greg/PdoWrapper.git"
"url": "https://git.kletellier.xyz/greg/framework.git"
},
{
"type": "git",
"url": "https://git.kletellier.xyz/greg/pdowrapper.git"
}
],
"require-dev": {
@@ -26,14 +25,12 @@
},
"autoload": {
"psr-4": {
"Kletellier\\MiniWeb\\": "src",
"App\\": "app"
},
"files": ["src/helpers.php"]
}
},
"autoload-dev": {
"psr-4": {
"Kletellier\\MiniWeb\\tests\\": "tests/"
"App\\tests\\": "tests/"
}
},
"config": {

705
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,11 +25,11 @@ function findCommandClasses($directory)
/**
* Enable autoload
*/
require_once ROOT . DS . 'vendor'. DS . 'autoload.php';
require_once ROOT . DIRECTORY_SEPARATOR . 'vendor'. DIRECTORY_SEPARATOR . 'autoload.php';
$application = new Application();
// Load all commands in Commands folder
$command_directory = ROOT . DS . 'src' . DS . "Commands";
$command_directory = ROOT . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . "Commands";
$commandClasses = findCommandClasses($command_directory);
foreach ($commandClasses as $commandClass) {
$clsname = "App\\Commands\\$commandClass";

View File

@@ -1,3 +1,3 @@
<?php
$router->get('/', '\Kletellier\MiniWeb\Controllers\Home@index');
$router->get('/', '\App\Controllers\Home@index');

View File

View File

@@ -1,112 +0,0 @@
<?php
namespace Kletellier\MiniWeb\Core\Controllers;
use Kletellier\MiniWeb\Core\Kernel\Templating;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
abstract class Controller
{
protected $_cookies;
protected $_cookiestodelete;
protected Request $_request;
/**
* Controller constructor
*
* @param String $controller controller name
* @param String $action action to execute
*/
function __construct()
{
$this->_cookies = array();
$this->_cookiestodelete = array();
$this->_request = Request::createFromGlobals();
}
public function render($content, $status = 200, $headers = array('Content-Type' => 'text/html')): void
{
$this->getResponse($content, $status, $headers)->send();
}
/**
* Return instance of Symfony Response Component
* @return type
*/
private function getResponse($content, $status = 200, $headers = array('Content-Type' => 'text/html')): Response
{
$response = new Response($content, $status, $headers);
foreach ($this->_cookies as $cookie) {
$response->headers->setCookie($cookie);
}
foreach ($this->_cookiestodelete as $cookie) {
$response->headers->clearCookie($cookie);
}
return $response;
}
/**
* Return instance of Symfony Request component
*/
public function request(): Request
{
return $this->_request;
}
/**
* Return Html from view
*/
public function renderView($view, $params = []): string
{
return Templating::getInstance()->render($view, $params);
}
/**
* Add cookie to response
* @param type \Symfony\Component\HttpFoundation\Cookie $cookie
* @return void
*/
public function addCookie(\Symfony\Component\HttpFoundation\Cookie $cookie)
{
array_push($this->_cookies, $cookie);
}
/**
* Cookie to remove in response
* @param string $cookie cookie name to delete
* @return void
*/
public function removeCookie($cookie)
{
array_push($this->_cookiestodelete, $cookie);
}
/**
* Return a Json Response
*
* @param object $var object to be serialized in JSON
*/
public function renderJSON($var)
{
$response = new Response(json_encode($var));
$response->headers->set('Content-Type', 'application/json');
$response->send();
}
public function redirecting($url)
{
$response = new \Symfony\Component\HttpFoundation\RedirectResponse($url);
foreach ($this->_cookies as $cookie) {
$response->headers->setCookie($cookie);
}
foreach ($this->_cookiestodelete as $cookie) {
$response->headers->clearCookie($cookie);
}
$response->send();
}
function __destruct()
{
}
}

View File

@@ -1,101 +0,0 @@
<?php
namespace Kletellier\MiniWeb\Core\Kernel;
use Kletellier\MiniWeb\Core\Routing\Router;
use Dotenv\Dotenv;
use Kletellier\PdoWrapper\Connection;
class Application
{
protected Router $router;
protected $_whoops;
public function __construct()
{
// enable error reporting
$this->setReporting();
try {
$dotenv = Dotenv::createImmutable(ROOT);
$dotenv->load();
} catch (\Throwable $th) {
e($th->getMessage());
die();
}
if ($this->isDebug()) {
$this->_whoops = new \Whoops\Run();
$handler = new \Whoops\Handler\PrettyPageHandler();
$this->_whoops->pushHandler($handler);
$this->_whoops->register();
}
$db_config = $this->getDatabaseConfig();
if (!empty($db_config)) {
// Initialize DB system
Connection::init($db_config, array_keys($db_config));
}
// Init router
$this->router = new Router();
}
private function isDebug(): bool
{
$ret = true;
if (isset($_ENV["DEBUG"])) {
$ret = ($_ENV["DEBUG"] == "true");
}
return $ret;
}
private function getDatabaseConfig(): array
{
$ret = [];
$connections = isset($_ENV["CONNECTIONS"]) ? explode(",", $_ENV["CONNECTIONS"]) : [];
foreach ($connections as $connection) {
if ($connection !== "") {
$conn = [];
$key = (strtoupper(trim($connection)));
$conn["TYPE"] = isset($_ENV[$this->getKey("TYPE", $key)]) ? $_ENV[$this->getKey("TYPE", $key)] : null;
$conn["USER"] = isset($_ENV[$this->getKey("USER", $key)]) ? $_ENV[$this->getKey("USER", $key)] : null;
$conn["HOST"] = isset($_ENV[$this->getKey("HOST", $key)]) ? $_ENV[$this->getKey("HOST", $key)] : null;
$conn["PASSWORD"] = isset($_ENV[$this->getKey("PASSWORD", $key)]) ? $_ENV[$this->getKey("PASSWORD", $key)] : null;
$conn["DATABASE"] = isset($_ENV[$this->getKey("DATABASE", $key)]) ? $_ENV[$this->getKey("DATABASE", $key)] : null;
$conn["PORT"] = isset($_ENV[$this->getKey("PORT", $key)]) ? $_ENV[$this->getKey("PORT", $key)] : null;
if ($conn["TYPE"] == "sqlite") {
if (!is_file($conn["DATABASE"])) {
$conn["DATABASE"] = ROOT . DS . "databases" . DS . $conn["DATABASE"];
}
}
$ret[$connection] = $conn;
}
}
return $ret;
}
private function getKey(string $type, string $name): string
{
return "DB_" . $name . "_" . $type;
}
/**
* Enable/Disable error reporting to output buffer
*/
private function setReporting()
{
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
public function handle()
{
try {
$this->router->run();
} catch (\Exception $ex) {
e($ex->getMessage());
die();
}
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace Kletellier\MiniWeb\Core\Kernel;
use eftec\bladeone\BladeOne;
class Templating
{
private $_views;
private $_cache;
private static $_instance = null;
private ?BladeOne $_blade = null;
private function __construct()
{
$this->_views = ROOT . DS . "views";
$this->_cache = ROOT . DS . "cache";
$mode = ($this->isDebug()) ? BladeOne::MODE_AUTO : BladeOne::MODE_FAST;
$this->_blade = new BladeOne($this->_views, $this->_cache, $mode);
}
public static function getInstance()
{
if (self::$_instance == null) {
self::$_instance = new Templating();
}
return self::$_instance;
}
private function isDebug(): bool
{
$ret = true;
if (isset($_ENV["DEBUG"])) {
$ret = ($_ENV["DEBUG"] == "true");
}
return $ret;
}
public function render(string $template, array $params = []): string
{
return $this->_blade->run($template, $params);
}
}

View File

@@ -1,35 +0,0 @@
<?php
namespace Kletellier\MiniWeb\Core\Routing;
use Bramus\Router\Router as RouterRouter;
class Router
{
private $_router;
public function __construct()
{
$this->init();
}
public function run()
{
$this->_router->run();
}
private function init()
{
$this->_router = new RouterRouter();
$this->loadFromFile(ROOT . DS . "routes");
$this->_router->set404("404 - Not found");
}
private function loadFromFile($path)
{
if (is_dir($path)) {
$router = $this->_router;
require $path . DS . "routes.php";
}
}
}

View File

@@ -1,15 +0,0 @@
<?php
if (! function_exists('e')) {
/**
* Encode HTML special characters in a string.
*
* @param string|null $value
* @param bool $doubleEncode
* @return string
*/
function e($value, $doubleEncode = true)
{
return htmlspecialchars($value ?? '', ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8', $doubleEncode);
}
}