amorvan / responders-bundle
一个提供许多响应器的bundle,遵循ADR架构
v4.1.0
2021-03-17 14:14 UTC
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-09-29 05:08:59 UTC
README
描述
一个库,用于根据ADR架构使用多个响应器。
安装
- 需要库
composer require amorvan/responders-bundle
- 对于没有Flex的Symfony 3.*
将bundle添加到 app/AppKernel.php
//app/AppKernel.php
$bundles = [
...,
new Morvan\Bundle\RespondersBundle\MorvanRespondersBundle(),
new AppBundle\AppBundle(),
];
- 对于使用Flex的Symfony 3.4,或Symfony 4.*,或Symfony 5
bundle将自动添加到 config/bundles.php
。检查bundle是否允许在所有环境中使用。
//config/bundles.php
<?php
return [
...,
Morvan\Bundle\RespondersBundle\MorvanRespondersBundle::class => ['all' => true],
];
使用
- 所有响应器都是自动装配的。
- 要使用这些响应器之一,注入响应器并使用响应器的`__invoke`方法和传递正确的参数。
ViewResponder
描述
这个响应器用于返回使用twig构建的视图的响应。
使用
- 在Symfony中,考虑以下方法用于一个动作
use Morvan\Bundle\RespondersBundle\Responders\ViewResponder;
public function listArticles(ViewResponder $viewResponder)
{
return $viewResponder(
'list.html.twig',
[
".idea/articles" => $articles,
]
);
}
RedirectResponder
描述
这个响应器用于返回带有路由参数的重定向响应。
使用
- 在Symfony中,考虑以下方法用于一个动作
use Morvan\Bundle\RespondersBundle\Responders\RedirectResponder;
public function addArticle(RedirectResponder $redirectResponder)
{
return $redirectResponder(
'show_article',
[
'id' => $article->getId(),
]
);
}
JsonResponder
描述
这个响应器用于根据许多参数返回json响应。
使用
- 在Symfony中,考虑以下方法用于一个动作
use Morvan\Bundle\RespondersBundle\Responders\JsonResponder;
public function getArticle(JsonResponder $jsonResponder)
{
return $jsonResponder(
$datas
);
}
FileResponder
描述
这个响应器用于返回文件。
使用
- 在Symfony中,考虑以下方法用于一个动作
use Morvan\Bundle\RespondersBundle\Responders\FileResponder;
public function getArticle(FileResponder $jsonResponder)
{
//$pathToFile accept string or SplFileObject
//$fileName optionnal parameter
return $jsonResponder(
$pathToFile,
$fileName
);
}
质量
使用了许多质量工具。
- PHPCS : PSR 1 & 12。
- PHPStan
- 所有构建都通过了CircleCI的测试。