You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
834 B

7 years ago
<?php
namespace common\modules\pages\repositories;
7 years ago
use common\modules\pages\entities\Page;
7 years ago
use core\repositories\NotFoundException;
3 years ago
use RuntimeException;
use yii\db\StaleObjectException;
7 years ago
class PageRepository
{
public function get($id): Page
{
if (!$page = Page::find()->with('translations')->andWhere(['id' => $id])->one()) {
7 years ago
throw new NotFoundException('Page is not found.');
}
return $page;
}
public function save(Page $page): void
{
if (!$page->save()) {
3 years ago
throw new RuntimeException('Saving error.');
7 years ago
}
}
3 years ago
/**
* @param Page $page
* @throws StaleObjectException
*/
7 years ago
public function remove(Page $page): void
{
if (!$page->delete()) {
3 years ago
throw new RuntimeException('Removing error.');
7 years ago
}
}
3 years ago
}