Download the PHP package raketman/service-versioning-bundle without Composer
On this page you can find all versions of the php package raketman/service-versioning-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download raketman/service-versioning-bundle
More information about raketman/service-versioning-bundle
Files in raketman/service-versioning-bundle
Package service-versioning-bundle
Short Description Easy versioning your services
License MIT
Informations about the package service-versioning-bundle
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