1. Go to this page and download the library: Download blast/turbine 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/ */
= new Hawkbit\Application();
$app->get('/', 'HomeController::index'); // calls index method on HomeController class
$app->run();
// HomeController.php
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class HomeController
{
public function index(ServerRequestInterface $request, ResponseInterface $response, array $args)
{
$response->getBody()->write('<h1>It works!</h1>');
return $response;
}
}
// index.php
Application();
$app->getContainer()->add('CustomService', new CustomService);
$app->get('/', 'HomeController::index'); // calls index method on HomeController class
$app->run();
// HomeController.php
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
class HomeController
{
/**
* @var CustomService
*/
private $service;
/**
* @param CustomService $application
*/
public function __construct(CustomService $service = null)
{
$this->service = $service;
}
/**
* @return CustomService
*/
public function getService()
{
return $this->service;
}
public function index(ServerRequestInterface $request, ResponseInterface $response, array $args)
{
//do somehing with service
$service = $this->getService();
return $response;
}
}
$app->group('/admin', function (\League\Route\RouteGroup $route) {
//access app container (or any other method!)
$app = $this;
$route->map('GET', '/acme/route1', 'AcmeController::actionOne');
$route->map('GET', '/acme/route2', 'AcmeController::actionTwo');
$route->map('GET', '/acme/route3', 'AcmeController::actionThree');
});
// index.php
\Application();
$app->get('/', function ($request, $response) {
$response->setContent('<h1>Hello World</h1>');
return $response;
});
$httpKernel = new Hawkbit\Application\Symfony\HttpKernelAdapter($app);
$stack = (new \Stack\Builder())
->push('Some/MiddleWare') // This will execute first
->push('Some/MiddleWare') // This will execute second
->push('Some/MiddleWare'); // This will execute third
$app = $stack->resolve($httpKernel);
\Stack\run($httpKernel); // The app will run after all the middlewares have run
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\ServerRequestFactory;
use Hawkbit\Application;
use Hawkbit\Application\Stratigility\MiddlewarePipeAdapter;
$application = new Application();
$application->get('/', function($request, ResponseInterface $response){
$response->getBody()->write('Hello World');
});
$middleware = new MiddlewarePipeAdapter($application);
//wrap html heading
$middleware->pipe('/', function($request, ResponseInterface $response, $next){
$response->getBody()->write('<h1>');
/** @var ResponseInterface $response */
$response = $next($request, $response);
$response->getBody()->write('</h1>');
});
/** @var ResponseInterface $response */
$response = $middleware(ServerRequestFactory::fromGlobals(), $application->getResponse());
echo $response->getBody(); //prints <h1>Hello World</h1>
$app->addListener($app::EVENT_RESPONSE_CREATED, function (\Hawkbit\Application\ApplicationEvent $event) {
$request = $event->getRequest();
$response = $event->getResponse();
// manipulate request or response
$event->setRequest($request);
$event->setResponse($response);
});
$app->addListener($app::EVENT_RESPONSE_SENT, function (\Hawkbit\Application\ApplicationEvent $event) {
$request = $event->getRequest();
$response = $event->getResponse();
// manipulate request or response
$event->setRequest($request);
$event->setResponse($response);
});
$app->addListener($app::EVENT_RUNTIME_ERROR, function (\Hawkbit\Application\ApplicationEvent $event, $exception) use ($app) {
//process exception
});
$app->addListener($app::EVENT_LIFECYCLE_ERROR, function (\Hawkbit\Application\ApplicationEvent $event, \Exception $exception) {
$errorResponse = $event->getErrorResponse();
//manipulate error response and process exception
$event->setErrorResponse($errorResponse);
});
$app->addListener($app::EVENT_LIFECYCLE_COMPLETE, function (\Hawkbit\Application\ApplicationEvent $event) {
// access the request using $event->getRequest()
// access the response using $event->getResponse()
});
$app->addListener($app::EVENT_SHUTDOWN, function (\Hawkbit\Application\ApplicationEvent $event, $response, $terminatedOutputBuffers = []) {
// access the response using $event->getResponse()
// access terminated output buffer contents
// or force application exit()
});
// addListener
$app->addListener('custom.event', function ($event, $time) {
return 'the time is '.$time;
});
// or with class addListener
$app->addListener(Acme\Event::class, function (Acme\Event $event, $time) {
return 'the time is '.$time;
});
// Publish
$app->getEventEmitter()->emit('custom.event', time());
$app->getContainer()->add('Bar', function () {
return new Bar();
});
$app->getContainer()->add('Foo', function () use ($app) {
return new Foo(
$app->getContainer()->get('Bar')
);
});
$app->setContainer($container);
$app->getContainer();
$app->getConfigurator();
$app->getContainer()->share(\Zend\Config\Config::class, new \Zend\Config\Config([], true));
$app->getContainer()->share(\Whoops\Run::class, new \Whoops\Run());