1. Go to this page and download the library: Download phly/conduit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phly / conduit example snippets
use Phly\Conduit\MiddlewarePipe;
use Phly\Http\Server;
teServer($app,
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$server->listen();
use Phly\Conduit\MiddlewarePipe;
use Phly\Http\Server;
teServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// Landing page
$app->pipe('/', function ($req, $res, $next) {
if ($req->getUri()->getPath() !== '/') {
return $next($req, $res);
}
return $res->end('Hello world!');
});
// Another page
$app->pipe('/foo', function ($req, $res, $next) {
return $res->end('FOO!');
});
$server->listen();
function (
$error, // Can be any type
Psr\Http\Message\ServerRequestInterface $request,
Psr\Http\Message\ResponseInterface $response,
callable $next
) {
}
$api = new MiddlewarePipe(); // API middleware collection
$api->pipe(/* ... */); // repeat as necessary
$app = new MiddlewarePipe(); // Middleware representing the application
$app->pipe('/api', $api); // API middleware attached to the path "/api"
use Phly\Conduit\MiddlewarePipe;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class CustomMiddleware extends MiddlewarePipe
{
public function __invoke(Request $request, Response $response, callable $next = null)
{
// perform some work...
// delegate to parent
parent::__invoke($request, $response, $next);
// maybe do more work?
}
}
use Phly\Conduit\MiddlewarePipe;
class CustomMiddleware extends MiddlewarePipe
{
public function __construct($configuration)
{
parent::__construct();
// do something with configuration ...
// attach some middleware ...
$this->pipe(/* some middleware */);
}
}
class MiddlewarePipe implements MiddlewareInterface
{
public function pipe($path, $middleware = null);
public function __invoke(
Psr\Http\Message\ServerRequestInterface $request = null,
Psr\Http\Message\ResponseInterface $response = null,
callable $out = null
);
}
class Next
{
public function __invoke(
Psr\Http\Message\ServerRequestInterface $request,
Psr\Http\Message\ResponseInterface $response,
$err = null
);
}
function ($request, $response, $next) use ($bodyParser)
{
$bodyParams = $bodyParser($request);
return $next(
$request->withBodyParams($bodyParams), // Next will pass the new
$response // request instance
);
}