Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.64 KB | None | 0 0
  1. <?php
  2.  
  3. use shop\entities\Page;
  4.  
  5. class PageRepository
  6. {
  7.     public function get($id): Page
  8.     {
  9.         if (!$page = Page::findOne($id)) {
  10.             throw new NotFoundException('Страница не найдена.');
  11.         }
  12.         return $page;
  13.     }
  14.  
  15.     public function save(Page $page): void
  16.     {
  17.         if (!$page->save()) {
  18.             throw new \RuntimeException('Ошибка при сохранении.');
  19.         }
  20.     }
  21.  
  22.     public function remove(Page $page): void
  23.     {
  24.         if (!$page->delete()) {
  25.             throw new \RuntimeException('Ошибка при удалении.');
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement