brille24 / sylius-shop-api-plugin
1.0.1
2018-10-29 14:23 UTC
Requires
- php: ^7.1
- brille24/sylius-customer-options-plugin: dev-master
- brille24/sylius-tierprice-plugin: dev-master
- brille24/sylius-wishlist-plugin: dev-master
- league/tactician-bundle: ^1.1
- league/tactician-doctrine: ^1.1
- phpstan/phpstan-shim: ^0.10.1
- sylius/sylius: ^1.1
Requires (Dev)
- lakion/api-test-case: ^3.1
- lexik/jwt-authentication-bundle: ^2.5
- matthiasnoback/symfony-config-test: ^3.1
- matthiasnoback/symfony-dependency-injection-test: ^2.3
- phpspec/phpspec: ^5.0
- phpstan/phpstan-shim: ^0.10.3
- phpstan/phpstan-webmozart-assert: ^0.10.0
- phpunit/phpunit: ^6.5
- sylius-labs/coding-standard: ^2.0
Suggests
- nelmio/cors-bundle: allows you to send Cross-Origin Ajax API Request
- dev-master
- 1.0.1
- 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
- dev-merge_downstream
- dev-channel_provider
- dev-peter
- dev-test
- dev-wishlist_refactoring
- dev-fixed_api_branch
- dev-order_endpoint
- dev-reorder
- dev-addresses
- dev-tierprice
- dev-wishlist_customer_options
- dev-wishlist
- dev-email_verification
- dev-expose_customer_orders
- dev-products-by-code
- dev-yaml-stringing
This package is auto-updated.
Last update: 2021-04-12 15:28:07 UTC
README
Sylius Shop API
Sylius Shop API
此仓库在 Sylius E-Commerce 平台之上提供了 ShopApi 实现。
注意
这只是 Sylius - Standard 的补充。请查看 官方文档 以理解基本概念。
先决条件
为了运行此插件,您需要满足以下要求
-
已安装 composer Composer。
$ wget https://getcomposer.org.cn/composer.phar $ php composer.phar create-project sylius/sylius-standard project
-
已安装 Sylius
$ cd project $ php bin/console sylius:install
其余的命令在 project
文件夹中执行。
使用方法
-
运行
composer require sylius/shop-api-plugin:^1.0@beta
。 -
扩展配置文件
- 将 SyliusShopApi 添加到 AppKernel。
// app/AppKernel.php public function registerBundles(): array { return array_merge(parent::registerBundles(), [ new \Sylius\ShopApiPlugin\ShopApiPlugin(), new \League\Tactician\Bundle\TacticianBundle(), ]); }
- 将
- { path: '^/shop-api', priorities: ['json'], fallback_format: json, prefer_extension: true }
添加到app/config/config.yml
文件中的fos_rest.format_listener.rules
部分,并从插件导入配置。
# app/config/config.yml imports: # ... - { resource: "@ShopApiPlugin/Resources/config/app/config.yml" } - { resource: "@ShopApiPlugin/Resources/config/app/sylius_mailer.yml" } # ... 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 }
- 调整结账配置,以避免与 Sylius 商店 API 冲突。例如(假设您正在使用常规 Sylius 安全定义)
# app/config/config.yml # ... sylius_shop: checkout_resolver: pattern: "%sylius.security.shop_regex%/checkout/.+"
- 添加路由到
app/config/routing.yml
# app/config/routing.yml # ... sylius_shop_api: resource: "@ShopApiPlugin/Resources/config/routing.yml"
- 配置防火墙
- 将
sylius.security.shop_regex
参数更改为排除shop-api
前缀 - 添加 ShopAPI 正则表达式参数
shop_api.security.regex: "^/shop-api"
- 添加 ShopAPI 防火墙配置
- 将
parameters: # ... sylius.security.shop_regex: "^/(?!admin|api/.*|api$|shop-api)[^/]++" # shop-api has been added inside the brackets shop_api.security.regex: "^/shop-api" # ... security: firewalls: // ... shop_api: pattern: "%shop_api.security.regex%" stateless: true anonymous: true
-
(可选) 如果您已安装
nelmio/NelmioCorsBundle
以支持跨源 Ajax 请求- 将 NelmioCorsBundle 添加到 AppKernel
// app/AppKernel.php /** * {@inheritdoc} */ public function registerBundles() { $bundles = array( // ... new Nelmio\CorsBundle\NelmioCorsBundle(), // ... ); // ... }
- 将配置添加到 `config.yml`
# app/config/config.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', 'OPTIONS'] max_age: 3600
附加功能
属性
如果您想要接收序列化属性,您需要在 shop_api.included_attributes
键下定义它们的代码数组。例如。
shop_api: included_attributes: - "MUG_MATERIAL_CODE"
授权
默认情况下,此包不提供授权。但它与 LexikJWTAuthenticationBundle 一起进行了测试。要检查示例配置,请查看
- security.yml
- jwt 参数 和 jwt 配置 在 config.yml 中
- 示例 rsa 密钥
- 登录请求
来自测试应用。
测试
可以使用 API 测试用例测试应用程序。要运行测试套件,请执行以下命令
$ bin/phpunit
PHPStan
PHPStan 是一个用于分析 PHP 类型的工具。问题是基础 API 不支持 PHPStan,并且仍在使用 PHP 7.1 运行,这意味着安装 PHPStan 将导致向后兼容性破坏。
安全问题
如果您认为您发现了安全问题,请不要使用问题跟踪器并不要公开发布。相反,所有安全问题都必须发送至 security@sylius.com
。