1. Go to this page and download the library: Download icanboogie/http 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/ */
icanboogie / http example snippets
namespace ICanBoogie\HTTP;
// The request is usually created from the $_SERVER super global.
$request = Request::from($_SERVER);
/* @var ResponderProvider $responder_provider */
// The Responder Provider matches a request with a Responder
$responder = $responder_provider->responder_for_request($request);
// The Responder responds to the request with a Response, it might also throw an exception.
$response = $responder->respond($request);
// The response is sent to the client.
$response();
namespace ICanBoogie\HTTP;
$initial_request = Request::from($_SERVER);
# a custom request in the same environment
$request = Request::from('path/to/file.html', $_SERVER);
# a request created from scratch
$request = Request::from([
Request::OPTION_PATH => 'path/to/file.html',
Request::OPTION_IS_LOCAL => true, // or OPTION_IP => '::1'
Request::OPTION_METHOD => RequestMethod::METHOD_POST,
Request::OPTION_HEADERS => [
'Cache-Control' => 'no-cache'
]
]);
namespace ICanBoogie\HTTP;
/** @var Request $request */
/** @var \ICanBoogie\Routing\Route $route */
$request->context->add($route);
// …
$route = $request->conntext->find(Route::class);
# or, if the value is
namespace ICanBoogie\HTTP;
/* @var $request Request */
/* @var ResponderProvider $responder_provider */
// The Responder Provider matches a request with a Responder
$responder = $responder_provider->responder_for_request($request);
// The Responder responds to the request with a Response, it might also throw an exception.
$response = $responder->respond($request);
// The response is sent to the client.
$response();
namespace ICanBoogie\HTTP;
/* @var $request Request */
$response = new FileResponse("/absolute/path/to/my/file", $request, [
FileResponse::OPTION_FILENAME => "Vidéo d'un été à la mer.mp4"
]);
$response();