Skip to content

Commit

Permalink
Rename ContentDimensionInterface to DimensionContentInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Dec 13, 2019
1 parent f0f66a0 commit 4f3f209
Show file tree
Hide file tree
Showing 59 changed files with 810 additions and 815 deletions.
6 changes: 3 additions & 3 deletions Content/Application/ContentCopier/ContentCopier.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sulu\Bundle\ContentBundle\Content\Application\ContentPersister\ContentPersisterInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ViewResolver\ApiViewResolverInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ViewFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentViewInterface;

Expand Down Expand Up @@ -67,11 +67,11 @@ public function copy(
}

public function copyFromContentDimensionCollection(
ContentDimensionCollectionInterface $contentDimensionCollection,
DimensionContentCollectionInterface $dimensionContentCollection,
ContentRichEntityInterface $targetContentRichEntity,
array $targetDimensionAttributes
): ContentViewInterface {
$sourceContentView = $this->viewFactory->create($contentDimensionCollection);
$sourceContentView = $this->viewFactory->create($dimensionContentCollection);

return $this->copyFromContentView($sourceContentView, $targetContentRichEntity, $targetDimensionAttributes);
}
Expand Down
4 changes: 2 additions & 2 deletions Content/Application/ContentCopier/ContentCopierInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentCopier;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentViewInterface;

