mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Update JMSSerializerServiceProvider to allow adding metadata_dirs
This commit is contained in:
@@ -14,8 +14,6 @@ namespace Alchemy\Phrasea\Core\Provider;
|
|||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
use JMS\Serializer\SerializerBuilder;
|
use JMS\Serializer\SerializerBuilder;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
|
||||||
|
|
||||||
class JMSSerializerServiceProvider implements ServiceProviderInterface
|
class JMSSerializerServiceProvider implements ServiceProviderInterface
|
||||||
{
|
{
|
||||||
@@ -24,20 +22,20 @@ class JMSSerializerServiceProvider implements ServiceProviderInterface
|
|||||||
$app['serializer.cache-directory'] = $app->share(function () use ($app) {
|
$app['serializer.cache-directory'] = $app->share(function () use ($app) {
|
||||||
return $app['cache.path'].'/serializer/';
|
return $app['cache.path'].'/serializer/';
|
||||||
});
|
});
|
||||||
|
$app['serializer.metadata_dirs'] = $app->share(function () {
|
||||||
$app['serializer.src_directory'] = $app['root.path'] . '/vendor/jms/serializer/src/';
|
return [];
|
||||||
|
|
||||||
$app['serializer.metadata.annotation_reader'] = $app->share(function () use ($app) {
|
|
||||||
AnnotationRegistry::registerAutoloadNamespace("JMS\Serializer\Annotation", $app['serializer.src_directory']);
|
|
||||||
|
|
||||||
return new AnnotationReader();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$app['serializer'] = $app->share(function (Application $app) {
|
$app['serializer'] = $app->share(function (Application $app) {
|
||||||
return SerializerBuilder::create()->setCacheDir($app['serializer.cache-directory'])
|
$builder = SerializerBuilder::create()
|
||||||
->setDebug($app['debug'])
|
->setCacheDir($app['serializer.cache-directory'])
|
||||||
->setAnnotationReader($app['serializer.metadata.annotation_reader'])
|
->setDebug($app['debug']);
|
||||||
->build();
|
|
||||||
|
if (!empty($app['serializer.metadata_dirs'])) {
|
||||||
|
$builder->addMetadataDirs($app['serializer.metadata_dirs']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder->build();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user