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.
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace core\repositories;
|
|
|
|
|
|
|
|
use core\entities\ModuleRecord;
|
|
|
|
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()) {
|
|
|
|
throw new RuntimeException('Saving error.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param ModuleRecord $module
|
|
|
|
* @throws StaleObjectException
|
|
|
|
*/
|
|
|
|
public function remove(ModuleRecord $module): void
|
|
|
|
{
|
|
|
|
if (!$module->delete()) {
|
|
|
|
throw new RuntimeException('Removing error.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|