Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

#17 upgrade to slim 4 #18

Open
wants to merge 28 commits into
base: slim-4
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c998c0f
update composer require definitions
gustavofabiane Feb 4, 2020
0e2c6c7
update ErrorHandler signature for Slim 4
gustavofabiane Feb 4, 2020
9212b43
update settings
gustavofabiane Feb 4, 2020
845edcb
update dependencies definitions
gustavofabiane Feb 4, 2020
eef6061
bootstrap application in separated file
gustavofabiane Feb 4, 2020
cdfbc3e
update app middleware
gustavofabiane Feb 4, 2020
784990c
update auth service
gustavofabiane Feb 4, 2020
a21d4c0
remove template
gustavofabiane Feb 4, 2020
a0d4214
update dependencies
gustavofabiane Feb 4, 2020
23c7fc7
update phinx settings
gustavofabiane Feb 4, 2020
1297aea
update definitions and middleware
gustavofabiane Feb 4, 2020
5167ac7
update route definitions
gustavofabiane Feb 4, 2020
a97735b
update base test case to use app as RequestHandlerInterface
gustavofabiane Feb 4, 2020
4089406
update authorization header
gustavofabiane Feb 4, 2020
c47f902
inject default dependencies used by all controllers in base controller
gustavofabiane Feb 5, 2020
aaea589
update dependencies, routes and settings
gustavofabiane Feb 6, 2020
b7bbac8
fix middleware order
gustavofabiane Feb 6, 2020
e80309f
update HomepageTest
gustavofabiane Feb 6, 2020
50aeb13
update services
gustavofabiane Feb 6, 2020
d4c23e0
update controllers
gustavofabiane Feb 6, 2020
b5a0b49
remove unnecessary response parameter from ArticleController:store ac…
gustavofabiane Feb 6, 2020
5561ab1
fix issue in article list
gustavofabiane Feb 6, 2020
5425042
add required platform extensions in composer.json
gustavofabiane Feb 6, 2020
5b96937
fix test case function name
gustavofabiane Feb 6, 2020
1803291
fix ternary in timestamps fields which were using an undefined variab…
gustavofabiane Feb 6, 2020
c3b7047
update directory structure
gustavofabiane Feb 13, 2020
5323cde
update readme with changes for new version
gustavofabiane Feb 18, 2020
e2316a7
Merge branch 'slim-4' into feature/upgrade-to-slim-4
gustavofabiane Jul 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update definitions and middleware
gustavofabiane committed Feb 4, 2020
commit 1297aea23967310f28d0f15adb57252cf5bb3ff7
6 changes: 3 additions & 3 deletions src/Conduit/Middleware/Cors.php
Original file line number Diff line number Diff line change
@@ -27,11 +27,11 @@ class Cors implements MiddlewareInterface
/**
* Cors Constructor
*
* @param array $settings
* @param array|string $settings
*/
public function __construct(array $settings)
public function __construct($allowedOrigins)
{
$this->allowedOrigins = $settings['cors'];
$this->allowedOrigins = $allowedOrigins;
}

/**
45 changes: 22 additions & 23 deletions src/Conduit/Middleware/OptionalAuth.php
Original file line number Diff line number Diff line change
@@ -2,46 +2,45 @@

namespace Conduit\Middleware;

use Interop\Container\ContainerInterface;
use Slim\DeferredCallable;

class OptionalAuth
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Tuupola\Middleware\JwtAuthentication;

class OptionalAuth implements MiddlewareInterface
{

/**
* @var \Interop\Container\ContainerInterface
* @var ContainerInterface
*/
private $container;
private $jwtMiddleware;

/**
* OptionalAuth constructor.
*
* @param \Interop\Container\ContainerInterface $container
* OptionalAuth constructor
*
* @internal param \Slim\Middleware\JwtAuthentication $jwt
* @param JwtAuthentication $jwtMiddleware
*/
public function __construct(ContainerInterface $container)
public function __construct(JwtAuthentication $jwtMiddleware)
{
$this->container = $container;
$this->jwtMiddleware = $jwtMiddleware;
}

/**
* OptionalAuth middleware invokable class to verify JWT token when present in Request
*
* @param \Psr\Http\Message\ServerRequestInterface $request PSR7 request
* @param \Psr\Http\Message\ResponseInterface $response PSR7 response
* @param callable $next Next middleware
*
* @return \Psr\Http\Message\ResponseInterface
* @param ServerRequestInterface $request
* @param RequestHandlerInterface $handler
* @return ResponseInterface
*/
public function __invoke($request, $response, $next)
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($request->hasHeader('HTTP_AUTHORIZATION')) {
$callable = new DeferredCallable($this->container->get('jwt'), $this->container);

return call_user_func($callable, $request, $response, $next);
if ($request->hasHeader('HTTP_AUTHORIZATION') || $request->hasHeader('Authorization')) {
return call_user_func([$this->jwtMiddleware, 'process'], $request, $handler);
}

return $next($request, $response);
return $handler->handle($request);
}
}
30 changes: 15 additions & 15 deletions src/dependencies.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

use Conduit\Middleware\Cors;
use Monolog\Logger;
use DI\ContainerBuilder;
use Conduit\Middleware\Cors;
use Conduit\Services\Auth\Auth;
use Respect\Validation\Validator;
use Monolog\Handler\StreamHandler;
use Monolog\Processor\UidProcessor;
use Conduit\Middleware\OptionalAuth;
use Tuupola\Middleware\JwtAuthentication;
use Slim\Factory\Psr17\NyholmPsr17Factory;
use Conduit\Middleware\RemoveTrailingSlash;
use Slim\Middleware\JwtAuthentication;
use League\Fractal\Manager as FractalManager;
use League\Fractal\Serializer\ArraySerializer;
use Illuminate\Database\Capsule\Manager as IlluminateDatabase;
use Slim\Factory\Psr17\NyholmPsr17Factory;

/**
* Application dependencies definitions
@@ -33,24 +33,14 @@
return $logger;
},

// JWT Middleware
'jwt' => function (array $settings) {
return new JwtAuthentication($settings['jwt']);
},

// Optional Auth Middleware
'optionalAuth' => function ($c) {
return new OptionalAuth($c);
},

// Request Validator
'validator' => function ($c) {
'validator' => function () {
Validator::with('\\Conduit\\Validation\\Rules');
return new Validator();
},

// Fractal
'fractal' => function ($c) {
'fractal' => function () {
$manager = new FractalManager();
$manager->setSerializer(new ArraySerializer());
return $manager;
@@ -84,6 +74,16 @@
// Middleware definitions
$containerBuilder->addDefinitions([

// JWT Middleware
'jwt' => function ($c) {
return new JwtAuthentication($c->get('settings')['jwt']);
},

// Optional Auth Middleware
'optionalAuth' => function ($c) {
return new OptionalAuth($c->get('jwt'));
},

// Remove trailing slash from URI path
RemoveTrailingSlash::class => function () {
$responseFactory = NyholmPsr17Factory::getResponseFactory();