Skip to content

Commit

Permalink
Removing dependecncies
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Jan 9, 2022
1 parent 2523595 commit e4a9a97
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 36 deletions.
15 changes: 11 additions & 4 deletions composer.json
Expand Up @@ -28,23 +28,30 @@
}
],

"support": {
"email": "code@fastybird.com",
"issues": "https://github.com/FastyBird/web-server/issues",
"source" : "https://github.com/FastyBird/web-server"
},

"prefer-stable" : true,

"minimum-stability" : "stable",

"require" : {
"php": ">=7.4.0|>=8.0.0",
"contributte/console": "^0.9",
"contributte/event-dispatcher": "^0.8",
"fastybird/socket-server-factory": "^0.1",
"fastybird/socket-server-factory": "^0.2",
"ipub/slim-router": "^0.2",
"nette/bootstrap": "^3.1",
"nette/di": "^3.0",
"nette/utils": "^3.2",
"psr/event-dispatcher": "^1.0",
"psr/http-message": "^1.0",
"psr/log": "^1.1",
"react/http": "^1.3",
"sunrise/http-server-request": "^1.1"
"sunrise/http-server-request": "^1.1",
"symfony/console": "^5.0",
"symfony/event-dispatcher-contracts": "^2.5|^3.0"
},

"require-dev" : {
Expand Down
14 changes: 9 additions & 5 deletions src/Application/Application.php
Expand Up @@ -43,12 +43,12 @@ class Application implements IApplication
/** @var Routing\IRouter */
private Routing\IRouter $router;

/** @var EventDispatcher\EventDispatcherInterface */
private EventDispatcher\EventDispatcherInterface $dispatcher;
/** @var EventDispatcher\EventDispatcherInterface|null */
private ?EventDispatcher\EventDispatcherInterface $dispatcher;

public function __construct(
Routing\IRouter $router,
EventDispatcher\EventDispatcherInterface $dispatcher
?EventDispatcher\EventDispatcherInterface $dispatcher = null
) {
$this->router = $router;
$this->dispatcher = $dispatcher;
Expand All @@ -65,7 +65,9 @@ public function run()
{
$request = ServerRequestFactory::fromGlobals();

$this->dispatcher->dispatch(new Events\RequestEvent($request));
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new Events\RequestEvent($request));
}

try {
$response = $this->router->handle($request);
Expand All @@ -74,7 +76,9 @@ public function run()
throw $e;
}

$this->dispatcher->dispatch(new Events\ResponseEvent($request, $response));
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new Events\ResponseEvent($request, $response));
}

$this->sendStatus($response);
$this->sendHeaders($response);
Expand Down
6 changes: 3 additions & 3 deletions src/Application/Console.php
Expand Up @@ -15,7 +15,7 @@

namespace FastyBird\WebServer\Application;

use Contributte\Console\Application;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input;
use Symfony\Component\Console\Output;
use Throwable;
Expand All @@ -35,9 +35,9 @@ class Console implements IConsole
private Application $application;

public function __construct(
Application $application
?Application $application = null
) {
$this->application = $application;
$this->application = $application ?? new Application();
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Commands/HttpServerCommand.php
Expand Up @@ -61,8 +61,8 @@ class HttpServerCommand extends Console\Command\Command
/** @var Middleware\RouterMiddleware */
private Middleware\RouterMiddleware $routerMiddleware;

/** @var EventDispatcher\EventDispatcherInterface */
private EventDispatcher\EventDispatcherInterface $dispatcher;
/** @var EventDispatcher\EventDispatcherInterface|null */
private ?EventDispatcher\EventDispatcherInterface $dispatcher;

/** @var Log\LoggerInterface */
private Log\LoggerInterface $logger;
Expand All @@ -77,7 +77,7 @@ class HttpServerCommand extends Console\Command\Command
* @param Middleware\CorsMiddleware $corsMiddleware
* @param Middleware\StaticFilesMiddleware $staticFilesMiddleware
* @param Middleware\RouterMiddleware $routerMiddleware
* @param EventDispatcher\EventDispatcherInterface $dispatcher
* @param EventDispatcher\EventDispatcherInterface|null $dispatcher
* @param SocketServerFactory\SocketServerFactory $socketServerFactory
* @param EventLoop\LoopInterface $eventLoop
* @param Log\LoggerInterface|null $logger
Expand All @@ -87,9 +87,9 @@ public function __construct(
Middleware\CorsMiddleware $corsMiddleware,
Middleware\StaticFilesMiddleware $staticFilesMiddleware,
Middleware\RouterMiddleware $routerMiddleware,
EventDispatcher\EventDispatcherInterface $dispatcher,
SocketServerFactory\SocketServerFactory $socketServerFactory,
EventLoop\LoopInterface $eventLoop,
?EventDispatcher\EventDispatcherInterface $dispatcher = null,
?Log\LoggerInterface $logger = null,
?string $name = null
) {
Expand Down Expand Up @@ -135,7 +135,9 @@ protected function execute(
*/

try {
$this->dispatcher->dispatch(new Events\StartupEvent());
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new Events\StartupEvent());
}

$httpServer = new Http\HttpServer(
$this->eventLoop,
Expand Down
14 changes: 9 additions & 5 deletions src/Middleware/RouterMiddleware.php
Expand Up @@ -32,27 +32,31 @@
final class RouterMiddleware
{

/** @var EventDispatcher\EventDispatcherInterface */
private EventDispatcher\EventDispatcherInterface $dispatcher;
/** @var EventDispatcher\EventDispatcherInterface|null */
private ?EventDispatcher\EventDispatcherInterface $dispatcher;

/** @var Routing\IRouter */
private Routing\IRouter $router;

public function __construct(
Routing\IRouter $router,
EventDispatcher\EventDispatcherInterface $dispatcher
?EventDispatcher\EventDispatcherInterface $dispatcher = null
) {
$this->router = $router;
$this->dispatcher = $dispatcher;
}

public function __invoke(ServerRequestInterface $request): ResponseInterface
{
$this->dispatcher->dispatch(new Events\RequestEvent($request));
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new Events\RequestEvent($request));
}

$response = $this->router->handle($request);

$this->dispatcher->dispatch(new Events\ResponseEvent($request, $response));
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(new Events\ResponseEvent($request, $response));
}

return $response;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/Unit/Commands/HttpServerCommandTest.phpt
Expand Up @@ -78,9 +78,9 @@ final class HttpServerCommandTest extends BaseMockeryTestCase
$corsFilesMiddleware,
$staticFilesMiddleware,
$routerMiddleware,
$eventDispatcher,
$socketServerFactory,
$eventLoop,
$eventDispatcher,
$logger
));

Expand Down
14 changes: 1 addition & 13 deletions tests/common.neon
Expand Up @@ -14,16 +14,4 @@ php:
date.timezone: Europe/Prague

extensions:
contributteConsole : Contributte\Console\DI\ConsoleExtension(%consoleMode%)
contributteEvents : Contributte\EventDispatcher\DI\EventDispatcherExtension
fbSocketServerFactory : FastyBird\SocketServerFactory\DI\SocketServerFactoryExtension

contributteConsole:
name: FastyBird:WebServer!
version: '1.0'
catchExceptions: true
autoExit: true
url: http://example.com
lazy: false
helperSet: \Symfony\Component\Console\Helper\HelperSet
helpers: []
fbSocketServerFactory : FastyBird\SocketServerFactory\DI\SocketServerFactoryExtension

0 comments on commit e4a9a97

Please sign in to comment.