raketman/service-versioning-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

raketman/service-versioning-bundle

最新稳定版本:1.0.1

Composer 安装命令:

composer require raketman/service-versioning-bundle

包简介

Easy versioning your services

README 文档

README

##Versioning Symfony Services

composer require raketman/service-versioning-bundle

####Usage :

services:
    
  #Specify the tag 'raketman.version.factory' - now this service will have versions
  #resolver - service that will determine the version
  
  app.validation.test:
    class: App\Validation\VInterface
    tags:
      - {name: 'raketman.version.factory', resolver: 'app.version.resolver'}
  # OR if yuo have autowire
  
  App\Validation\VInterface
    tags:
      - {name: 'raketman.version.factory', resolver: 'app.version.resolver'}



  #The version is indicated through tags that correspond to the name of the service we want to version
  #version - value of version 

  app.validation.test_v1:
    class: App\Validation\V1
    tags:
      - {name: 'app.validation.test', version: 1 }
      - {name: 'app.validation.test', version: 3 }

  app.validation.test_v2:
    class: App\Validation\V2
    tags:
      - {name: 'app.validation.test', version: 2 }
  #OR if yuo have autowire
  
  app.validation.test_v1:
    class: App\Validation\V1
    tags:
      - {name: 'App\Validation\VInterface', version: 1 }
      - {name: 'App\Validation\VInterface', version: 3 }

  app.validation.test_v2:
    class: App\Validation\V2
    tags:
      - {name: 'App\Validation\VInterface', version: 2 }		
	
  # Version resolver
  	
  app.version.resolver:
    class: App\Resolver\Version
    arguments:
        - '@request_stack'

Now you have the service "app.validation.test", upon receipt of which, depending on which version it will return "app.version.resolver", if 1 then "app.validation.test_v1" or if 2 then "app.validation.test_v2 will return

#####For example, the implementation of "app.version.resolver" is as follows:

 namespace App\Resolver;

 use Raketman\Bundle\ServiceVersioningBundle\Resolver\VersionResolverInterface;
 use Symfony\Component\HttpFoundation\RequestStack;

 class Version implements VersionResolverInterface
 {
     /** @var RequestStack  */
     private  $request;
 
     public function __construct(RequestStack $request)
     {
         $this->request = $request;
     }
 
     public function getVersion()
     {
         return $this->request->getMasterRequest()->get('version') ? : 1;
     }
 }

Now we can use "app.validation.test", and get different versions depending on $ _GET ['version']

 $validation = $this->get('app.validation.test');
 
 if $_GET['version'] === 1, then get_class($validation) - App\Validation\V1 // app.validation.test_v1
 if $_GET['version'] === 2, then get_class($validation) - App\Validation\V2 // app.validation.test_v2
 if $_GET['version'] === 3, then get_class($validation) - App\Validation\V1 // app.validation.test_v1
 
 OR
 
 /**
 * @Route("/some-method")
 */
 public function test(App\Validation\VInterface $validation)
 {
     //if $_GET['version'] === 1, then get_class($validation) - App\Validation\V1 // app.validation.test_v1
     //if $_GET['version'] === 2, then get_class($validation) - App\Validation\V2 // app.validation.test_v2
     //if $_GET['version'] === 3, then get_class($validation) - App\Validation\V1 // app.validation.test_v1
 }

The implementation of resolver can be any, for example, based on the current user, which will allow for various users on the go to issue the necessary service implementations

If you use versioning in daemons, then do not forget to set the service mode

  shared: false

otherwise you will always be given the same instance after the first call

统计信息

  • 总下载量: 2.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固