Skip to content

Commit

Permalink
Replaced Whoops and Collision packages by slashtrace that provides ht…
Browse files Browse the repository at this point in the history
…tp and cli debug
  • Loading branch information
Jupiter committed Jan 28, 2019
1 parent 5a7dbfd commit 31f1f5f
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 61 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand Down
9 changes: 1 addition & 8 deletions app/Console/Jobby.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: Jerfeson Guerreiro
* Date: 26/11/18
* Time: 20:56
*/

namespace App\Console;

Expand All @@ -28,10 +22,9 @@ public function init()
*/
private function test()
{

$this->jobby->add('CommandExample', [
'closure' => function () {
$fp = fopen('data.txt', 'w');
$fp = fopen('storage\\data.txt', 'a');
fwrite($fp, 'Working');
fclose($fp);
return true;
Expand Down
6 changes: 3 additions & 3 deletions app/Handlers/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}

Expand Down
8 changes: 5 additions & 3 deletions app/Handlers/NotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
Expand Down
11 changes: 3 additions & 8 deletions app/Handlers/PhpError.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -17,22 +16,18 @@ 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;
}

if (!$this->displayErrorDetails) {
return app()->error($error->getMessage(), 500);
}

if (class_exists(Run::class)) {
throw $error;
}

return parent::__invoke($request, $response, $error);
}

Expand Down
23 changes: 23 additions & 0 deletions app/ServiceProviders/SlashTrace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\ServiceProviders;
use SlashTrace\SlashTrace as ST;
use SlashTrace\EventHandler\DebugHandler;
use SlashTrace\DebugRenderer\DebugCliRenderer;

class SlashTrace implements ProviderInterface
{

public static function register()
{
$d = new DebugHandler();
if (php_sapi_name() === "cli") $d->setRenderer(new DebugCliRenderer());

$st = new ST();
$st->addHandler($d);
$st->register();

app()->getContainer()['slashtrace'] = $st;
}

}
19 changes: 0 additions & 19 deletions app/ServiceProviders/Whoops.php

This file was deleted.

11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

1 comment on commit 31f1f5f

@jerfeson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing !

Please sign in to comment.