Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo committed May 21, 2019
1 parent ab107ba commit 126ad77
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
8 changes: 6 additions & 2 deletions app/Auth/UI/Http/Middleware/OAuth.php
Expand Up @@ -12,19 +12,23 @@
class OAuth implements MiddlewareInterface
{
private $container;

public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (!$this->container->get('oauth_server')->verifyResourceRequest(Request::createFromGlobals())) {
$this->container->get('oauth_server')->getResponse()->send();
die;
}

$tokenData = $this->container->get('oauth_server')->getAccessTokenData(Request::createFromGlobals());

$request = $request->withAttribute('user_id', $tokenData['user_id']);

return $handler->handle($request);
}
}
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace App\Users\Infrastructure\Persistance\Doctrine\ORM;

Expand Down
4 changes: 4 additions & 0 deletions bootstrap/db.php
Expand Up @@ -21,6 +21,10 @@

$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);

($isDevMode)
? $config->setAutoGenerateProxyClasses(true)
: $config->setAutoGenerateProxyClasses(false);

$em = EntityManager::create($dbParams, $config);
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('uuid_binary_ordered_time', 'binary');

Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -55,6 +55,7 @@
"schema-create": "doctrine orm:schema-tool:create",
"schema-drop": "doctrine orm:schema-tool:drop --force",
"schema-update": "doctrine orm:schema-tool:update --force",
"schema-cache:clear-metadata": "doctrine orm:clear-cache:metadata",
"sql-import": "doctrine dbal:import ",
"check-style": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 app/ system/",
"fix-style": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 app/ system/"
Expand Down
8 changes: 3 additions & 5 deletions system/UI/Http/Controller/BaseController.php
Expand Up @@ -24,7 +24,7 @@ abstract class BaseController
protected $commandBus;

protected $statusCode = 200;

public function __construct(
ContainerInterface $container,
ErrorReporterInterface $errorReporter,
Expand All @@ -42,10 +42,8 @@ public function run(RequestInterface $request, string $call, array $vars)
{
try {
return $this->{$call . 'Action'}($request, $vars);
} catch (NotFoundException $e) {
} catch (NotFoundException | ResourceNotFoundException $e) {
return $this->respondNotFound();
} catch (ResourceNotFoundException $e) {
return $this->respondWithData([]);
} catch (InvalidArgumentException $e) {
$this->errorReporter->report($e);
return $this->respondBadRequestError();
Expand All @@ -71,7 +69,7 @@ protected function respondInternalError($message = 'Internal Error!')
{
return $this->setStatusCode(500)->respond($message);
}

protected function respondBadRequestError($message = 'Bad request or invalid parameters')
{
return $this->setStatusCode(400)->respond($message);
Expand Down
12 changes: 6 additions & 6 deletions system/UI/Http/Router.php
Expand Up @@ -15,7 +15,7 @@
class Router
{
private $middlewares = [];

private $routes = [];

public function addMiddleware(MiddlewareInterface $middleware): void
Expand All @@ -29,11 +29,11 @@ public function addRoute(string $method, string $path, $handler, array $middlewa
$route->method = $method;
$route->path = $path;
$route->handler = $handler;
$route->middlewares = $this->middlewares + $middlewares;
$route->middlewares = array_merge($this->middlewares, $middlewares);

$this->routes[] = $route;
}

public function routes()
{
return function (RouteCollector $collector) {
Expand All @@ -56,7 +56,7 @@ private function getHandler(stdClass $route)
) {
if (is_callable($route->handler)) {
$handlerCallable = $route->handler;

return $handlerCallable();
}

Expand All @@ -74,7 +74,7 @@ private function processMiddlewares(array $middlewares, ServerRequestInterface $
$relay = new Relay($middlewares, function ($entry) {
return is_string($entry) ? new $entry() : $entry;
});

return $relay->handle($request);
}
}

0 comments on commit 126ad77

Please sign in to comment.