Skip to content

Commit

Permalink
Add ArticleRepository and ArticleController getAction
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Dec 3, 2022
1 parent d7b691b commit 6b08021
Show file tree
Hide file tree
Showing 36 changed files with 2,262 additions and 74 deletions.
49 changes: 49 additions & 0 deletions Application/Mapper/ArticleContentMapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Mapper;

use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;
use Sulu\Bundle\ContentBundle\Content\Application\ContentPersister\ContentPersisterInterface;
use Webmozart\Assert\Assert;

/**
* @experimental
*
* @internal This class should be instantiated inside a project.
* Use the message to create or modify an article.
* Or the inject all the mappers into a custom service.
* Create an own Mapper to extend the mapper with
* custom logic.
*/
final class ArticleContentMapper implements ArticleMapperInterface
{
/**
* @var ContentPersisterInterface
*/
private $contentPersister;

public function __construct(ContentPersisterInterface $contentPersister)
{
$this->contentPersister = $contentPersister;
}

public function mapArticleData(ArticleInterface $article, array $data): void
{
$locale = $data['locale'] ?? null;
Assert::string($locale);

$dimensionAttributes = ['locale' => $locale];

// TODO this will be changed to `$article`, `$dimensionAttributes`, `$data`
$this->contentPersister->persist($article, $data, $dimensionAttributes);
}
}
25 changes: 25 additions & 0 deletions Application/Mapper/ArticleMapperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Mapper;

use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;

/**
* @experimental
*/
interface ArticleMapperInterface
{
/**
* @param mixed[] $data
*/
public function mapArticleData(ArticleInterface $article, array $data): void;
}
64 changes: 64 additions & 0 deletions Application/Message/ApplyWorkflowTransitionArticleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Message;

class ApplyWorkflowTransitionArticleMessage
{
/**
* @param array{
* uuid?: string
* } $identifier
*/
private $identifier;

/**
* @var string
*/
private $locale;

/**
* @var string
*/
private $transitionName;

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function __construct(array $identifier, string $locale, string $transitionName)
{
$this->identifier = $identifier;
$this->locale = $locale;
$this->transitionName = $transitionName;
}

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function getIdentifier(): array
{
return $this->identifier;
}

public function getLocale(): string
{
return $this->locale;
}

public function getTransitionName(): string
{
return $this->transitionName;
}
}
55 changes: 55 additions & 0 deletions Application/Message/CopyLocaleArticleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Sulu\Bundle\ArticleBundle\Application\Message;

class CopyLocaleArticleMessage
{
/**
* @param array{
* uuid?: string
* } $identifier
*/
private $identifier;

/**
* @var string
*/
private $sourceLocale;

/**
* @var string
*/
private $targetLocale;

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function __construct($identifier, string $sourceLocale, string $targetLocale)
{
$this->identifier = $identifier;
$this->sourceLocale = $sourceLocale;
$this->targetLocale = $targetLocale;
}

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function getIdentifier()
{
return $this->identifier;
}

public function getSourceLocale(): string
{
return $this->sourceLocale;
}

public function getTargetLocale(): string
{
return $this->targetLocale;
}
}
44 changes: 44 additions & 0 deletions Application/Message/CreateArticleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Message;

use Webmozart\Assert\Assert;

/**
* @experimental
*/
class CreateArticleMessage
{
/**
* @var mixed[]
*/
private $data;

/**
* @param mixed[] $data
*/
public function __construct(array $data)
{
Assert::string($data['locale'] ?? null, 'Expected a "locale" string given.');
Assert::nullOrString($data['uuid'] ?? null, 'Expected "uuid" to be a string.');

$this->data = $data;
}

/**
* @return mixed[]
*/
public function getData(): array
{
return $this->data;
}
}
64 changes: 64 additions & 0 deletions Application/Message/ModifyArticleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Message;

use Webmozart\Assert\Assert;

/**
* @experimental
*/
class ModifyArticleMessage
{
/**
* @param array{
* uuid?: string
* } $identifier
*/
private $identifier;

/**
* @var mixed[]
*/
private $data;

/**
* @param array{
* uuid?: string
* } $identifier
* @param mixed[] $data
*/
public function __construct(array $identifier, array $data)
{
Assert::string($data['locale'] ?? null, 'Expected a "locale" string given.');

$this->identifier = $identifier;
$this->data = $data;
}

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function getIdentifier(): array
{
return $this->identifier;
}

/**
* @var mixed[]
*/
public function getData(): array
{
return $this->data;
}
}
45 changes: 45 additions & 0 deletions Application/Message/RemoveArticleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Application\Message;

/**
* @experimental
*/
class RemoveArticleMessage
{
/**
* @param array{
* uuid?: string
* } $identifier
*/
private $identifier;

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function __construct(array $identifier)
{
$this->identifier = $identifier;
}

/**
* @param array{
* uuid?: string
* } $identifier
*/
public function getIdentifier(): array
{
return $this->identifier;
}
}
Loading

0 comments on commit 6b08021

Please sign in to comment.