sylius / shop-api-plugin
Sylius电子商务平台的Shop API。
Requires
- php: ^8.0
- doctrine/doctrine-bundle: ^2.0
- lexik/jwt-authentication-bundle: ^2.5
- sylius/sylius: ~1.11.10 || ~1.12.0
- symfony/messenger: ^5.4 || ^6.0
Requires (Dev)
- lchrusciel/api-test-case: ^5.1
- matthiasnoback/symfony-config-test: ^4.0
- matthiasnoback/symfony-dependency-injection-test: ^4.0
- phpspec/phpspec: ^7.0
- phpstan/phpstan: ^1.8
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^9.0
- sylius-labs/coding-standard: ^4.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- symfony/webpack-encore-bundle: ^1.15
Suggests
- nelmio/cors-bundle: allows you to send Cross-Origin Ajax API Request
- 1.7.x-dev
- 1.6.x-dev
- v1.6.0
- 1.5.x-dev
- v1.5.1
- v1.5.0
- 1.4.x-dev
- v1.4.1
- v1.4.0
- 1.3.x-dev
- v1.3.1
- v1.3.0
- 1.2.x-dev
- v1.2.1
- v1.2.0
- 1.1.x-dev
- v1.1.1
- v1.1.0
- 1.0.x-dev
- v1.0.0
- v1.0.0-rc.3
- v1.0.0-rc.2
- v1.0.0-rc.1
- v1.0.0-beta.21
- v1.0.0-beta.20
- v1.0.0-beta.19
- v1.0.0-beta.18
- v1.0.0-beta.17
- v1.0.0-beta.16
- v1.0.0-beta.15
- v1.0.0-beta.14
- v1.0.0-beta.13
- v1.0.0-beta.12
- v1.0.0-beta.11
- v1.0.0-beta.10
- v1.0.0-beta.9
- v1.0.0-beta.8
- v1.0.0-beta.7
- v1.0.0-beta.6
- v1.0.0-beta.5
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- v1.0.0-alpha.3
- v1.0.0-alpha.2
- v1.0.0-alpha.1
This package is auto-updated.
Last update: 2024-09-11 21:02:34 UTC
README
Sylius Shop API
此仓库包含一个插件,该插件通过JSON API扩展了Sylius电子商务平台,允许从客户的角度执行所有标准商店操作。
文档
最新的文档可在此处找到。如果您想了解更多关于系统如何工作的信息,请查看食谱
安装
重要提示:在安装SyliusShopApiPlugin之前,您应禁用所有SyliusShopBundle的依赖项。您不能一起使用这些包。
-
运行
composer require sylius/shop-api-plugin
,当被问及是否要执行Flex配方时,回答'是'。 -
扩展配置文件
- 将SyliusShopApi添加到
config/bundles.php
。
// config/bundles.php return [ Sylius\ShopApiPlugin\SyliusShopApiPlugin::class => ['all' => true], ];
- 将
- { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true }
添加到config/packages/fos_rest.yaml
文件中的fos_rest.format_listener.rules
部分,并从插件导入配置。
# config/packages/_sylius_shop_api.yaml imports: # <-- Add this section if it does not already exist and add the lines below # ... - { resource: "@SyliusShopApiPlugin/Resources/config/app/config.yml" } - { resource: "@SyliusShopApiPlugin/Resources/config/app/sylius_mailer.yml" } # config/packages/fos_rest.yaml fos_rest: # ... format_listener: rules: - { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true } # <-- Add this - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true } - { path: '^/', stop: true }
- 添加新的路由文件以导入SyliusShopApiPlugin的路由
# config/routes/sylius_shop_api.yaml sylius_shop_api: resource: "@SyliusShopApiPlugin/Resources/config/routing.yml"
-
配置防火墙
- 将
sylius.security.shop_regex
参数更改为排除shop-api
前缀 - 添加ShopAPI正则表达式参数
sylius_shop_api.security.regex: "^/shop-api"
- 添加ShopAPI防火墙配置
-
Symfony 6
# config/packages/security.yaml parameters: # ... sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api|media/.*)[^/]++" # shop-api has been added inside the brackets sylius_shop_api.security.regex: "^/shop-api" # ... security: firewalls: // ... sylius_shop_api: pattern: "%sylius_shop_api.security.regex%" stateless: true entry_point: jwt provider: sylius_shop_user_provider json_login: check_path: /shop-api/login username_path: email password_path: password success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure jwt: true access_control: - { path: "%sylius_shop_api.security.regex%/address-book", role: ROLE_USER} - { path: "%sylius_shop_api.security.regex%/me", role: ROLE_USER}
-
Symfony 5
# config/packages/security.yaml parameters: # ... sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api|media/.*)[^/]++" # shop-api has been added inside the brackets sylius_shop_api.security.regex: "^/shop-api" # ... security: firewalls: // ... sylius_shop_api: pattern: "%sylius_shop_api.security.regex%" stateless: true anonymous: true provider: sylius_shop_user_provider json_login: check_path: /shop-api/login username_path: email password_path: password success_handler: lexik_jwt_authentication.handler.authentication_success failure_handler: lexik_jwt_authentication.handler.authentication_failure guard: authenticators: - lexik_jwt_authentication.jwt_token_authenticator access_control: - { path: "%sylius_shop_api.security.regex%/address-book", role: ROLE_USER} - { path: "%sylius_shop_api.security.regex%/me", role: ROLE_USER}
-
- 将
-
(可选)如果您已安装
nelmio/NelmioCorsBundle
以支持跨源Ajax请求- 将NelmioCorsBundle添加到AppKernel
// config/bundles.php return [ Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true], ];
- 添加新的配置文件
# config/packages/nelmio_cors.yml # ... nelmio_cors: defaults: allow_credentials: false allow_origin: [] allow_headers: [] allow_methods: [] expose_headers: [] max_age: 0 hosts: [] origin_regex: false forced_allow_origin_value: ~ paths: '^/shop-api/': allow_origin: ['*'] allow_headers: ['Content-Type', 'authorization'] allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'PATCH', 'OPTIONS'] max_age: 3600
- 将SyliusShopApi添加到
Shop API的示例配置可在此找到:https://github.com/Sylius/SyliusDemo/commit/4872350dcd6c987d54dec1f365b4bb890d7183c9
附加功能
属性
如果您希望接收序列化属性,您需要在sylius_shop_api.included_attributes
键下定义它们的代码数组。例如。
# config/packages/sylius_shop_api.yml sylius_shop_api: included_attributes: - "MUG_MATERIAL_CODE"
此插件包含与LexikJWTAuthenticationBundle的集成。有关安全自定义的更多信息,请参阅那里。
测试
可以使用API测试用例测试应用程序。要运行测试套件,请执行以下命令
$ cp tests/Application/.env.test.dist tests/Application/.env.test $ set -a && source tests/Application/.env.test && set +a $ (cd tests/Application && bin/console doctrine:database:create -e test) $ (cd tests/Application && bin/console doctrine:schema:create -e test) $ vendor/bin/phpunit
应用程序也可以使用PHPSpec进行测试
$ vendor/bin/phpspec run
安全问题
如果您认为您发现了一个安全问题,请不要使用问题跟踪器,也不要公开发布。相反,所有安全问题都必须发送到security@sylius.com
。
维护
此库由Sylius以及以下组织外部的贡献者共同维护
发布周期
此项目遵循语义版本控制。Shop API的发布周期独立于Sylius的发布周期。
尚未计划下一主要版本发布。根据需要发布小版本和补丁版本。
我们只为最新的小版本提供bug修复。对于后续小版本的发布,我们提供一年的安全修复。