1. Go to this page and download the library: Download germania-kg/responder 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/ */
germania-kg / responder example snippets
public function createResponse( $data ) : ResponseInterface;
public function __invoke( $data ) : ResponseInterface;
use Germania\Responder\TwigResponder;
// Have Twig\Environment at hand
$twig = ...;
$responder = new TwigResponder($twig, "template");
// These are optional
$default_context = array();
$psr17 = new \Nyholm\Psr7\Factory\Psr17Factory;
$responder = new TwigResponder($twig, "template", $default_context, $psr17);
$responder->setTwig( $twig );
$responder->setTemplateField('template');
$responder->setDefaultContext( array('another' => 'data') );
$responder->setResponseFactory($psr17);
# Fallback when context lacks 'template' element
$responder->setDefaultTemplate('website.tpl');
$data = array(
'template' => 'website.tpl',
'foo' => 'bar'
)
// These are equal:
$response = $responder->createResponse($data);
$response = $responder($data);
use Germania\Responder\JsonResponder;
use Germania\Responder\ResponderExceptionInterface;
use Slim\Psr7\Factory\ResponseFactory;
$json = \JSON_PRETTY_PRINT;
$psr17 = new ResponseFactory; // Optional
$responder = new JsonResponder($json);
$responder = new JsonResponder($json, $psr17);
use Germania\Responder\CallbackResponder;
use Germania\Responder\JsonResponder;
// Do-nothing callback for demonstration purposes
$callback = function($item) { return $item; };
// Any kind of ResponderInterface will do
$inner = new JsonResponder();
$responder = new CallbackResponder($callback, $inner);
use Germania\Responder\NoContentResponder;
$responder = new NoContentResponder();
use Germania\Responder\ErrorResponder;
use Germania\Responder\JsonResponder;
$debug = true;
$inner_responder = new JsonResponder(\JSON_PRETTY_PRINT);
$error_responder = new ErrorResponder($debug, $inner_responder);