Bundle to use many responders acccording ADR architecture
A library to use many responders according ADR architecture.
composer require amorvan/responders-bundle
Adding bundle to app/AppKernel.php
//app/AppKernel.php
$bundles = [
...,
new Morvan\Bundle\RespondersBundle\MorvanRespondersBundle(),
new AppBundle\AppBundle(),
];
Bundle is automatically add to config/bundles.php
. Check the bundle is allow for all environment.
//config/bundles.php
<?php
return [
...,
Morvan\Bundle\RespondersBundle\MorvanRespondersBundle::class => ['all' => true],
];
This responder used to return a response with a view build with twig.
use Morvan\Bundle\RespondersBundle\Responders\ViewResponder;
public function listArticles(ViewResponder $viewResponder)
{
return $viewResponder(
'list.html.twig',
[
".idea/articles" => $articles,
]
);
}
This responder used to return a redirect response with route parameters
use Morvan\Bundle\RespondersBundle\Responders\RedirectResponder;
public function addArticle(RedirectResponder $redirectResponder)
{
return $redirectResponder(
'show_article',
[
'id' => $article->getId(),
]
);
}
This responder used to return a json response according many parameters
use Morvan\Bundle\RespondersBundle\Responders\JsonResponder;
public function getArticle(JsonResponder $jsonResponder)
{
return $jsonResponder(
$datas
);
}
This responder used to return a file.
use Morvan\Bundle\RespondersBundle\Responders\FileResponder;
public function getArticle(FileResponder $jsonResponder)
{
//$pathToFile accept string or SplFileObject
//$fileName optionnal parameter
return $jsonResponder(
$pathToFile,
$fileName
);
}
Many tools used for quality.