skalpa / silex-doctrine-annotations-provider

Doctrine 注释服务提供者,适用于 Pimple 3.x / Silex 2.x

v1.0.0 2017-04-12 01:06 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:51:34 UTC


README

Build Status Scrutinizer Code Quality Code Coverage

适用于 Silex 2.x / Pimple 3.x 的 Doctrine 注释服务提供者

允许你在 Silex/Pimple 应用程序中使用 Doctrine 注释读取器。

安装

使用 composer 安装服务提供者

composer require skalpa/silex-doctrine-annotations-provider

注册

$app->register(new \Skalpa\Silex\Doctrine\AnnotationsServiceProvider());

$fooAnnotations = $app['annotations']->getClassAnnotations(new \ReflectionClass('Foobar\FooClass'));

配置参数

配置注释缓存

默认情况下,注释读取器使用的缓存是 ArrayCache,这可能不是你希望在生产服务器上使用的。

如果你已经使用 Doctrine Cache 服务提供者,并希望使用已注册的缓存服务,请将 annotations.cache 设置为服务的名称

// The DoctrineCacheServiceProvider will register a service named "cache"
$app->register(new DoctrineCacheServiceProvider());

// Cache annotations using the "cache" service
$app->register(new AnnotationsServiceProvider(), [
    'annotations.cache' => 'cache',
]);

或者,你可以覆盖 annotations.cache 服务并提供自己的缓存提供者

$app->register(new AnnotationsServiceProvider(), [
    'annotations.cache' => function () {
        $cache = new \Doctrine\Common\Cache\PhpFileCache(__DIR__.'/cache);
        $cache->setNamespace('annotations');

        return $cache;
    },
]);