lightsuner / carbon-bundle
提供 Carbon 日期时间库作为注解参数转换器(SensioFrameworkExtraBundle)
2.3
2018-11-30 12:05 UTC
Requires
- nesbot/carbon: *
- sensio/framework-extra-bundle: 3.*
- symfony/form: ~2.3|~3.0
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-09-28 14:58:09 UTC
README
此包提供了将请求和表单数据转换为 Carbon 对象的机会。使用参数转换器将请求数据转换为
... use Carbon\Carbon; ... /** * @Route("/blog/archive/{start}/{end}") * @ParamConverter("start", options={"format": "Y-m-d"}) * @ParamConverter("end", options={"format": "Y-m-d"}) */ public function archiveAction(Carbon $start, Carbon $end) { }
无需对表单数据进行代码更改。Symfony 的内置 DateType
和 DateTimeType
会自动扩展以返回 Carbon 实例。
安装
步骤 1: 使用 composer 下载 Carbon SF2 Bundle
在您的 composer.json 中添加 Carbon SF2 Bundle
对于 sensio/framework-extra-bundle
2.x
,请按照 此链接 进行操作。
对于 sensio/framework-extra-bundle
3.x
{ "require": { "lightsuner/carbon-bundle": "2.*" } }
现在运行以下命令让 composer 下载此包:
$ php composer.phar update lightsuner/carbon-bundle
Composer 会将包安装到您项目的 vendor/lightsuner
目录中。
步骤 2: 启用包
在内核中启用包
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new LightSuner\CarbonBundle\CarbonBundle(), ); }