Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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('...');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement