Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <?php
  2.  
  3. class ArticleIdentification extends Article, Identification
  4. {
  5. }
  6.  
  7.  
  8. class ArticleIdIdentification implements ArticleIdentification
  9. {
  10. function __construct($num)
  11. {}
  12.  
  13. function getIdentKey()
  14. {}
  15.  
  16. }
  17.  
  18.  
  19. class ArticleSlugIdentification implements ArticleIdentification
  20. {
  21. function __construct($str)
  22. {}
  23.  
  24. function getIdentKey()
  25. {}
  26.  
  27. }
  28.  
  29.  
  30. class ArticleNew implements Article
  31. {
  32. function __construct($name, $content, User $author)
  33. {}
  34.  
  35. function getName()
  36. {}
  37.  
  38. function getContent()
  39. {}
  40.  
  41. function getAuthor()
  42. {}
  43. }
  44.  
  45.  
  46.  
  47. class ArticleEntry implements Article
  48. {
  49. function __construct(ArticleIdentification $id, $name, $content, User $author)
  50. {}
  51.  
  52. function getId()
  53. {}
  54.  
  55. function getName()
  56. {}
  57.  
  58. function getContent()
  59. {}
  60.  
  61. function getAuthor()
  62. {}
  63. }
  64.  
  65.  
  66. class ArticleCreateService
  67. {
  68. function __construct(AclReader $acl, ArticleCreatePersistence $articleCreate, Majler $mail)
  69. {}
  70.  
  71.  
  72.  
  73. function doPersist(ArticleNew $article)
  74. {
  75. $acl = $this->acl->read($article->getAuthor());
  76. $acl->assert('create-article');
  77.  
  78. $entry = $this->articleCreate->doPersist($article);
  79.  
  80. $this->mailer->sendMail($entry);
  81. return $entry;
  82. }
  83.  
  84. }
  85.  
  86.  
  87.  
  88. class ArticleCreateDatebase implements ArticleCreatePersistence
  89. {
  90. function __construct(DBContext $db)
  91. {}
  92.  
  93.  
  94.  
  95. function doPersist(ArticleNew $article)
  96. {
  97. $id = $this->db->insert([
  98. 'name' => $article->getName(),
  99. 'content' => $article->getContent(),
  100. 'id_author' => $article->getAuthor()->getId(),
  101. ]);
  102. return new ArticleEntry(new ArticleIdentification($id), $name, $content, $article->getAuthor());
  103. }
  104.  
  105. }
  106.  
  107.  
  108.  
  109. class ArticleRemoveDatebase implements ArticleRemovePersistence
  110. {
  111. function __construct(DBContext $db)
  112. {}
  113.  
  114. function doRemove(Article $article)
  115. {
  116. switch (True) {
  117. case $article instanceof ArticleEntry:
  118. $id = $article->getId();
  119. break;
  120. case $article instanceof ArticleIdentification:
  121. $id = $article;
  122. break;
  123. default:
  124. throw new LogicException('...');
  125. }
  126. $this->fetch($id);
  127. }
  128.  
  129. private function fetch(ArticleIdentification $id)
  130. {
  131. switch (True) {
  132. case $id instanceof ArticleSlugIdentification:
  133. $this->db->delete()->where('slug', $id->getIdentKey());
  134. break;
  135. case $id instanceof ArticleIdIdentification:
  136. $this->db->delete()->where('id', $id->getIdentKey());
  137. break;
  138. default:
  139. throw new LogicException('...');
  140. }
  141. }
  142.  
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement