Git Product home page Git Product logo

foa.responder_bundle's Introduction

FOA.Resonder_Bundle

AbstractResponder of action domain responder by Paul M Jones.

Foreword

Installation

It is installable and autoloadable via composer as foa/responder-bundle.

Quality

Scrutinizer Code Quality Code Coverage Build Status

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.

Community

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.

Example usage

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);

Create your responder object

<?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);

Rendering and Setting content to response

<?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.

Inside Aura Project

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');

Integrated Views

We have integrated the below template engines. You can choose the one you love.

  1. aura/view
  2. league/plates
  3. mustache/mustache
  4. twig/twig

foa.responder_bundle's People

Contributors

harikt avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.