PHP code example of hawkbit / presentation

1. Go to this page and download the library: Download hawkbit/presentation 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/ */

    

hawkbit / presentation example snippets







use \Hawkbit\Application;
use \Hawkbit\Presentation\PresentationService;
use \Hawkbit\Presentation\Adapters\PlatesAdapter;
use \Hawkbit\Presentation\Adapters\Adapter;

$app = new Application(s',
]);

$app[PresentationService::class] = new PresentationService($app->getContainer());




/** @var \Hawkbit\Presentation\PresentationService $Presentation */
$service = $app[\Hawkbit\Presentation\PresentationService::class];




use Hawkbit\Presentation\PresentationService;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class MyController
{
    /**
     * @var PresentationService
     */
    private $presentationService;

    /**
     * TestInjectableController constructor.
     * @param PresentationService $presentationService
     */
    public function __construct(PresentationService $presentationService)
    {
        $this->presentationService = $presentationService;
    }

    public function getIndex(ServerRequestInterface $request, ResponseInterface $response, array $args = [])
    {
        $response->getBody()->write($this->presentationService->render('index', ['world' => 'World']));
        return $response;
    }
}



use Hawkbit\Presentation\PresentationService;

/** @var PresentationService $service */
$service = $app->getContainer()->get(PresentationService::class);
$service->getEngine()
    ->addFolder('acme', __DIR__ . '/templates/acme')
    ->registerFunction('uppercase', function ($string) {
        return strtoupper($string);
    });




use \Hawkbit\Application;
use \Hawkbit\Presentation\PresentationService;
use \Hawkbit\Presentation\Adapters\PlatesAdapter;
use \Hawkbit\Presentation\Adapters\Adapter;
use \Hawkbit\Presentation\Adapters\Psr7WrapperAdapter;

$app = new Application(ServerRequestInterface::class], 
$app[\Psr\Http\Message\ResponseInterface::class]);

$app[PresentationService::class] = new PresentationService($app->getContainer());




use Hawkbit\Presentation\PresentationService;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class MyController
{
    /**
     * @var PresentationService
     */
    private $presentationService;

    /**
     * TestInjectableController constructor.
     * @param PresentationService $presentationService
     */
    public function __construct(PresentationService $presentationService)
    {
        $this->presentationService = $presentationService;
    }

    public function getIndex(ServerRequestInterface $request, ResponseInterface $response, array $args = [])
    {
        // configured with PSR-7 adapter
        return $this->presentationService->render('index', ['world' => 'World']);
    }
}



use Hawkbit\Presentation\PresentationService;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class MyController
{
    /**
     * @var PresentationService
     */
    private $presentationService;

    /**
     * TestInjectableController constructor.
     * @param PresentationService $presentationService
     */
    public function __construct(PresentationService $presentationService)
    {
        $this->presentationService = $presentationService;
    }
    
    public function getIndex(ServerRequestInterface $request, ResponseInterface $response, array $args = [])
    {
        // manipulate response
        // for example we need to add an api key
        $response = $response->withHeader('API-KEY', 123);
        
        // configured with PSR-7 adapter
        return $this->presentationService->render('index', ['world' => 'World'], $response);
    }
}