mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	
		
			
				
	
	
		
			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');
 | 
						|
    }
 | 
						|
 | 
						|
}
 |