AbstractResponder of action domain responder by Paul M Jones.
It is installable and autoloadable via composer as foa/responder-bundle.
This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request.
To ask questions, provide feedback, or otherwise communicate with the Aura community, please join our Google Group, follow @auraphp on Twitter, or chat with us on #auraphp on Freenode.
It is recommend to checkout the action domain responder example code.
It is recommended you use some sort of DI containers.
<?php
namespace FOA\Responder_Bundle;
class BrowseResponder extends AbstractResponder
{
protected $available = array(
'text/html' => '',
'application/json' => '.json',
);
protected $payload_method = array(
'FOA\DomainPayload\Found' => 'display',
'FOA\DomainPayload\NotFound' => 'notFound',
'FOA\DomainPayload\Valid' => 'valid',
'FOA\DomainPayload\NotValid' => 'notValid',
);
public function display()
{
if ($this->negotiateMediaType()) {
$content_type = $this->response->content->getType();
if ($content_type) {
$view .= $this->available[$content_type];
}
$this->renderView('browse', 'layout');
}
}
}
First instantiate your templating engine of choice. Eg usage of Aura.View .
<?php
// Instantiate your templating engine
use Aura\Html\HelperLocatorFactory;
use Aura\View\ViewFactory;
use FOA\Responder_Bundle\Renderer\AuraView;
$factory = new HelperLocatorFactory;
$helpers = $factory->newInstance();
$view_factory = new ViewFactory();
$view = $view_factory->newInstance($helpers);
$renderer = new AuraView($view);
<?php
use Aura\Web\Response;
use Aura\Accept\Accept;
$web_factory = new WebFactory($GLOBALS);
$response = $web_factory->newResponse();
$accept_factory = new AcceptFactory($_SERVER);
$accept = $accept_factory->newInstance();
$responder = new BrowseResponder($accept, $response, $renderer);
<?php
use FOA\DomainPayload\PayloadFactory;
$payload_factory = new PayloadFactory();
$payload = $payload_factory->found(array('name' => 'Hari KT'));
$responder->setPayload($payload);
$responder->__invoke();
Calling __invoke will render and set the content on the response object. Now you can either use Aura\Web\ResponseSender
to send the response, or any other library to set and send the response back.
Add the configuration as
$di->params['FOA\Responder_Bundle\AbstractResponder']['response'] = $di->lazyGet('aura/web-kernel:response');
$di->params['FOA\Responder_Bundle\AbstractResponder']['view'] = $di->lazyNew('Aura\View\View');
$di->params['FOA\Responder_Bundle\AbstractResponder']['accept'] = $di->lazyNew('Aura\Accept\Accept');
We have integrated the below template engines. You can choose the one you love.