Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Application interface to allow cretting different implementations
- Loading branch information
Showing
7 changed files
with
111 additions
and
89 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
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,79 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Antidot\Application\Http; | ||
|
||
use Antidot\Application\Http\Middleware\Pipeline; | ||
use Antidot\Container\MiddlewareFactory; | ||
use Zend\HttpHandlerRunner\RequestHandlerRunner; | ||
|
||
class WebServerApplication implements Application | ||
{ | ||
protected $pipeline; | ||
protected $router; | ||
protected $runner; | ||
protected $middlewareFactory; | ||
protected $routeFactory; | ||
|
||
public function __construct( | ||
RequestHandlerRunner $runner, | ||
Pipeline $pipeline, | ||
Router $router, | ||
MiddlewareFactory $middlewareFactory, | ||
RouteFactory $routeFactory | ||
) { | ||
$this->runner = $runner; | ||
$this->pipeline = $pipeline; | ||
$this->router = $router; | ||
$this->middlewareFactory = $middlewareFactory; | ||
$this->routeFactory = $routeFactory; | ||
} | ||
|
||
public function run(): void | ||
{ | ||
$this->runner->run(); | ||
} | ||
|
||
public function pipe(string $middlewareName): void | ||
{ | ||
$this->pipeline->pipe($this->middlewareFactory->create($middlewareName)); | ||
} | ||
|
||
public function get(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('GET', $uri, $middleware, $name); | ||
} | ||
|
||
public function post(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('POST', $uri, $middleware, $name); | ||
} | ||
|
||
public function patch(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('PATCH', $uri, $middleware, $name); | ||
} | ||
|
||
public function put(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('PUT', $uri, $middleware, $name); | ||
} | ||
|
||
public function delete(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('DELETE', $uri, $middleware, $name); | ||
} | ||
|
||
public function options(string $uri, array $middleware, string $name): void | ||
{ | ||
$this->route('OPTIONS', $uri, $middleware, $name); | ||
} | ||
|
||
public function route(string $method, string $uri, array $middleware, string $name): void | ||
{ | ||
$this->router->append( | ||
$this->routeFactory->create([$method], $middleware, $uri, $name) | ||
); | ||
} | ||
} |
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
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
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
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
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