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.

37 lines
782 B

<?php
namespace core\repositories;
use core\entities\ModuleRecord;
3 years ago
use RuntimeException;
use yii\db\StaleObjectException;
class ModuleRepository
{
public function get($id): ModuleRecord
{
if (!$module = ModuleRecord::findOne($id)) {
throw new NotFoundException('Module is not found.');
}
return $module;
}
public function save(ModuleRecord $module): void
{
if (!$module->save()) {
3 years ago
throw new RuntimeException('Saving error.');
}
}
3 years ago
/**
* @param ModuleRecord $module
* @throws StaleObjectException
*/
public function remove(ModuleRecord $module): void
{
if (!$module->delete()) {
3 years ago
throw new RuntimeException('Removing error.');
}
}
3 years ago
}