-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergey Surkov
committed
Aug 30, 2021
1 parent
6b539c6
commit 4c48e12
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
} | ||
|
||
|
||
} |