定制 wernerdweight/cors-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wernerdweight/cors-bundle

Composer 安装命令:

composer require wernerdweight/cors-bundle

包简介

Symfony bundle that handles cross-origin resource sharing headers.

README 文档

README

Symfony bundle that handles cross-origin resource sharing headers.

Build Status Latest Stable Version Total Downloads License

Installation

1. Download using composer

composer require wernerdweight/cors-bundle

2. Enable the bundle

Enable the bundle in your kernel:

    <?php
    // config/bundles.php
    return [
        // ...
        WernerDweight\CORSBundle\CORSBundle::class => ['all' => true],
    ];

Configuration

None of the configuration keys are mandatory, default values are mentioned in comments.

# config/packages/cors.yaml
cors:
    access_control:
        # if true, Access-Control-Allow-Credentials header will be present and set to true
        allow_credentials: true # default false
        
        # list of allowed origins (present in Access-Control-Allow-Origin header)
        allow_origin:           # default none
            - '*'               # all origins or list specific origins (see next line)
            - 'https://my-origin.com'
        
        # list of allowed headers (present in Access-Control-Allow-Headers header)
        allow_headers:          # default none
            - 'Authorization'
            - 'Content-Type'
            - 'Cache-Control'
            - 'X-Requested-With'
        
        # list of exposed headers (present in Access-Control-Expose-Headers header)
        expose_headers:         # default none
            - 'Content-Disposition'
    
    # list of controllers to target
    target_controllers:         # default 'WernerDweight\CORSBundle\Contrtoller\CORSControllerInterface'
        - '*'                   # all controllers or list specific controllers (see next line)
        - 'My\Controller\SomeInterface'
        - 'Vendor\Bundle\Controller\SomeOtherInterface'

Target controllers

All controllers that implement WernerDweight\CORSBundle\Controller\CORSControllerInterface will be targeted automatically (no configuration required).

If you can't modify the controller (e.g. it's vendor code), you can specify an interface implemented by the vendor controller (be aware that it may also be implemented by some other controllers), or specify the class of the controller itself.

If you want to target all controllers, use * as configuration value for target_controllers.

Usage

Use your API as usual, your preconfigured headers will be present in the response for specified controllers.

Events

The following events are dispatched, so you can hook in the process. For general info on how to use events, please consult the official Symfony documentation.

PreflightRequestInterceptedEvent (wds.cors_bundle.preflight_request_intercepted)
Issued before the response for preflight request is returned. Contains the request and response. You may want to update the response with some arbitrary headers or replace it completely (the default response is a simple 200: OK response with configured headers).

GetResponseHeadersEvent (wds.cors_bundle.get_response_headers)
Issued before the response headers are set to the response. Contains the request and headers (array). You may want to set some custom headers.

License

This bundle is under the MIT license. See the complete license in the root directiory of the bundle.

wernerdweight/cors-bundle 适用场景与选型建议

wernerdweight/cors-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 992 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cors」 「bundle」 「headers」 「Cross-Origin Resource Sharing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 wernerdweight/cors-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 wernerdweight/cors-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 wernerdweight/cors-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 992
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-07-05