diff --git a/README.md b/README.md index a0ff9e0..36f8647 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Slim Framework 3 Skeleton Application (http + cli) -Use this skeleton application to quickly setup and start working on a new Slim Framework 3 application (Tested with slim 3.10). +Use this skeleton application to quickly setup and start working on a new Slim Framework 3 application (Tested with slim 3.12). This application handles http and command line requests. This application ships with a few service providers and a Session middleware out of the box. Supports container resolution and auto-wiring. @@ -9,14 +9,14 @@ To remove a service provider comment it on config/app.php file and remove it fro Available service providers: -* Whoops -* Monolog -* Eloquent -* Plates -* Twig -* Flysystem -* PHPMailer -* Cache (redis for now) +* [SlashTrace](https://github.com/slashtrace/slashtrace) +* [Monolog](https://github.com/Seldaek/monolog) +* [Eloquent](https://github.com/illuminate/database) +* [Plates](https://github.com/thephpleague/plates) +* [Twig](https://github.com/twigphp/Twig) +* [Flysystem](https://github.com/thephpleague/flysystem) +* [PHPMailer](https://github.com/PHPMailer/PHPMailer) +* [Redis Cache](https://github.com/naroga/redis-cache) * [Jobby](https://github.com/jobbyphp/jobby) Available middleware: @@ -247,7 +247,10 @@ $ cp vendor/hellogerard/jobby/resources/jobby.php . ## Changelog -V3.0.0 +v2.6 + - Replaced Whoops and Collision packages by slashtrace that provides http and cli debug + +V2.5 - Allow for providers and middleware to be registered only for a given scope (dependent on app name) - general code improvements and error handling when developing rest api diff --git a/app/Console/Jobby.php b/app/Console/Jobby.php index ff3640a..f743fee 100644 --- a/app/Console/Jobby.php +++ b/app/Console/Jobby.php @@ -1,10 +1,4 @@ jobby->add('CommandExample', [ 'closure' => function () { - $fp = fopen('data.txt', 'w'); + $fp = fopen('storage\\data.txt', 'a'); fwrite($fp, 'Working'); fclose($fp); return true; diff --git a/app/Handlers/Error.php b/app/Handlers/Error.php index 4aad7a3..4ba5819 100644 --- a/app/Handlers/Error.php +++ b/app/Handlers/Error.php @@ -5,7 +5,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; use Psr\Log\LoggerInterface; -use NunoMaduro\Collision\Provider as Collision; +use App\ServiceProviders\SlashTrace; final class Error extends \Slim\Handlers\Error { @@ -16,11 +16,11 @@ public function __invoke(Request $request, Response $response, \Exception $excep $container = $app->getContainer(); // Log the message - if ($container->has(LoggerInterface::class)) { + if ($container->has(LoggerInterface::class) && !$this->displayErrorDetails) { $app->resolve(LoggerInterface::class)->error($exception); } - if ($app->isConsole() && class_exists(Collision::class)) { + if (class_exists(SlashTrace::class) && ($app->isConsole() || $this->displayErrorDetails)) { throw $exception; } diff --git a/app/Handlers/NotFound.php b/app/Handlers/NotFound.php index 2f2bd7d..d3ed9f4 100644 --- a/app/Handlers/NotFound.php +++ b/app/Handlers/NotFound.php @@ -5,7 +5,6 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; use Psr\Log\LoggerInterface; -use League\Plates\Engine; final class NotFound extends \Slim\Handlers\NotFound { @@ -28,8 +27,11 @@ public function __invoke(Request $request, Response $response) return app()->error("URI '".$request->getUri()->getPath()."' not found", 404); } - $resp = $app->resolve(Engine::class)->render('error::404'); - $response->withStatus(404)->write($resp); + $resp = $app->resolve('view')->render('http::error', [ + 'code' => 404, + 'message' => "uri {$request->getUri()->getPath()} not found", + ]); + $response = $response->withStatus(404)->write($resp); return $response; } diff --git a/app/Handlers/PhpError.php b/app/Handlers/PhpError.php index 0d76c9a..697f6b7 100644 --- a/app/Handlers/PhpError.php +++ b/app/Handlers/PhpError.php @@ -5,8 +5,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ResponseInterface as Response; use Psr\Log\LoggerInterface; -use Whoops\Run; -use NunoMaduro\Collision\Provider as Collision; +use App\ServiceProviders\SlashTrace; final class PhpError extends \Slim\Handlers\PhpError { @@ -17,11 +16,11 @@ public function __invoke(Request $request, Response $response, \Throwable $error $container = $app->getContainer(); // Log the message - if ($container->has(LoggerInterface::class)) { + if ($container->has(LoggerInterface::class) && !$this->displayErrorDetails) { $app->resolve(LoggerInterface::class)->error($error); } - if ($app->isConsole() && class_exists(Collision::class)) { + if (class_exists(SlashTrace::class) && ($app->isConsole() || $this->displayErrorDetails)) { throw $error; } @@ -29,10 +28,6 @@ public function __invoke(Request $request, Response $response, \Throwable $error return app()->error($error->getMessage(), 500); } - if (class_exists(Run::class)) { - throw $error; - } - return parent::__invoke($request, $response, $error); } diff --git a/app/ServiceProviders/SlashTrace.php b/app/ServiceProviders/SlashTrace.php new file mode 100644 index 0000000..a75cda0 --- /dev/null +++ b/app/ServiceProviders/SlashTrace.php @@ -0,0 +1,23 @@ +setRenderer(new DebugCliRenderer()); + + $st = new ST(); + $st->addHandler($d); + $st->register(); + + app()->getContainer()['slashtrace'] = $st; + } + +} \ No newline at end of file diff --git a/app/ServiceProviders/Whoops.php b/app/ServiceProviders/Whoops.php deleted file mode 100644 index 27a3554..0000000 --- a/app/ServiceProviders/Whoops.php +++ /dev/null @@ -1,19 +0,0 @@ -allowQuit(false); - $handler = new PrettyPageHandler; - $whoops->pushHandler($handler); - $whoops->register(); - } - -} \ No newline at end of file diff --git a/composer.json b/composer.json index b0ca8ab..dbea508 100644 --- a/composer.json +++ b/composer.json @@ -7,18 +7,17 @@ "license": "MIT", "require": { "php": ">= 7.0", - "slim/slim": "3.10.*", - "monolog/monolog": "1.23.*", - "nunomaduro/collision": "2.0.*", + "slim/slim": "3.12.*", + "monolog/monolog": "1.24.*", + "slashtrace/slashtrace": "1.1.*", "league/flysystem": "1.0.*", "league/plates": "3.3.*", - "illuminate/database": "5.6.*", + "illuminate/database": "5.7.*", "phpmailer/phpmailer": "6.0.*", "naroga/redis-cache": "1.1.*", - "hellogerard/jobby": "^3.4" + "hellogerard/jobby": "3.4.*" }, "require-dev": { - "filp/whoops": "2.2.*" }, "autoload": { "psr-4": { diff --git a/config/app.php b/config/app.php index 23d5ae8..86dece9 100644 --- a/config/app.php +++ b/config/app.php @@ -69,11 +69,10 @@ ], // add your service providers here 'providers' => [ - App\ServiceProviders\Monolog::class => 'http,console', - App\ServiceProviders\Whoops::class => 'http', - App\ServiceProviders\Collision::class => 'console', + App\ServiceProviders\Monolog::class => 'http,console', + App\ServiceProviders\SlashTrace::class => 'http,console', App\ServiceProviders\Plates::class => 'http', - App\ServiceProviders\Twig::class => 'http', + //App\ServiceProviders\Twig::class => 'http', App\ServiceProviders\Eloquent::class => 'http,console', App\ServiceProviders\FileSystem::class => 'http,console', App\ServiceProviders\Mailer::class => 'http,console',