wwsh / gastro-api
为桌面和移动应用程序维护的 Gastro API
dev-master
2016-03-17 08:23 UTC
Requires
- php: >=5.4
- doctrine/doctrine-bundle: >=1.4
- doctrine/orm: ~2.5,>=2.2.3
- friendsofsymfony/rest-bundle: 1.7.7
- incenteev/composer-parameter-handler: ~2.1
- jms/di-extra-bundle: 1.*
- jms/security-extra-bundle: ^1.5
- jms/serializer-bundle: ^1.1
- knplabs/knp-snappy-bundle: ^1.2
- nelmio/api-doc-bundle: ^2.11
- qandidate/symfony-json-request-transformer: 1.*
- sensio/distribution-bundle: *
- sensio/framework-extra-bundle: 3.*
- symfony/monolog-bundle: >=2.7
- symfony/symfony: >=2.8
- twig/extensions: ~1.2
Requires (Dev)
- mockery/mockery: *
- phpspec/phpspec: ~2.0
This package is not auto-updated.
Last update: 2024-09-14 19:09:22 UTC
README
此包支持由 wwsh 编写的 Gastro API 的功能,该功能由桌面和移动应用程序指定和使用。
如需更多信息,请联系 Thomas Parys,请访问 此网站。
配置
在您的 mail config.yml 中启用 Doctrine ORM,并添加以下 FOSRestBundle 的配置
fos_rest:
param_fetcher_listener: true
body_listener: true
body_converter:
enabled: true
format_listener:
rules:
- { path: '^/api', priorities: [ json ], fallback_format: json, prefer_extension: true }
- { path: '^/', priorities: [html, json], fallback_format: html, prefer_extension: false }
view:
view_response_listener: 'true'
mime_types: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1']
formats:
json: true
html: false
xml: false
routing_loader:
default_format: json
include_format: false
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
messages:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': true
access_denied_listener:
json: true
别忘了在 kernel 中启用这些包
new \FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new \Nelmio\ApiDocBundle\NelmioApiDocBundle(),
new \Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
现在是将路由包含到您的 routing.yml 中的时候了
api:
resource: "@ApiBundle/Resources/config/routing.yml"
type: rest
prefix: /api
您可以自定义前缀,但我建议使用标准前缀。
现在 API 已经设置好了。要创建数据库模式并用示例数据填充,您可以使用
php bin/console database:create
php bin/console doctrine:schema:create
php bin/console doctrine:fixtures:load
在此处检查您的 API 是否工作: API DOC
如有任何疑问,请随时提问。