openclassrooms/service-proxy-bundle

Service Proxy Symfony2 Bundle

安装量: 216,889

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 23

分支: 1

公开问题: 0

类型:symfony-bundle

v2.3.0 2022-05-12 12:01 UTC

README

Build Status SensioLabsInsight Coverage Status

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']