1. Go to this page and download the library: Download linkeddatacenter/usilex 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/ */
linkeddatacenter / usilex example snippets
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Server\MiddlewareInterface;
class MyMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface
{
//here your code that returns a response or passes the control to the handler
}
}
...
$app= new Application;
$app->register( new MyPsr7ServiceProvider() };
$app['my.router'] = function($app) { return new \My\RouterMiddleWare($app) };
$app['my.notfound'] = function($app) { return new \My\NotFoundMiddleWare($app) };
$app['handler.queue'] = [
'my.router'
'my.notfound'
];
$app['uSilex.httpHandler'] = function($app) {
return new MyHttpHandler($app['handler.queue']);
};
$app->boot()->run();
Silex\Application;
use uSilex\ContainerAwareTrait;
use uSilex\Provider\Psr15\RelayServiceProvider as Psr15Provider;
use uSilex\Provider\Psr7\DiactorosServiceProvider as Psr7Provider ;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Http\Server\MiddlewareInterface;
use Zend\Diactoros\Response\TextResponse;
class MyMiddleware implements MiddlewareInterface {
use ContainerAwareTrait;
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
return new \Zend\Diactoros\Response\TextResponse( $this->containerGet('message', 'Hi'));
}
}
$app = new Application;
$app->register(new Psr15Provider());
$app->register(new Psr7Provider());
$app['myMiddleware'] = function($app) { return new MyMiddleware($app); };
$app['message'] = 'hello world!';
$app['handler.queue'] = ['myMiddleware'];
$app->run();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.