Expand All @@ -34,7 +34,7 @@ public function copy(
* @param mixed[] $targetDimensionAttributes
*/
public function copyFromContentDimensionCollection(
ContentDimensionCollectionInterface $contentDimensionCollection,
DimensionContentCollectionInterface $dimensionContentCollection,
ContentRichEntityInterface $targetContentRichEntity,
array $targetDimensionAttributes
): ContentViewInterface;
Expand Down
16 changes: 8 additions & 8 deletions Content/Application/ContentLoader/ContentLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ViewFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentViewInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\ContentDimensionRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionRepositoryInterface;

class ContentLoader implements ContentLoaderInterface
Expand All @@ -28,9 +28,9 @@ class ContentLoader implements ContentLoaderInterface
private $dimensionRepository;

/**
* @var ContentDimensionRepositoryInterface
* @var DimensionContentRepositoryInterface
*/
private $contentDimensionRepository;
private $dimensionContentRepository;

/**
* @var ViewFactoryInterface
Expand All @@ -39,11 +39,11 @@ class ContentLoader implements ContentLoaderInterface

public function __construct(
DimensionRepositoryInterface $dimensionRepository,
ContentDimensionRepositoryInterface $contentDimensionRepository,
DimensionContentRepositoryInterface $dimensionContentRepository,
ViewFactoryInterface $viewFactory
) {
$this->dimensionRepository = $dimensionRepository;
$this->contentDimensionRepository = $contentDimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->viewFactory = $viewFactory;
}

Expand All @@ -55,12 +55,12 @@ public function load(ContentRichEntityInterface $contentRichEntity, array $dimen
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

$contentDimensionCollection = $this->contentDimensionRepository->load($contentRichEntity, $dimensionCollection);
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);

if (0 === \count($contentDimensionCollection)) {
if (0 === \count($dimensionContentCollection)) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

return $this->viewFactory->create($contentDimensionCollection);
return $this->viewFactory->create($dimensionContentCollection);
}
}
19 changes: 7 additions & 12 deletions Content/Application/ContentPersister/ContentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentPersister;

use Sulu\Bundle\ContentBundle\Content\Application\ViewResolver\ApiViewResolverInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ContentDimensionCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\DimensionContentCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\DimensionCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ViewFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
Expand All @@ -28,39 +28,34 @@ class ContentPersister implements ContentPersisterInterface
private $dimensionCollectionFactory;

/**
* @var ContentDimensionCollectionFactoryInterface
* @var DimensionContentCollectionFactoryInterface
*/
private $contentDimensionCollectionFactory;
private $dimensionContentCollectionFactory;

/**
* @var ViewFactoryInterface
*/
private $viewFactory;

/**
* @var ApiViewResolverInterface
*/
private $viewResolver;

public function __construct(
DimensionCollectionFactoryInterface $dimensionCollectionFactory,
ContentDimensionCollectionFactoryInterface $contentDimensionCollectionFactory,
DimensionContentCollectionFactoryInterface $dimensionContentCollectionFactory,
ViewFactoryInterface $viewFactory
) {
$this->dimensionCollectionFactory = $dimensionCollectionFactory;
$this->contentDimensionCollectionFactory = $contentDimensionCollectionFactory;
$this->dimensionContentCollectionFactory = $dimensionContentCollectionFactory;
$this->viewFactory = $viewFactory;
}

public function persist(ContentRichEntityInterface $contentRichEntity, array $data, array $dimensionAttributes): ContentViewInterface
{
$dimensionCollection = $this->dimensionCollectionFactory->create($dimensionAttributes);
$contentDimensionCollection = $this->contentDimensionCollectionFactory->create(
$dimensionContentCollection = $this->dimensionContentCollectionFactory->create(
$contentRichEntity,
$dimensionCollection,
$data
);

return $this->viewFactory->create($contentDimensionCollection);
return $this->viewFactory->create($dimensionContentCollection);
}
}
18 changes: 9 additions & 9 deletions Content/Application/ContentWorkflow/ContentWorkflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentViewInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\ContentDimensionRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionRepositoryInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -42,9 +42,9 @@ class ContentWorkflow implements ContentWorkflowInterface
private $dimensionRepository;

/**
* @var ContentDimensionRepositoryInterface
* @var DimensionContentRepositoryInterface
*/
private $contentDimensionRepository;
private $dimensionContentRepository;

/**
* @var ViewFactoryInterface
Expand All @@ -63,13 +63,13 @@ class ContentWorkflow implements ContentWorkflowInterface

public function __construct(
DimensionRepositoryInterface $dimensionRepository,
ContentDimensionRepositoryInterface $contentDimensionRepository,
DimensionContentRepositoryInterface $dimensionContentRepository,
ViewFactoryInterface $viewFactory,
?Registry $workflowRegistry = null,
?EventDispatcherInterface $eventDispatcher = null
) {
$this->dimensionRepository = $dimensionRepository;
$this->contentDimensionRepository = $contentDimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->viewFactory = $viewFactory;
$this->eventDispatcher = $eventDispatcher ?: new EventDispatcher();
// TODO get workflow from outside
Expand All @@ -91,9 +91,9 @@ public function apply(
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
}

$contentDimensionCollection = $this->contentDimensionRepository->load($contentRichEntity, $dimensionCollection);
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);

$localizedContentDimension = $contentDimensionCollection->getLocalizedContentDimension();
$localizedContentDimension = $dimensionContentCollection->getLocalizedDimensionContent();

if (!$localizedContentDimension) {
throw new ContentNotFoundException($contentRichEntity, $dimensionAttributes);
Expand All @@ -111,7 +111,7 @@ public function apply(
try {
$workflow->apply($localizedContentDimension, $transitionName, [
'contentRichEntity' => $contentRichEntity,
'contentDimensionCollection' => $contentDimensionCollection,
'dimensionContentCollection' => $dimensionContentCollection,
'dimensionAttributes' => $dimensionAttributes,
]);
} catch (UndefinedTransitionException $e) {
Expand All @@ -120,7 +120,7 @@ public function apply(
throw new ContentInvalidTransitionException($e->getMessage(), $e->getCode(), $e);
}

return $this->viewFactory->create($contentDimensionCollection);
return $this->viewFactory->create($dimensionContentCollection);
}

private function getWorkflow(): SymfonyWorkflowInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber;

use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -35,24 +35,24 @@ public function __construct(ContentCopierInterface $contentCopier)

public function onPublish(TransitionEvent $transitionEvent): void
{
$contentDimension = $transitionEvent->getSubject();
$dimensionContent = $transitionEvent->getSubject();

if (!$contentDimension instanceof ContentDimensionInterface) {
if (!$dimensionContent instanceof DimensionContentInterface) {
return;
}

$context = $transitionEvent->getContext();

$contentDimensionCollection = $context['contentDimensionCollection'] ?? null;
$dimensionContentCollection = $context['dimensionContentCollection'] ?? null;
$dimensionAttributes = $context['dimensionAttributes'] ?? null;
$contentRichEntity = $context['contentRichEntity'] ?? null;

if (!$dimensionAttributes) {
throw new \RuntimeException('No "dimensionAttributes" given.');
}

if (!$contentDimensionCollection instanceof ContentDimensionCollectionInterface) {
throw new \RuntimeException('No "contentDimensionCollection" given.');
if (!$dimensionContentCollection instanceof DimensionContentCollectionInterface) {
throw new \RuntimeException('No "dimensionContentCollection" given.');
}

if (!$contentRichEntity instanceof ContentRichEntityInterface) {
Expand All @@ -62,7 +62,7 @@ public function onPublish(TransitionEvent $transitionEvent): void
$dimensionAttributes['stage'] = DimensionInterface::STAGE_LIVE;

$this->contentCopier->copyFromContentDimensionCollection(
$contentDimensionCollection,
$dimensionContentCollection,
$contentRichEntity,
$dimensionAttributes
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDimensionFactory;
namespace Sulu\Bundle\ContentBundle\Content\Application\DimensionContentFactory;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Sulu\Bundle\ContentBundle\Content\Application\ContentDimensionFactory\Mapper\MapperInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\ContentDimensionCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionCollection;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Application\DimensionContentFactory\Mapper\MapperInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Factory\DimensionContentCollectionFactoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollection;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionCollectionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\ContentDimensionRepositoryInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface;

class ContentDimensionCollectionFactory implements ContentDimensionCollectionFactoryInterface
class DimensionContentCollectionFactory implements DimensionContentCollectionFactoryInterface
{
/**
* @var ContentDimensionRepositoryInterface
* @var DimensionContentRepositoryInterface
*/
private $contentDimensionRepository;
private $dimensionContentRepository;

/**
* @var iterable<MapperInterface>
Expand All @@ -40,77 +40,77 @@ class ContentDimensionCollectionFactory implements ContentDimensionCollectionFac
/**
* @param iterable<MapperInterface> $mappers
*/
public function __construct(ContentDimensionRepositoryInterface $contentDimensionRepository, iterable $mappers)
public function __construct(DimensionContentRepositoryInterface $dimensionContentRepository, iterable $mappers)
{
$this->contentDimensionRepository = $contentDimensionRepository;
$this->dimensionContentRepository = $dimensionContentRepository;
$this->mappers = $mappers;
}

public function create(
ContentRichEntityInterface $contentRichEntity,
DimensionCollectionInterface $dimensionCollection,
array $data
): ContentDimensionCollectionInterface {
$contentDimensionCollection = $this->contentDimensionRepository->load($contentRichEntity, $dimensionCollection);
): DimensionContentCollectionInterface {
$dimensionContentCollection = $this->dimensionContentRepository->load($contentRichEntity, $dimensionCollection);

$localizedDimension = $dimensionCollection->getLocalizedDimension();
$unlocalizedDimension = $dimensionCollection->getUnlocalizedDimension();

$contentDimensions = new ArrayCollection(iterator_to_array($contentDimensionCollection));
$dimensionContents = new ArrayCollection(iterator_to_array($dimensionContentCollection));

if (!$unlocalizedDimension) {
throw new \RuntimeException('The "$dimensionCollection" should contain atleast a unlocalizedDimension.');
}

$unlocalizedContentDimension = $this->getOrCreateContentDimension(
$contentRichEntity,
$contentDimensions,
$dimensionContents,
$unlocalizedDimension
);

$localizedContentDimension = null;
if ($localizedDimension) {
$localizedContentDimension = $this->getOrCreateContentDimension(
$contentRichEntity,
$contentDimensions,
$dimensionContents,
$localizedDimension
);
}

// Sort correctly ContentDimensions by given dimensionIds to merge them later correctly
$orderedContentDimensions = [];
foreach ($dimensionCollection as $key => $dimension) {
$contentDimension = $contentDimensions->filter(function (ContentDimensionInterface $contentDimension) use ($dimension) {
return $contentDimension->getDimension()->getId() === $dimension->getId();
$dimensionContent = $dimensionContents->filter(function (DimensionContentInterface $dimensionContent) use ($dimension) {
return $dimensionContent->getDimension()->getId() === $dimension->getId();
})->first();

if ($contentDimension) {
$orderedContentDimensions[$key] = $contentDimension;
if ($dimensionContent) {
$orderedContentDimensions[$key] = $dimensionContent;
}
}

foreach ($this->mappers as $mapper) {
$mapper->map($data, $unlocalizedContentDimension, $localizedContentDimension);
}

return new ContentDimensionCollection($orderedContentDimensions, $dimensionCollection);
return new DimensionContentCollection($orderedContentDimensions, $dimensionCollection);
}

private function getOrCreateContentDimension(
ContentRichEntityInterface $contentRichEntity,
Collection $contentDimensions,
Collection $dimensionContents,
DimensionInterface $dimension
): ContentDimensionInterface {
$contentDimension = $contentDimensions->filter(function (ContentDimensionInterface $contentDimension) use ($dimension) {
return $contentDimension->getDimension()->getId() === $dimension->getId();
): DimensionContentInterface {
$dimensionContent = $dimensionContents->filter(function (DimensionContentInterface $dimensionContent) use ($dimension) {
return $dimensionContent->getDimension()->getId() === $dimension->getId();
})->first();

if (!$contentDimension) {
$contentDimension = $contentRichEntity->createDimension($dimension);
$contentRichEntity->addDimension($contentDimension);
$contentDimensions->add($contentDimension);
if (!$dimensionContent) {
$dimensionContent = $contentRichEntity->createDimensionContent($dimension);
$contentRichEntity->addDimensionContent($dimensionContent);
$dimensionContents->add($dimensionContent);
}

return $contentDimension;
return $dimensionContent;
}
}
Loading

0 comments on commit 4f3f209

Please sign in to comment.