-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from jaljo/feat/publish
Feat/publish
- Loading branch information
Showing
11 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace App\Domain\Command\Handler; | ||
|
||
use App\Domain\Model\Article; | ||
use App\Domain\Command\PublishArticle as PublishArticleCommand; | ||
use App\Domain\Exception\ResourceNotFoundException; | ||
use App\Domain\Repository\ArticleRepository; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
|
||
class PublishArticle | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $manager; | ||
|
||
/** | ||
* @var ArticleRepository | ||
*/ | ||
private $repository; | ||
|
||
public function __construct( | ||
ObjectManager $manager, | ||
ArticleRepository $repository | ||
) { | ||
$this->manager = $manager; | ||
$this->repository = $repository; | ||
} | ||
|
||
/** | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function __invoke(PublishArticleCommand $command): Article | ||
{ | ||
$article = $this->repository->find($command->getId()); | ||
|
||
if (null === $article) { | ||
throw new ResourceNotFoundException(); | ||
} | ||
|
||
$article->publish(); | ||
|
||
$this->manager->persist($article); | ||
$this->manager->flush(); | ||
|
||
return $article; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace App\Domain\Command; | ||
|
||
class PublishArticle | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $id; | ||
|
||
public function __construct(int $id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Domain\Exception; | ||
|
||
use Exception; | ||
|
||
class ResourceNotFoundException extends Exception | ||
{ | ||
protected $message = 'Resource not found.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters