amorvan / responders-bundle
A bundle provide many responders according ADR architecture
Installs: 78
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 3
Type:symfony-bundle
Requires
- php: ^7.3|^7.4|^8
- symfony/framework-bundle: ^3.4|^4.4|^5
- symfony/serializer: ^3.4|^4.4|^5
- twig/twig: ^2.10|^3
Requires (Dev)
- phpstan/phpstan: ^0.12.42
- phpunit/phpunit: ^8.1
- squizlabs/php_codesniffer: ^3.5.8
- dev-development
- 4.x-dev
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.6.0
- v1.5.0
- v1.4
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-dependabot/composer/twig/twig-3.4.3
- dev-dependabot/composer/symfony/framework-bundle-5.3.15
- dev-dependabot/composer/symfony/serializer-5.3.12
- dev-feature/fileresponder
This package is auto-updated.
Last update: 2024-11-29 05:57:03 UTC
README
Description
A library to use many responders according ADR architecture.
Installation
- Require library
composer require amorvan/responders-bundle
- For Symfony 3.* without Flex:
Adding bundle to app/AppKernel.php
//app/AppKernel.php
$bundles = [
...,
new Morvan\Bundle\RespondersBundle\MorvanRespondersBundle(),
new AppBundle\AppBundle(),
];
- For Symfony 3.4 with Flex, Symfony 4.* or Symfony 5:
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],
];
Usage
- All responders are autowiring.
- To use one of these responders, inject responder and use the responder's with __invoke` method and pass the correct parameters.
ViewResponder
Description
This responder used to return a response with a view build with twig.
Usage
- Example inside Symfony, consider following method for an action :
use Morvan\Bundle\RespondersBundle\Responders\ViewResponder;
public function listArticles(ViewResponder $viewResponder)
{
return $viewResponder(
'list.html.twig',
[
".idea/articles" => $articles,
]
);
}
RedirectResponder
Description
This responder used to return a redirect response with route parameters
Usage
- Example inside Symfony, consider following method for an action :
use Morvan\Bundle\RespondersBundle\Responders\RedirectResponder;
public function addArticle(RedirectResponder $redirectResponder)
{
return $redirectResponder(
'show_article',
[
'id' => $article->getId(),
]
);
}
JsonResponder
Description
This responder used to return a json response according many parameters
Usage
- Example inside Symfony, consider following method for an action :
use Morvan\Bundle\RespondersBundle\Responders\JsonResponder;
public function getArticle(JsonResponder $jsonResponder)
{
return $jsonResponder(
$datas
);
}
FileResponder
Description
This responder used to return a file.
Usage
- Example inside Symfony, consider following method for an action :
use Morvan\Bundle\RespondersBundle\Responders\FileResponder;
public function getArticle(FileResponder $jsonResponder)
{
//$pathToFile accept string or SplFileObject
//$fileName optionnal parameter
return $jsonResponder(
$pathToFile,
$fileName
);
}
Quality
Many tools used for quality.
- PHPCS : PSR 1 & 12.
- PHPStan
- All builds passed by CircleCI.