mirror of
				https://github.com/elyby/accounts.git
				synced 2025-05-31 14:11:46 +05:30 
			
		
		
		
	
		
			
				
	
	
		
			24 lines
		
	
	
		
			571 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			571 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
namespace common\validators;
 | 
						|
 | 
						|
use InvalidArgumentException;
 | 
						|
use Ramsey\Uuid\Uuid;
 | 
						|
use yii\validators\Validator;
 | 
						|
 | 
						|
class UuidValidator extends Validator {
 | 
						|
 | 
						|
    public $skipOnEmpty = false;
 | 
						|
 | 
						|
    public $message = '{attribute} must be valid uuid';
 | 
						|
 | 
						|
    public function validateAttribute($model, $attribute) {
 | 
						|
        try {
 | 
						|
            $uuid = Uuid::fromString($model->$attribute)->toString();
 | 
						|
            $model->$attribute = $uuid;
 | 
						|
        } catch (InvalidArgumentException $e) {
 | 
						|
            $this->addError($model, $attribute, $this->message, []);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
}
 |