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
849 B

6 years ago
<?php
namespace core\repositories;
use core\entities\Settings;
3 years ago
use RuntimeException;
use yii\db\StaleObjectException;
6 years ago
class SettingsRepository
{
public function get($section, $key): Settings
6 years ago
{
if (!$settings = Settings::find()->andWhere(['section' => $section])->andWhere(['key' => $key])->one()) {
6 years ago
throw new NotFoundException('Setting is not found.');
}
return $settings;
}
public function save(Settings $settings): void
{
if (!$settings->save()) {
3 years ago
throw new RuntimeException('Saving error.');
6 years ago
}
}
3 years ago
/**
* @param Settings $settings
* @throws StaleObjectException
*/
6 years ago
public function remove(Settings $settings): void
{
if (!$settings->delete()) {
3 years ago
throw new RuntimeException('Removing error.');
6 years ago
}
}
}