refactoring new project structure

This commit is contained in:
xinatorus 2020-04-21 17:59:37 +02:00
parent c520cf847c
commit 85b10e1098
14 changed files with 57 additions and 91 deletions

View File

@ -3,29 +3,16 @@
root = true root = true
[*] [*]
tab_width = 3 indent_style = tab
indent_size = 3
[*.{php,phpt,inc,phtml}] end_of_line = lf
charset = utf-8 charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = tab
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[*.md] [*.md]
charset = utf-8
end_of_line = lf
indent_style = tab
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80 max_line_length = 80
[COMMIT_EDITMSG] [COMMIT_EDITMSG]
charset = utf-8
end_of_line = lf
indent_size = 4 indent_size = 4
indent_style = tab max_line_length = 80
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 80

View File

@ -1,40 +1,38 @@
<?php <?php
// import autoload
//Autoloader //Autoloader
class Autoloader {
protected static $extension = ".php";
protected static $root = __DIR__;
protected static $files = [];
Class Autoloader { static function ClassLoader ($className = ""){
protected static $extension = ".php"; $directorys = new RecursiveDirectoryIterator(static::$root, RecursiveDirectoryIterator::SKIP_DOTS);
protected static $root = __DIR__;
protected static $files = [];
static function ClassLoader ($className = ""){ //echo '<pre>';
$directorys = new RecursiveDirectoryIterator(static::$root, RecursiveDirectoryIterator::SKIP_DOTS); //var_dump($directorys);
//echo '</pre>';
//echo '<pre>'; $files = new RecursiveIteratorIterator($directorys, RecursiveIteratorIterator::LEAVES_ONLY);
//var_dump($directorys);
//echo '</pre>';
$files = new RecursiveIteratorIterator($directorys, RecursiveIteratorIterator::LEAVES_ONLY);
$filename = $className . static::$extension; $filename = $className . static::$extension;
foreach ($files as $key => $file) { foreach ($files as $key => $file) {
if (strtolower($file->getFilename()) === strtolower($filename) && $file->isReadable()) { if (strtolower($file->getFilename()) === strtolower($filename) && $file->isReadable()) {
include_once $file->getPathname(); include_once $file->getPathname();
return; return;
} }
} }
} }
static function setRoot($rootPath){ static function setRoot($rootPath){
static::$root = $rootPath; static::$root = $rootPath;
} }
} }
spl_autoload_register("Autoloader::ClassLoader"); spl_autoload_register("Autoloader::ClassLoader");
Autoloader::setRoot('/var/www/dev.steelants.cz/vasek/home-update/'); Autoloader::setRoot('/var/www/dev.steelants.cz/vasek/home-update/');
//Debug //Debug
error_reporting(E_ALL); error_reporting(E_ALL);
ini_set( 'display_errors','1'); ini_set( 'display_errors','1');
@ -47,22 +45,22 @@ ini_set('session.cookie_secure', '1');
session_start (); session_start ();
mb_internal_encoding ("UTF-8"); mb_internal_encoding ("UTF-8");
//Logs // import configs
require_once '../config/config.php';
// Logs
$logManager = new LogManager(); $logManager = new LogManager();
//Language // Language
$langTag = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); $langTag = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$langMng = new LanguageManager($langTag); $langMng = new LanguageManager($langTag);
$langMng->load(); $langMng->load();
//DB Conector //D B Conector
//Db::connect (DBHOST, DBUSER, DBPASS, DBNAME); Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
// TODO: Přesunout do Login Pohledu
//TODO: Přesunout do Login Pohledu
$userManager = new UserManager(); $userManager = new UserManager();
// import routes // import routes
require_once '../app/Routes.php'; require_once '../app/Routes.php';

View File

@ -3,7 +3,7 @@
$router = new Router(); $router = new Router();
$router->setDefault(function(){ $router->setDefault(function(){
echo '404'; echo $_GET['URL'].': 404';
}); });
//Pages //Pages

View File

