Last active
June 6, 2018 11:28
-
-
Save tacoberu/c69c3e5f476b0699937b to your computer and use it in GitHub Desktop.
Jak používám anemický model.
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
<?php | |
class ArticleIdentification extends Article, Identification | |
{ | |
} | |
class ArticleIdIdentification implements ArticleIdentification | |
{ | |
function __construct($num) | |
{} | |
function getIdentKey() | |
{} | |
} | |
class ArticleSlugIdentification implements ArticleIdentification | |
{ | |
function __construct($str) | |
{} | |
function getIdentKey() | |
{} | |
} | |
class ArticleNew implements Article | |
{ | |
function __construct($name, $content, User $author) | |
{} | |
function getName() | |
{} | |
function getContent() | |
{} | |
function getAuthor() | |
{} | |
} | |
class ArticleEntry implements Article | |
{ | |
function __construct(ArticleIdentification $id, $name, $content, User $author) | |
{} | |
function getId() | |
{} | |
function getName() | |
{} | |
function getContent() | |
{} | |
function getAuthor() | |
{} | |
} | |
class ArticleCreateService | |
{ | |
function __construct(AclReader $acl, ArticleCreatePersistence $articleCreate, Majler $mail) | |
{} | |
function doPersist(ArticleNew $article) | |
{ | |
$acl = $this->acl->read($article->getAuthor()); | |
$acl->assert('create-article'); | |
$entry = $this->articleCreate->doPersist($article); | |
$this->mailer->sendMail($entry); | |
return $entry; | |
} | |
} | |
class ArticleCreateDatebase implements ArticleCreatePersistence | |
{ | |
function __construct(DBContext $db) | |
{} | |
function doPersist(ArticleNew $article) | |
{ | |
$id = $this->db->insert([ | |
'name' => $article->getName(), | |
'content' => $article->getContent(), | |
'id_author' => $article->getAuthor()->getId(), | |
]); | |
return new ArticleEntry(new ArticleIdentification($id), $name, $content, $article->getAuthor()); | |
} | |
} | |
class ArticleRemoveDatebase implements ArticleRemovePersistence | |
{ | |
function __construct(DBContext $db) | |
{} | |
function doRemove(Article $article) | |
{ | |
switch (True) { | |
case $article instanceof ArticleEntry: | |
$id = $article->getId(); | |
break; | |
case $article instanceof ArticleIdentification: | |
$id = $article; | |
break; | |
default: | |
throw new LogicException('...'); | |
} | |
$this->fetch($id); | |
} | |
private function fetch(ArticleIdentification $id) | |
{ | |
switch (True) { | |
case $id instanceof ArticleSlugIdentification: | |
$this->db->delete()->where('slug', $id->getIdentKey()); | |
break; | |
case $id instanceof ArticleIdIdentification: | |
$this->db->delete()->where('id', $id->getIdentKey()); | |
break; | |
default: | |
throw new LogicException('...'); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Předělávku najdeš na
https://gist.github.com/kitsaels/0099a2996dbffb730cdb