Subscriber is on DataRepository not actual repository

This commit is contained in:
Benoît Burnichon
2016-05-10 16:28:38 +02:00
parent f87fc35f6a
commit 7e9e34a87d
6 changed files with 115 additions and 89 deletions

View File

@@ -1057,7 +1057,7 @@ class V1Controller extends Controller
$searchView = $this->buildSearchView($this->doSearch($request));
$subdefTransformer = new SubdefTransformer();
$subdefTransformer = new SubdefTransformer($this->app['acl'], $this->getAuthenticatedUser(), new PermalinkTransformer());
$recordTransformer = new RecordTransformer($subdefTransformer, new TechnicalDataTransformer());
$storyTransformer = new StoryTransformer($subdefTransformer, $recordTransformer);
$compositeTransformer = new V1SearchCompositeResultTransformer($recordTransformer, $storyTransformer);
@@ -1269,20 +1269,20 @@ class V1Controller extends Controller
*/
private function resolveSearchIncludes(Request $request)
{
if (!$request->attributes->get('_extended', false)) {
return [];
if ($request->attributes->get('_extended', false)) {
return [
'results.stories.records.subdefs',
'results.stories.records.metadata',
'results.stories.records.caption',
'results.stories.records.status',
'results.records.subdefs',
'results.records.metadata',
'results.records.caption',
'results.records.status',
];
}
return [
'results.stories.records.subdefs',
'results.stories.records.metadata',
'results.stories.records.caption',
'results.stories.records.status',
'results.records.subdefs',
'results.records.metadata',
'results.records.caption',
'results.records.status',
];
return [];
}
/**
@@ -1293,16 +1293,16 @@ class V1Controller extends Controller
*/
private function resolveSearchRecordsIncludes(Request $request)
{
if (!$request->attributes->get('_extended', false)) {
return [];
if ($request->attributes->get('_extended', false)) {
return [
'results.subdefs',
'results.metadata',
'results.caption',
'results.status',
];
}
return [
'results.subdefs',
'results.metadata',
'results.caption',
'results.status',
];
return [];
}
/**

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Databox\Caption;
use Alchemy\Phrasea\Databox\DataboxBoundRepositoryFactory;
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
use Doctrine\Common\Cache\Cache;
class CaptionDataRepositoryFactory implements DataboxBoundRepositoryFactory
{
/**
* @var DataboxConnectionProvider
*/
private $connectionProvider;
/**
* @var Cache
*/
private $cache;
public function __construct(DataboxConnectionProvider $connectionProvider, Cache $cache)
{
$this->connectionProvider = $connectionProvider;
$this->cache = $cache;
}
public function createRepositoryFor($databoxId)
{
return new CachedCaptionDataRepository(
new DbalCaptionDataRepository($this->connectionProvider->getConnection($databoxId)),
$this->cache,
sprintf('databox[%d]:', $databoxId)
);
}
}

View File

@@ -10,8 +10,6 @@
namespace Alchemy\Phrasea\Databox\Caption;
use Assert\Assertion;
class CaptionRepository
{
/**

View File

@@ -1,60 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Databox\Caption;
use Alchemy\Phrasea\Databox\DataboxBoundRepositoryFactory;
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
use Doctrine\Common\Cache\Cache;
class CaptionRepositoryFactory implements DataboxBoundRepositoryFactory
{
/**
* @var DataboxConnectionProvider
*/
private $connectionProvider;
/**
* @var Cache
*/
private $cache;
/**
* @var callable
*/
private $captionFactoryProvider;
public function __construct(DataboxConnectionProvider $connectionProvider, Cache $cache, callable $captionFactoryProvider)
{
$this->connectionProvider = $connectionProvider;
$this->cache = $cache;
$this->captionFactoryProvider = $captionFactoryProvider;
}
public function createRepositoryFor($databoxId)
{
$connection = $this->connectionProvider->getConnection($databoxId);
$dbalRepository = new DbalCaptionDataRepository($connection);
$dataRepository = new CachedCaptionDataRepository($dbalRepository, $this->cache, sprintf('databox[%d]:', $databoxId));
$provider = $this->captionFactoryProvider;
$factory = $provider($databoxId);
if (!is_callable($factory)) {
throw new \UnexpectedValueException(sprintf(
'Caption factory is expected to be callable, got %s',
is_object($factory) ? get_class($factory) : gettype($factory)
));
}
return new CaptionRepository($dataRepository, $factory);
}
}

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Databox\Caption;
use Alchemy\Phrasea\Controller\LazyLocator;
use Alchemy\Phrasea\Databox\ClosureDataboxBoundRepositoryFactory;
use Alchemy\Phrasea\Databox\DataboxBoundRepositoryProvider;
use Alchemy\Phrasea\Databox\DataboxConnectionProvider;
use Alchemy\Phrasea\Record\RecordReference;
@@ -29,13 +30,26 @@ class CaptionServiceProvider implements ServiceProviderInterface
};
});
$app['provider.data_repo.caption'] = $app->share(function (Application $app) {
return new DataboxBoundRepositoryProvider(new CaptionDataRepositoryFactory(
new DataboxConnectionProvider($app['phraseanet.appbox']),
$app['cache']
));
});
$app['provider.repo.caption'] = $app->share(function (Application $app) {
$connectionProvider = new DataboxConnectionProvider($app['phraseanet.appbox']);
$factoryProvider = $app['provider.factory.caption'];
return new DataboxBoundRepositoryProvider(
new ClosureDataboxBoundRepositoryFactory(function ($databoxId) use ($app) {
/** @var CaptionDataRepository $dataRepository */
$dataRepository = $app['provider.data_repo.caption']->getRepositoryForDatabox($databoxId);
$captionFactoryProvider = $app['provider.factory.caption'];
$repositoryFactory = new CaptionRepositoryFactory($connectionProvider, $app['cache'], $factoryProvider);
return new DataboxBoundRepositoryProvider($repositoryFactory);
return new CaptionRepository(
$dataRepository,
$captionFactoryProvider($databoxId)
);
})
);
});
$app['service.caption'] = $app->share(function (Application $app) {
@@ -45,6 +59,6 @@ class CaptionServiceProvider implements ServiceProviderInterface
public function boot(Application $app)
{
$app['dispatcher']->addSubscriber(new CaptionCacheInvalider(new LazyLocator($app, 'provider.repo.caption')));
$app['dispatcher']->addSubscriber(new CaptionCacheInvalider(new LazyLocator($app, 'provider.data_repo.caption')));
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Databox;
class ClosureDataboxBoundRepositoryFactory implements DataboxBoundRepositoryFactory
{
/**
* @var callable
*/
private $factory;
public function __construct(callable $factory)
{
$this->factory = $factory;
}
public function createRepositoryFor($databoxId)
{
$factory = $this->factory;
return $factory($databoxId);
}
}