diff --git a/.dockerignore b/.dockerignore index 857aa6a..a34e019 100755 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,4 @@ .gitignore LICENSE README.md -CHANGELOG.md \ No newline at end of file +CHANGELOG.md diff --git a/.gitignore b/.gitignore index b5dbeb2..029ea9d 100755 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ vendor .idea .DS_Store *.cache -composer.lock \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3b971be..83bd882 100755 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,11 @@ RUN composer install \ --optimize-autoloader \ --prefer-dist -FROM php:8.1.1-fpm AS base +FROM php:8.2-fpm AS base COPY --from=vendor /usr/bin/composer /usr/bin/composer RUN apt-get update \ - && apt-get install -y --fix-missing curl git vim wget netcat chrpath git unzip zip \ + && apt-get install -y --fix-missing curl git vim wget chrpath git unzip zip \ && usermod -u 1000 www-data \ && usermod -G staff www-data \ && chown -R www-data:www-data /var/www \ diff --git a/LICENSE.md b/LICENSE.md index 1c5e292..dca1a4c 100755 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # License -### Copyright (c) 2017-2022 Daniyal Hamid (https://designcise.com) +### Copyright (c) 2017-2023 Daniyal Hamid (https://designcise.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 473b857..5d7f858 100755 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ Simply clone the repo and start building your projects. ### Prerequisites: -- BitFrame v3.6 -- PHP 8.1+ -- Nginx +- BitFrame v4.0 +- PHP 8.2+ +- Nginx (or Apache) - Docker Engine 1.13.0+ ## Directory Structure diff --git a/www/composer.json b/www/composer.json index baac0ea..519d1f2 100755 --- a/www/composer.json +++ b/www/composer.json @@ -1,10 +1,10 @@ { "require": { - "php": ">=8.1", - "designcise/bitframe": "^3.6", - "designcise/bitframe-fastroute": "^3.6", - "designcise/bitframe-whoops": "^3.6", - "nyholm/psr7": "^1.4" + "php": ">=8.2", + "designcise/bitframe": "^4.0", + "designcise/bitframe-fastroute": "^4.0", + "designcise/bitframe-whoops": "^4.0", + "nyholm/psr7": "^1.8.0" }, "require-dev": { "roave/security-advisories": "dev-master", diff --git a/www/server/app/Controller/DefaultController.php b/www/server/app/Controller/DefaultController.php index 06f39f7..114b2e8 100755 --- a/www/server/app/Controller/DefaultController.php +++ b/www/server/app/Controller/DefaultController.php @@ -7,16 +7,22 @@ use Psr\Http\Message\{ServerRequestInterface, ResponseInterface}; use Psr\Http\Server\RequestHandlerInterface; use BitFrame\Container; +use BitFrame\FastRoute\Route; +use BitFrame\Http\Message\JsonResponse; class DefaultController { - public function testAction( + public function __construct( + private readonly Container $container, + ) {} + + #[Route(['GET'], '/hello/{action}')] + public function indexAction( ServerRequestInterface $request, RequestHandlerInterface $handler, - Container $container ): ResponseInterface { $response = $handler->handle($request); - $globals = $container['globals']; + $globals = $this->container['globals']; $response->getBody()->write( "{$globals['title']} - 👋 Build Something Amazing Today!" @@ -24,4 +30,17 @@ public function testAction( return $response; } + + #[Route(['GET'], '/json')] + public function jsonAction(): ResponseInterface + { + $globals = $this->container['globals']; + + return JsonResponse::create([ + 'data' => [ + 'title' => $globals['title'], + 'mainHeading' => 'Build Something Amazing Today!', + ], + ]); + } } diff --git a/www/server/config/routes.php b/www/server/config/routes.php index 111fa51..5c1e1df 100755 --- a/www/server/config/routes.php +++ b/www/server/config/routes.php @@ -7,5 +7,7 @@ use YourProject\App\Controller\DefaultController; return static function (AbstractRouter $router, Container $container) { - $router->get('/hello/{action}', [DefaultController::class, 'testAction', $container]); + $router->registerControllers([ + new DefaultController($container), + ]); };