From 588294043536c84593582b13baf811803b5cad6c Mon Sep 17 00:00:00 2001 From: "nisch.codes" Date: Wed, 23 Jul 2025 22:08:42 +0200 Subject: [PATCH] Initial Code commit --- app/Controller/HomeController.php | 7 + app/Model/Date.php | 38 ----- app/Model/HomeModel.php | 38 ----- app/Model/WorkingHoursEntryModel.php | 51 +++++++ .../HomeView.php => Task/BackupTask.php} | 15 +- composer.json | 6 +- .../cache/.gitkeep | 0 data/database/.gitkeep | 0 data/logging/.gitkeep | 0 docker-compose.yml | 55 +++++++ docker/apache/vhost.conf | 21 +++ docker/php/Dockerfile | 24 +++ public/cron.php | 20 +++ public/index.php | 6 +- src/Application.php | 144 ++++++++++++------ src/MVC/BaseController.php | 10 +- src/MVC/BaseModel.php | 25 +-- src/MVC/BaseView.php | 11 +- src/Routing/MiddlewareHandler.php | 0 src/{ => Routing}/Request.php | 2 +- src/{ => Routing}/Router.php | 6 +- src/Task/BaseTask.php | 24 +++ src/TaskRunner.php | 30 ++++ src/{ => Utilities}/DotEnv.php | 4 +- src/{ => Utilities}/HTTP.php | 2 +- 25 files changed, 375 insertions(+), 164 deletions(-) delete mode 100644 app/Model/Date.php delete mode 100644 app/Model/HomeModel.php create mode 100644 app/Model/WorkingHoursEntryModel.php rename app/{View/HomeView.php => Task/BackupTask.php} (60%) rename src/MiddlewareHandler.php => data/cache/.gitkeep (100%) create mode 100644 data/database/.gitkeep create mode 100644 data/logging/.gitkeep create mode 100644 docker-compose.yml create mode 100644 docker/apache/vhost.conf create mode 100644 docker/php/Dockerfile create mode 100644 public/cron.php create mode 100644 src/Routing/MiddlewareHandler.php rename src/{ => Routing}/Request.php (95%) rename src/{ => Routing}/Router.php (86%) create mode 100644 src/Task/BaseTask.php create mode 100644 src/TaskRunner.php rename src/{ => Utilities}/DotEnv.php (94%) rename src/{ => Utilities}/HTTP.php (96%) diff --git a/app/Controller/HomeController.php b/app/Controller/HomeController.php index 2d77ac6..1699519 100644 --- a/app/Controller/HomeController.php +++ b/app/Controller/HomeController.php @@ -22,10 +22,17 @@ namespace Nischcodes\Shiftcalc\App\Controller; use Nischcodes\Shiftcalc\Attributes\Route; use Nischcodes\Shiftcalc\MVC\BaseController; +use Nischcodes\Shiftcalc\App\Model\WorkingHoursEntryModel; + class HomeController extends BaseController { #[Route('GET', '/')] public function index() { + WorkingHoursEntryModel::load(); + + $entries = WorkingHoursEntryModel::all(); + var_dump($entries); + echo "Homepage"; } diff --git a/app/Model/Date.php b/app/Model/Date.php deleted file mode 100644 index 2c8a127..0000000 --- a/app/Model/Date.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @copyright 2021 nisch.codes - * @license https://projects.nisch.codes/nischcodes/shiftcalc/src/branch/main/LICENSE GPL-3 - * @version 1.0.0 - * @link https://projects.nisch.codes/nischcodes/shiftcalc - */ - -use Nischcodes\Shiftcalc\MVC\BaseModel; - -class HomeModel extends BaseModel { - - // implement the init function - public function init() { - echo "HomeModel init"; - } - - // implement the load function - public function load() { - $this->repository = [ - ['date' => '01/01/2025', 'start' => '', 'end' => '', 'sdec' => 0, 'edec' => 0, 'worktime' => 8, 'break' => 0, 'worktime_total' => 8, 'info' => 'Holiday', 'desc' => 'First Example Holiday'], - ['date' => '03/05/2025', 'start' => '', 'end' => '', 'sdec' => 0, 'edec' => 0, 'worktime' => 8, 'break' => 0, 'worktime_total' => 8, 'info' => 'Holiday', 'desc' => 'Second Example Holiday'] - ]; - } -} \ No newline at end of file diff --git a/app/Model/HomeModel.php b/app/Model/HomeModel.php deleted file mode 100644 index e138098..0000000 --- a/app/Model/HomeModel.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @copyright 2021 nisch.codes - * @license https://projects.nisch.codes/nischcodes/shiftcalc/src/branch/main/LICENSE GPL-3 - * @version 1.0.0 - * @link https://projects.nisch.codes/nischcodes/shiftcalc - */ - -use Nischcodes\Shiftcalc\MVC\BaseModel; - -class HomeModel extends BaseModel { - - // implement the init function - public function init() { - echo "HomeModel init"; - } - - // implement the load function - public function load() { - $this->repository = [ - ['date' => '01/01/2025', 'start' => '', 'end' => '', 'sdec' => 0, 'edec' => 0, 'worktime' => 8, 'break' => 0, 'worktime_total' => 8, 'info' => 'Holiday', 'desc' => 'First Example Holiday'], - ['date' => '03/05/2025', 'start' => '', 'end' => '', 'sdec' => 0, 'edec' => 0, 'worktime' => 8, 'break' => 0, 'worktime_total' => 8, 'info' => 'Holiday', 'desc' => 'Second Example Holiday'] - ]; - } -} \ No newline at end of file diff --git a/app/Model/WorkingHoursEntryModel.php b/app/Model/WorkingHoursEntryModel.php new file mode 100644 index 0000000..4ece0af --- /dev/null +++ b/app/Model/WorkingHoursEntryModel.php @@ -0,0 +1,51 @@ + + * @copyright 2021 nisch.codes + * @license https://projects.nisch.codes/nischcodes/shiftcalc/src/branch/main/LICENSE GPL-3 + * @version 1.0.0 + * @link https://projects.nisch.codes/nischcodes/shiftcalc + */ + +use Nischcodes\Shiftcalc\MVC\BaseModel; + +class WorkingHoursEntryModel extends BaseModel { + + public function __construct( + protected string $date, + protected string $start, + protected string $end, + protected string $type, + protected string $info, + protected float $start_decimal, + protected float $end_decimal, + protected float $worktime_decimal, + protected float $break_decimal, + protected float $worktime_total_decimal + ){ + parent::__construct(); + } + + // implement the load function + public static function load() { + static::$repository = [ + new self('2025-01-01','','','Holiday', 'First Example Holiday', 0, 0, 0, 0, 0), + new self('2025-05-03','','','Holiday', 'Second Example Holiday', 0, 0, 0, 0, 0), + new self('2025-01-02','','','Vacation', '', 0, 0, 0, 0, 8.00), + new self('2025-07-01','08:41','17:48','Office', '', 8.68, 17.8, 9.12, 0.75, 7.72), + new self('2025-07-15','08:23','16:36','Homeoffice', '', 8.38, 16.6, 8.22, 0.5, 0) + ]; + } +} \ No newline at end of file diff --git a/app/View/HomeView.php b/app/Task/BackupTask.php similarity index 60% rename from app/View/HomeView.php rename to app/Task/BackupTask.php index 96842d6..c9fb038 100644 --- a/app/View/HomeView.php +++ b/app/Task/BackupTask.php @@ -1,11 +1,11 @@ + sh -c " + if [ ! -d vendor ]; then + composer install --no-dev --optimize-autoloader; + php scripts/setup.php; + fi; + php-fpm + " + networks: + - appnet + + web: + image: docker.io/library/httpd:2.4 + container_name: app-web + depends_on: [php] + ports: + - "8080:80" + volumes: + - ./public:/usr/local/apache2/htdocs:Z + - ./docker/apache/vhost.conf:/usr/local/apache2/conf/extra/vhost.conf:ro,Z + command: > + sh -c " + # ───────── Module laden ───────── + echo 'LoadModule rewrite_module modules/mod_rewrite.so' \ + >> /usr/local/apache2/conf/httpd.conf; + echo 'LoadModule proxy_module modules/mod_proxy.so' \ + >> /usr/local/apache2/conf/httpd.conf; + echo 'LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so' \ + >> /usr/local/apache2/conf/httpd.conf; + # ───────── VHost aktivieren ───────── + echo 'Include conf/extra/vhost.conf' \ + >> /usr/local/apache2/conf/httpd.conf; + httpd-foreground + " + networks: + - appnet + +networks: + appnet: + driver: bridge \ No newline at end of file diff --git a/docker/apache/vhost.conf b/docker/apache/vhost.conf new file mode 100644 index 0000000..750a81c --- /dev/null +++ b/docker/apache/vhost.conf @@ -0,0 +1,21 @@ + + ServerName localhost + DocumentRoot /usr/local/apache2/htdocs + + + Options Indexes FollowSymLinks + AllowOverride All + Require all granted + + + DirectoryIndex index.php index.html + + # + # SetHandler "proxy:fcgi://php:9000/var/www/html/public" + # + + ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://php:9000/var/www/html/public/$1" + + ErrorLog /usr/local/apache2/logs/error.log + CustomLog /usr/local/apache2/logs/access.log combined + \ No newline at end of file diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile new file mode 100644 index 0000000..2584206 --- /dev/null +++ b/docker/php/Dockerfile @@ -0,0 +1,24 @@ +FROM php:8.4-fpm + +# Build-Arg default: kein Xdebug +ARG INSTALL_XDEBUG=false + +# System-Tools für pecl +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + git unzip \ + && rm -rf /var/lib/apt/lists/* + +# Conditionally install Xdebug +RUN if [ "$INSTALL_XDEBUG" = "true" ]; then \ + pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && { \ + echo "zend_extension=xdebug.so"; \ + echo "xdebug.mode=develop,trace"; \ + echo "xdebug.start_with_request=yes"; \ + echo "xdebug.client_host=host.docker.internal"; \ + echo "xdebug.client_port=9003"; \ + echo "xdebug.log=/tmp/xdebug.log"; \ + } > /usr/local/etc/php/conf.d/xdebug.ini ; \ + fi \ No newline at end of file diff --git a/public/cron.php b/public/cron.php new file mode 100644 index 0000000..7b67dd6 --- /dev/null +++ b/public/cron.php @@ -0,0 +1,20 @@ +registerRoutesFromController( - $controllerClass, - $modelClass, - $viewClass - ); - } + // init the website part by loading the controllers + static::initWeb(); + } - } - - static function run() { - - // call the route for the requested path - self::$router->dispatch( - Request::uri(), - Request::method(), - Request::parameters() - ); } + public static function run() { - static function getProjectRoot(?string $startDir = null): string { + // check if the application is running on the cli or not + if (static::$isContextCli) { + + // run the console part + static::runConsole(); + + } else { + + // run the website part + static::runWeb(); + + } + + } + + public static function getProjectRoot(?string $startDir = null): string { $dir = realpath($startDir ?? __DIR__); while ($dir) { @@ -108,4 +101,55 @@ class Application { throw new \RuntimeException('Project root folder not found.'); } + + private static function initConsole() { + + } + + private static function initWeb() { + + // initilise the router object + self::$router = new Router(); + + // get all controller from the application directory + $appControllers = glob(static::$projectRoot."/app/Controller/*.php"); + + // iterate over all application controller and register the routes with model + foreach($appControllers as $appController) { + + // extract the class name + $controllerClassName = basename($appController, '.php'); + // construct the namespaces + $controllerFQN = self::$controllernamespace.$controllerClassName; + + // check if classes exists + $controllerClass = (class_exists($controllerFQN) ? $controllerFQN : false); + + // check if the current classname is loaded + if($controllerClass) { + + // register controller for routing + self::$router->registerRoutesFromController( + $controllerClass + ); + } + } + + } + + private static function runConsole() { + + } + + private static function runWeb() { + + // call the route for the requested path + self::$router->dispatch( + Request::uri(), + Request::method(), + Request::parameters() + ); + + } + } \ No newline at end of file diff --git a/src/MVC/BaseController.php b/src/MVC/BaseController.php index 03f7102..3175dd4 100644 --- a/src/MVC/BaseController.php +++ b/src/MVC/BaseController.php @@ -18,13 +18,9 @@ namespace Nischcodes\Shiftcalc\MVC; */ abstract class BaseController { - - public function __construct( - protected BaseModel $model, - protected BaseView $view - ) { - // initilise the model - $model->init(); + protected function view(string $template, array $data = []): BaseView { + return new BaseView($template, $data); } + } \ No newline at end of file diff --git a/src/MVC/BaseModel.php b/src/MVC/BaseModel.php index 7d854e4..a402a7d 100644 --- a/src/MVC/BaseModel.php +++ b/src/MVC/BaseModel.php @@ -19,18 +19,23 @@ namespace Nischcodes\Shiftcalc\MVC; abstract class BaseModel { - protected $repository = []; - - abstract public function init(); - abstract public function load(); + protected static $repository = []; + abstract public static function load(); - // implement the getAll function - public function getAll() { - return $this->repository; + // implement the all function + public static function all() { + return static::$repository; } - // implement the get function - public function get($index){ - return $this->repository[$index]; + // implement the find function + public static function find($index){ + return static::$repository[$index]; } + + /* + public static function find(int|string $id): ?self + { + return static::query()->where('id', $id)->first(); + } + */ } \ No newline at end of file diff --git a/src/MVC/BaseView.php b/src/MVC/BaseView.php index f06a3f9..d181b9b 100644 --- a/src/MVC/BaseView.php +++ b/src/MVC/BaseView.php @@ -19,6 +19,15 @@ namespace Nischcodes\Shiftcalc\MVC; abstract class BaseView { - abstract public function render($data); + public function __construct( + private string $template, + private array $data = [] + ) {} + + public function render(): void { + // create array entries with data property as key + extract($this->data, EXTR_SKIP); + //TODO: load template from dist and compile template to code + } } \ No newline at end of file diff --git a/src/Routing/MiddlewareHandler.php b/src/Routing/MiddlewareHandler.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Request.php b/src/Routing/Request.php similarity index 95% rename from src/Request.php rename to src/Routing/Request.php index 3479b7f..793f915 100644 --- a/src/Request.php +++ b/src/Routing/Request.php @@ -1,6 +1,6 @@ + * @copyright 2021 nisch.codes + * @license https://projects.nisch.codes/nischcodes/shiftcalc/src/branch/main/LICENSE GPL-3 + * @version 1.0.0 + * @link https://projects.nisch.codes/nischcodes/shiftcalc + */ + +abstract class BaseTask { + + abstract public static function run(); + +} \ No newline at end of file diff --git a/src/TaskRunner.php b/src/TaskRunner.php new file mode 100644 index 0000000..911154d --- /dev/null +++ b/src/TaskRunner.php @@ -0,0 +1,30 @@ + + * @copyright 2021 nisch.codes + * @license https://projects.nisch.codes/nischcodes/shiftcalc/src/branch/main/LICENSE GPL-3 + * @version 1.0.0 + * @link https://projects.nisch.codes/nischcodes/shiftcalc + */ + +use Nischcodes\Shiftcalc\Utilities\DotEnv; + +class TaskRunner { + + static function init() {} + + static function run() {} + +} \ No newline at end of file diff --git a/src/DotEnv.php b/src/Utilities/DotEnv.php similarity index 94% rename from src/DotEnv.php rename to src/Utilities/DotEnv.php index 73b6654..44a0cd0 100644 --- a/src/DotEnv.php +++ b/src/Utilities/DotEnv.php @@ -1,6 +1,6 @@