openclassrooms / service-proxy-bundle
Service Proxy Symfony2 Bundle
v2.3.0
2022-05-12 12:01 UTC
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: 2024-09-12 17:07:30 UTC
README
ServiceProxyBundle 提供了 ServiceProxy 库的集成。
ServiceProxy 提供了跨类管理技术代码的功能
- 事务性上下文(尚未实现)
- 安全访问(尚未实现)
- 缓存管理
- 事件(尚未实现)
- 日志(尚未实现)
有关完整详细信息,请参阅 ServiceProxy。
安装
此捆绑包可以使用 composer 安装
composer require openclassrooms/service-proxy-bundle
或者直接将包添加到 composer.json 文件中。
{ "require": { "openclassrooms/service-proxy-bundle": "*" } }
安装完包后,将捆绑包添加到 AppKernel.php 文件中
// in AppKernel::registerBundles() $bundles = array( // ... new OpenClassrooms\Bundle\ServiceProxyBundle\OpenClassroomsServiceProxyBundle(), // ... );
⚠️ 使用缓存功能需要安装 openclassrooms/doctrine-cache-extension-bundle。
有关更多详细信息,请参阅 openclassrooms/doctrine-cache-extension-bundle 安装指南。
配置
# app/config/config.yml openclassrooms_service_proxy: ~
用法
缓存
使用 Cache 注解。
有关更多详细信息,请参阅 Service Proxy Cache。
<?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>
性能
自动加载器
使用代理需要大量的 I/O。请参阅 Ocramius\ProxyManager 生产调优。
可以指定使用代理自动加载器的环境。
openclassrooms_service_proxy: production_environments: ['prod', 'stage'] # default : ['prod']
缓存预热
捆绑包使用 Symfony 缓存预热来导出代理文件。
完整配置
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']