openclassrooms / service-proxy-bundle
Service Proxy Symfony2 Bundle
Installs: 216 890
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 24
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=7.4
- openclassrooms/doctrine-cache-extension: 1.0.*@dev
- openclassrooms/service-proxy: ^3.1.0
- symfony/config: ~3.4 || ~4.0 || ^5.0 || ^6.0
- symfony/dependency-injection: ~3.4 || ~4.0 || ^5.0 || ^6.0
- symfony/event-dispatcher: ~3.4 || ~4.0 || ^5.0 || ^6.0
- symfony/http-kernel: ~3.4 || ~4.0 || ^5.0 || ^6.0
- symfony/yaml: ~3.4 || ~4.0 || ^5.0 || ^6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ~2.15
- phpunit/phpunit: ~7.5
This package is auto-updated.
Last update: 2025-01-12 17:56:41 UTC
README
The ServiceProxyBundle offers integration of the ServiceProxy library.
ServiceProxy provides functionality to manage technical code over a class:
- Transactional context (not implemented yet)
- Security access (not implemented yet)
- Cache management
- Events (not implemented yet)
- Logs (not implemented yet)
See ServiceProxy for full details.
Installation
This bundle can be installed using composer:
composer require openclassrooms/service-proxy-bundle
or by adding the package to the composer.json file directly.
{ "require": { "openclassrooms/service-proxy-bundle": "*" } }
After the package has been installed, add the bundle to the AppKernel.php file:
// in AppKernel::registerBundles() $bundles = array( // ... new OpenClassrooms\Bundle\ServiceProxyBundle\OpenClassroomsServiceProxyBundle(), // ... );
⚠️ The usage of cache capabilities requires the installation of the openclassrooms/doctrine-cache-extension-bundle.
See the openclassrooms/doctrine-cache-extension-bundle installation guidefor more details.
Configuration
# app/config/config.yml openclassrooms_service_proxy: ~
Usage
Cache
Use the Cache annotation.
See Service Proxy Cache for more details.
<?php namespace A\Namespace; use OpenClassrooms\ServiceProxy\Annotations\Cache; class AClass { /** * @Cache */ public function aMethod() { // do things } }
Using default cache provider
# app/config/config.yml doctrine_cache: providers: a_cache_provider: type: array openclassrooms_service_proxy: default_cache: doctrine_cache.providers.a_cache_provider
<!-- services.xml --> <service id="a_service" class="A\Namespace\AClass"> <tag name="openclassrooms.service_proxy"/> </service>
Using specific cache provider
<!-- services.xml --> <service id="a_service" class="AClass"> <tag name="openclassrooms.service_proxy" cache="doctrine_cache.providers.a_cache_provider"/> </service>
Performance
Autoloader
The usage of a proxy require a lot of I/O. See Ocramius\ProxyManager Tunning for production.
It's possible to specify the environments where the proxy autoloader is used.
openclassrooms_service_proxy: production_environments: ['prod', 'stage'] # default : ['prod']
Cache Warmup
The bundle uses the Symfony cache warmup to dump the proxies files.
Full configuration
openclassrooms_service_proxy: # the directory where the proxy are written cache_dir : "/a/path/to/the/cache/directory" # default: %kernel.cache_dir% # the default cache provider (optional) default_cache: doctrine_cache.providers.a_cache_provider # default: null # the Symfony environments where the proxy autoloader is used production_environments: ['prod', 'stage'] # default : ['prod']