1
|
|
|
<?php namespace Arcanedev\Currencies\Validators; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Currencies\Contracts\CurrencyManager; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class CurrencyValidator |
7
|
|
|
* |
8
|
|
|
* @package Arcanedev\Currencies\Validators |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class CurrencyValidator |
12
|
|
|
{ |
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
14
|
|
|
| Properties |
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
16
|
|
|
*/ |
17
|
|
|
/** @var \Arcanedev\Currencies\Contracts\CurrencyManager */ |
18
|
|
|
protected $manager; |
19
|
|
|
|
20
|
|
|
/* ------------------------------------------------------------------------------------------------ |
21
|
|
|
| Constructor |
22
|
|
|
| ------------------------------------------------------------------------------------------------ |
23
|
|
|
*/ |
24
|
|
|
/** |
25
|
|
|
* CurrencyValidator constructor. |
26
|
|
|
* |
27
|
|
|
* @param \Arcanedev\Currencies\Contracts\CurrencyManager $manager |
28
|
|
|
*/ |
29
|
|
|
public function __construct(CurrencyManager $manager) |
30
|
|
|
{ |
31
|
|
|
$this->manager = $manager; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/* ------------------------------------------------------------------------------------------------ |
35
|
|
|
| Main Functions |
36
|
|
|
| ------------------------------------------------------------------------------------------------ |
37
|
|
|
*/ |
38
|
|
|
public function validateCurrencyIso($attribute, $value, $parameters, $validator) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$manager = $this->manager; |
41
|
|
|
|
42
|
|
|
/** @var \Illuminate\Validation\Validator $validator */ |
43
|
|
|
$validator->addReplacer('currency_iso', function($message, $attribute, $rule, $parameters) use ($manager) { |
|
|
|
|
44
|
|
|
return trans("currencies::validation.currency.iso", ['attribute' => $attribute]); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
return in_array($value, $manager->currencies()->keys()->toArray()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param string $attribute |
52
|
|
|
* @param mixed $value |
53
|
|
|
* @param array $parameters |
54
|
|
|
* @param \Illuminate\Validation\Validator $validator |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function validateCurrencySupported($attribute, $value, $parameters, $validator) |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$manager = $this->manager; |
61
|
|
|
|
62
|
|
|
/** @var \Illuminate\Validation\Validator $validator */ |
63
|
|
|
$validator->addReplacer('currency_supported', function($message, $attribute, $rule, $parameters) use ($manager) { |
|
|
|
|
64
|
|
|
return trans("currencies::validation.currency.supported", ['attribute' => $attribute]); |
65
|
|
|
}); |
66
|
|
|
|
67
|
|
|
return in_array($value, $manager->getSupported()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.