mirror of
https://github.com/elyby/accounts.git
synced 2024-12-11 16:09:25 +05:30
8906370bb9
Подкорректирован errorDict на фронте
40 lines
897 B
PHP
40 lines
897 B
PHP
<?php
|
|
namespace common\validators;
|
|
|
|
use common\helpers\Error as E;
|
|
use Yii;
|
|
use yii\validators\Validator;
|
|
|
|
class LanguageValidator extends Validator {
|
|
|
|
public $message = E::UNSUPPORTED_LANGUAGE;
|
|
|
|
protected function validateValue($value) {
|
|
if (empty($value)) {
|
|
return null;
|
|
}
|
|
|
|
$files = $this->getFilesNames();
|
|
if (in_array($value, $files)) {
|
|
return null;
|
|
}
|
|
|
|
return [$this->message, []];
|
|
}
|
|
|
|
protected function getFilesNames() {
|
|
$files = array_values(array_filter(scandir($this->getFolderPath()), function(&$value) {
|
|
return $value !== '..' && $value !== '.';
|
|
}));
|
|
|
|
return array_map(function($value) {
|
|
return basename($value, '.json');
|
|
}, $files);
|
|
}
|
|
|
|
protected function getFolderPath() {
|
|
return Yii::getAlias('@frontend/src/i18n');
|
|
}
|
|
|
|
}
|