trt / doctrine-encrypted-cache-bundle
Doctrine 加密缓存包
v0.2
2014-12-22 13:07 UTC
Requires
Requires (Dev)
- phpunit/phpunit: ~4.4
This package is not auto-updated.
Last update: 2024-09-24 08:17:50 UTC
README
此包将 Symfony2 应用与 trt/doctrine-encoded-cache
库集成。
## 为什么需要缓存编码?因为有时候需要使缓存数据不可读。想想高度机密数据。
只有数据库服务器有权限存储数据。
如何做?
缓存数据将通过 AES256 加密/解密(需要 php-mcrypt 扩展)
安装
运行 php composer.phar require trt/doctrine-encrypted-cache-bundle:~0.1
创建你的 KeyProvider
在 Symfony Kernel 中添加以下行
public function registerBundles() { $bundles = array( new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(), new Trt\Doctrine\Cache\Bundle\DoctrineEncodedCacheBundle() ); }
出于安全考虑,存储加密密钥的责任在你,因此必须提供密钥提供者服务。
创建一个实现 KeyProvider
接口的服务。
示例
class CacheKeyProvider implements \Trt\Doctrine\Cache\Key\KeyProvider { /** * Provide the encoding key string. * * @return String */ public function getKey() { return $this->fetchKeyFromASafePlace(); } }
注册服务
services: my_bundle.cache.key_provider: class: My\Bundle\CacheKeyProvider
完整配置
根据 DoctrineCacheBundle 文档,配置缓存服务
## An Example with apc cache doctrine_cache: aliases: cache_apc: my_apc_cache providers: my_apc_cache: type: apc namespace: my_apc_cache_ns aliases: - apc_cache doctrine_encoded_cache: key_provider: my_bundle.cache.key_provider #Your key provider service cache: apc_cache #The doctrine cache service # Enable the doctrine ORM cache doctrine: orm: result_cache_driver: type: service id: doctrine_encoded_cache metadata_cache_driver: type: service id: doctrine_encoded_cache query_cache_driver: type: service id: doctrine_encoded_cache