Add local development example site.
This commit is contained in:
parent
a9ba30fa79
commit
6ddcb03fe8
|
|
@ -5,6 +5,7 @@ vendor/
|
|||
phpdoc/
|
||||
|
||||
# Code coverage report
|
||||
coverage/
|
||||
report/
|
||||
|
||||
# Sphinx Documentation
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
version: '2'
|
||||
services:
|
||||
|
||||
# PHPUnit and Composer
|
||||
php:
|
||||
build:
|
||||
context: .
|
||||
|
|
@ -8,9 +9,24 @@ services:
|
|||
volumes:
|
||||
- .:/usr/local/src/wellrested
|
||||
|
||||
# Documentation generator
|
||||
docs:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./docker/docs/Dockerfile
|
||||
volumes:
|
||||
- .:/usr/local/src/wellrested
|
||||
- .:/usr/local/src/wellrested
|
||||
|
||||
# Local development site
|
||||
nginx:
|
||||
image: nginx:1.13
|
||||
ports:
|
||||
- 8080:80
|
||||
volumes:
|
||||
- .:/usr/local/src/wellrested
|
||||
- ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
|
||||
|
||||
php-fpm:
|
||||
image: php:7.1-fpm
|
||||
volumes:
|
||||
- .:/usr/local/src/wellrested
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
server {
|
||||
listen 80;
|
||||
|
||||
root /usr/local/src/wellrested/public;
|
||||
index index.php index.html;
|
||||
charset utf-8;
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
# Front Controller
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$args;
|
||||
}
|
||||
|
||||
# PHP
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_pass php-fpm:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_buffers 8 8k;
|
||||
fastcgi_buffer_size 16k;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param SCRIPT_NAME index.php;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,6 @@
|
|||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-html" target="./report" charset="UTF-8" hightlight="true" />
|
||||
<log type="coverage-html" target="./public/coverage" charset="UTF-8" hightlight="true" />
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
../docs/build/html
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use WellRESTed\Message\Response;
|
||||
use WellRESTed\Message\Stream;
|
||||
use WellRESTed\Server;
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// Create a handler using the PSR-15 RequestHandlerInterface
|
||||
class HomePageHandler implements RequestHandlerInterface
|
||||
{
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$view = <<<HTML
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>WellRESTed Development Site</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>WellRESTed Development Site</h1>
|
||||
|
||||
<p>To run unit tests, run:</p>
|
||||
<code>docker-compose run --rm php phpunit</code>
|
||||
<p>View the <a href="/coverage/">code coverage report</a>.</p>
|
||||
|
||||
<p>To generate documentation, run:</p>
|
||||
<code>docker-compose run --rm docs</code>
|
||||
<p>View <a href="/docs/"> documentation</a>.</p>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
return (new Response(200))
|
||||
->withHeader('Content-type', 'text/html')
|
||||
->withBody(new Stream($view));
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
$server = new Server();
|
||||
|
||||
// Add a router to the server to map methods and endpoints to handlers.
|
||||
$router = $server->createRouter();
|
||||
$router->register("GET", "/", new HomePageHandler());
|
||||
$server->add($router);
|
||||
|
||||
// Read the request from the client, dispatch a handler, and output.
|
||||
$server->respond();
|
||||
Loading…
Reference in New Issue