pgs-soft / restfony-bundle
此包已被放弃,不再维护。未建议替代包。
Symfony3 包,用于实现 RESTful CRUD
1.0.0
2016-08-10 09:35 UTC
Requires
- php: >=5.6
- doctrine/doctrine-bundle: ^1.6
- friendsofsymfony/rest-bundle: ^2.0
- jms/serializer-bundle: ^1.1
- knplabs/knp-paginator-bundle: ^2.5
- lexik/form-filter-bundle: ^5.0
- nelmio/api-doc-bundle: ^2.13
- symfony/symfony: ^3.1
- willdurand/hateoas-bundle: ^1.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.11
- pdepend/pdepend: ^2.2
- phing/phing: ^2.14
- php-mock/php-mock-phpunit: ^1.1
- phpmd/phpmd: ^2.4
- phpspec/prophecy: ^1.6
- phpunit/php-code-coverage: ^4.0
- phpunit/phpunit: ^5.5
- sebastian/phpcpd: ^2.0
- sensio/generator-bundle: ^3.0
- squizlabs/php_codesniffer: ^2.6
- theseer/phpdox: 0.8.1.1
This package is auto-updated.
Last update: 2020-02-17 08:20:59 UTC
README
用于辅助创建 Doctrine 实体类的 Bundle,旨在加速创建 RESTful API。
安装
使用 Composer 安装包
composer require pgs-soft/restfony-bundle
在内核中启用包(以及依赖包)
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Pgs\RestfonyBundle\PgsRestfonyBundle(), new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new Nelmio\ApiDocBundle\NelmioApiDocBundle(), new Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle(), new Knp\Bundle\PaginatorBundle\KnpPaginatorBundle(), new Lexik\Bundle\FormFilterBundle\LexikFormFilterBundle(), // ... ); }
为 Restfony 和 FOSRestBundle 准备配置
# app/config/rest.yml jms_serializer: handlers: datetime: default_format: 'Y-m-d\TH:i:sP' property_naming: separator: null lower_case: false fos_rest: param_fetcher_listener: true body_listener: true format_listener: true routing_loader: default_format: json include_format: false serializer: serialize_null: true pgs_restfony: modules:
并将其包含在主配置中
# app/config/config.yml imports: # ... - { resource: rest.yml } # ...
添加路由定义,例如:
# app/config/routing.yml # ... appbundle_rest: resource: "@AppBundle/Resources/config/rest_routing.yml" prefix: /api/
使用方法
对实体运行命令
bin/console pgs:generate:crud MyEntity
提供实体快捷名称(例如 AppBundle:MyEntity
),决定是否添加“写”操作和生成路由。
将生成新文件
- Controller/MyEntityController.php - 包含 RESTful 动作和 ApiDoc 的控制器
- Form/Filter/MyEntityFilterType.php - 表单过滤器类
- Form/Type/MyEntityType.php - 表单类型类
- Manager/MyEntityManager.php - 用于管理存储库的空类
- Manager/MyEntityManagerInterface.php - 上面管理器的接口
- Repository/MyEntityRepository.php - 空的存储库类
- Resources/config/serializer/Entity.MyEntity.yml - JMS Serializer 的配置
- Tests/MyEntityControllerTest.php - 为生成操作设置测试
并将更新配置
- rest.yml - 添加 MyEntity 模块
- rest_routing.yml - 添加 MyEntity 条目
API 文档
如果需要,可以添加 NelmioApiDocBundle API 文档路由,例如:
# app/config/routing_dev.yml # ... NelmioApiDocBundle: resource: "@NelmioApiDocBundle/Resources/config/routing.yml" prefix: /api/doc
作者
- Lech Groblewicz lgroblewicz@pgs-soft.com
- Michał Sikora
贡献者
- Tomasz Brzeziński tbrzezinski@pgs-soft.com
- Karol Joński kjonski@pgs-soft.com
- Krzysztof Maczkowiak kmaczkowiak@pgs-soft.com
- Grzegorz Mandziak gmandziak@pgs-soft.com
- Kamil Purzyński kpurzynski@pgs-soft.com
- Dariusz Rzeźnik drzeznik@pgs-soft.com
- Jakub Werłos jwerlos@pgs-soft.com
- Krzysztof Wojtas kwojtas@pgs-soft.com