Skip to content

Commit

Permalink
fix php7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Surkov committed Aug 30, 2021
1 parent 6b539c6 commit 4c48e12
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/Routing/KernelPreloadFindRouteMiddleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Symbiotic\Routing;

use Psr\Http\Message\{ServerRequestInterface,ResponseInterface};
use Psr\Http\Server\{MiddlewareInterface,RequestHandlerInterface};
use Symbiotic\Core\{CoreInterface,ProvidersRepository};

/**
* Class Settlements
* @package Symbiotic\Services
*
*/
class KernelPreloadFindRouteMiddleware implements MiddlewareInterface
{

protected $core;

public function __construct(CoreInterface $core)
{
$this->core = $core;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$app = $this->core;

$providers = [
CacheRoutingProvider::class => null,
SettlementsRoutingProvider::class => null
];
foreach ($providers as $class => $v) {
if (class_exists($class)) {
$providers[$class] = $app->register(new $class($app));
} else {
unset($providers[$class]);
}
}
foreach ($providers as $class => $v) {
$v->boot();
}
$app[ProvidersRepository::class]->exclude(array_keys($providers));

$path = $request->getUri()->getPath();
$route = $this->core['router']->match($request->getMethod(), $path);

if ($route) {
/**
* @used-by \Symbiotic\Http\Kernel\RoutingHandler::handle()
*/
$app['route'] = $route;
return $handler->handle($request);
} else {
$app['destroy_response'] = true;
return \_DS\response(404, new \Exception('Route not found for path [' . $path . ']', 7623));
}
}
}
21 changes: 21 additions & 0 deletions src/Routing/SettlementsPreloadMiddlewareBootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Symbiotic\Routing;



use Symbiotic\Core\BootstrapInterface;
use Symbiotic\Core\CoreInterface;
use Symbiotic\Http\Kernel\PreloadKernelHandler;

class SettlementsPreloadMiddlewareBootstrap implements BootstrapInterface
{
public function bootstrap(CoreInterface $app): void
{
$app['listeners']->add(PreloadKernelHandler::class, function (PreloadKernelHandler $event) use ($app) {
$event->append(new KernelPreloadFindRouteMiddleware($app));
});
}


}

0 comments on commit 4c48e12

Please sign in to comment.