@ -17,18 +17,19 @@ class LanguageManager
function load() function load()
{ {
$file = './app/lang/en.php'; $file = '../lang/en.php';
if (!file_exists($file)){ if (!file_exists($file)){
echo 'ERROR: en.php not found';
die(); die();
//TODO add lng EXEPTIONS //TODO add lng EXEPTIONS
} }
$arrayFirst = include($file); $arrayFirst = include($file);
$file = './app/lang/' . $this->lngCode . '.php'; $file = '../lang/' . $this->lngCode . '.php';
$arraySecond = []; $arraySecond = [];
if (file_exists($file)){ if (file_exists($file)){
$arraySecond = include($file); $arraySecond = include($file);
} }
$this->lngDatabase = array_merge($arrayFirst,$arraySecond); $this->lngDatabase = array_merge($arrayFirst, $arraySecond);
return true; return true;
} }

View File

@ -48,7 +48,7 @@ class LogManager
$record = "[".date("H:m:s")."][".$type."]" . $value . "\n"; $record = "[".date("H:m:s")."][".$type."]" . $value . "\n";
if (strlen($record) > 65 ) { if (strlen($record) > 65 ) {
$record = Utilities::stringInsert($record,"\n",65); $record = Utilities::stringInsert($record,"\n",65);
} }
fwrite($this->logFile, $record); fwrite($this->logFile, $record);
} }

View File

@ -1,13 +1,13 @@
<?php <?php
class Partial{ class Partial{
var $assignedValues = []; private $assignedValues = [];
var $partBuffer; private $partBuffer;
var $path; private $path;
var $debug; private $debug;
function __construct($path = "", $debug = false) { function __construct($path = "", $debug = false) {
$this->debug = $debug; $this->debug = $debug;
if (!empty('app/templates/part/' . $path . '.phtml') && file_exists('app/templates/part/' . $path . '.phtml')) { if (!empty('../app/templates/part/' . $path . '.phtml') && file_exists('../app/templates/part/' . $path . '.phtml')) {
$this->path = $path; $this->path = $path;
} else { } else {
echo '<pre>'; echo '<pre>';
@ -29,6 +29,6 @@ class Partial{
extract($this->assignedValues); extract($this->assignedValues);
} }
require('app/templates/part/' . $this->path . '.phtml'); require('../app/templates/part/' . $this->path . '.phtml');
} }
} }

View File

@ -1,13 +1,13 @@
<?php <?php
class Template extends Partial{ class Template{
var $assignedValues = []; private $assignedValues = [];
var $partBuffer; private $partBuffer;
var $path; private $path;
var $debug; private $debug;
function __construct($path = "", $debug = false) { function __construct($path = "", $debug = false) {
$this->debug = $debug; $this->debug = $debug;
if (!empty('app/templates/' . $path . '.phtml') && file_exists('app/templates/' . $path . '.phtml')) { if (!empty('../app/templates/' . $path . '.phtml') && file_exists('../app/templates/' . $path . '.phtml')) {
$this->path = $path; $this->path = $path;
} else { } else {
echo '<pre>'; echo '<pre>';
@ -26,9 +26,9 @@ class Template extends Partial{
function render() { function render() {
extract($this->assignedValues); extract($this->assignedValues);
if (!empty('app/controls/' . $this->path . '.php') && file_exists('app/controls/' . $this->path . '.php')) { if (!empty('../app/controls/' . $this->path . '.php') && file_exists('../app/controls/' . $this->path . '.php')) {
include('app/controls/' . $this->path . '.php'); include('../app/controls/' . $this->path . '.php');
} }
require_once('app/templates/' . $this->path . '.phtml'); require_once('../app/templates/' . $this->path . '.phtml');
} }
} }

View File

@ -1,18 +0,0 @@
Options -Indexes
Options -MultiViews -Indexes
RewriteEngine On
RewriteBase /vasek/home-update/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.css
RewriteCond %{REQUEST_FILENAME} !.js
RewriteRule (.*) index.php?url=$1 [QSA,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !api.php
RewriteCond %{REQUEST_FILENAME} !apiFront.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
AddType application/x-httpd-php .php .phtml

View File

@ -1,5 +1,3 @@
<?php <?php
echo('GET [url]: ' . $_GET['url']);
require_once __DIR__ . '/../app/Bootstrap.php'; require_once __DIR__ . '/../app/Bootstrap.php';