-
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
Marco Perone
committed
Apr 22, 2017
1 parent
38fa4b1
commit c583b3a
Showing
1 changed file
with
39 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,39 @@ | ||
<?php | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace Marcosh\EffectorExample; | ||
|
||
use Marcosh\Effector\Compose; | ||
use Marcosh\Effector\Effect\Http\EmitResponse; | ||
use Marcosh\Effector\Effect\Http\ReceiveRequest; | ||
use Psr\Http\Message\RequestInterface; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Zend\Diactoros\Response; | ||
|
||
/** | ||
* You could use this as a web application. | ||
* | ||
* This is really a dumb application, but using PSR-7 middleware this could be easily | ||
* become something more interesting. | ||
* | ||
* You could use this with `php -S localhost:8000 example/Http.php` | ||
* and then browse to `localhost:8000` to check this is actually working. | ||
* | ||
* If you don't have php 7.1 installed in your machine, you could use docker with | ||
* `docker run --rm -ti -p 8000:8000 -v "$(pwd):/app" php:7.1-cli php -S 0.0.0.0:8000 /app/example/Http.php` | ||
*/ | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$websiteLogic = function (RequestInterface $request): ResponseInterface { | ||
return new Response\TextResponse((string) $request->getUri()); | ||
}; | ||
|
||
$app = Compose::pieces( | ||
new ReceiveRequest(), | ||
$websiteLogic, | ||
new EmitResponse() | ||
); | ||
|
||
$app(); |