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.
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(),
// ...
);
See the openclassrooms/doctrine-cache-extension-bundle installation guidefor more details.
# app/config/config.yml
openclassrooms_service_proxy: ~
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
}
}
# 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>
<!-- services.xml -->
<service id="a_service" class="AClass">
<tag name="openclassrooms.service_proxy" cache="doctrine_cache.providers.a_cache_provider"/>
</service>
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']
The bundle uses the Symfony cache warmup to dump the proxies files.
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']