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.

43 lines
950 B

<?php
namespace common\modules\languages\repositories;
use common\modules\languages\entities\Language;
use core\repositories\NotFoundException;
3 years ago
use RuntimeException;
use yii\db\StaleObjectException;
class LanguageRepository
{
public function get($id): Language
{
if (!$language = Language::findOne($id)) {
throw new NotFoundException('Language is not found.');
}
return $language;
}
public function save(Language $language): void
{
if (!$language->save()) {
3 years ago
throw new RuntimeException('Saving error.');
}
}
3 years ago
/**
* @param Language $language
* @throws StaleObjectException
*/
public function remove(Language $language): void
{
if (!$language->delete()) {
3 years ago
throw new RuntimeException('Removing error.');
}
}
public function clearDefaults()
{
Language::updateAll(['default' => 0]);
}
3 years ago
}