1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ubiquity\contents\validation\traits; |
4
|
|
|
|
5
|
|
|
use Ubiquity\cache\CacheManager; |
6
|
|
|
use Ubiquity\controllers\Startup; |
7
|
|
|
use Ubiquity\contents\validation\ValidationModelParser; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* |
11
|
|
|
* @author jcheron <[email protected]> |
12
|
|
|
* @property array $validatorTypes |
13
|
|
|
*/ |
14
|
|
|
trait ValidatorsManagerInitTrait { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Parses models and save validators in cache |
18
|
|
|
* to use in dev only |
19
|
|
|
* |
20
|
|
|
* @param array $config |
21
|
|
|
* @param array $databaseOffset |
22
|
|
|
*/ |
23
|
|
|
public static function initModelsValidators(&$config, $databaseOffset = 'default') { |
24
|
|
|
$models = CacheManager::getModels ( $config, true, $databaseOffset ); |
25
|
|
|
foreach ( $models as $model ) { |
26
|
|
|
self::initClassValidators ( $model ); |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* Parses a class and save validators in cache |
33
|
|
|
* to use in dev only |
34
|
|
|
* |
35
|
|
|
* @param string $class |
36
|
|
|
*/ |
37
|
32 |
|
public static function initClassValidators($class) { |
38
|
32 |
|
$parser = new ValidationModelParser(); |
39
|
32 |
|
$parser->parse ( $class ); |
40
|
32 |
|
$validators = $parser->getValidators (); |
41
|
32 |
|
if (\count ( $validators ) > 0) { |
42
|
|
|
self::store ( $class, $validators ); |
43
|
|
|
} |
44
|
32 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Parses a class and save validators in cache |
48
|
|
|
* |
49
|
|
|
* @param string $class |
50
|
|
|
*/ |
51
|
1 |
|
public static function addClassValidators($class) { |
52
|
1 |
|
$config = Startup::getConfig (); |
53
|
1 |
|
CacheManager::start ( $config ); |
54
|
1 |
|
self::initClassValidators ( $class ); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Registers a validator type for using with @validator annotation |
59
|
|
|
* |
60
|
|
|
* @param string $type |
61
|
|
|
* @param string $validatorClass |
62
|
|
|
*/ |
63
|
|
|
public static function registerType($type, $validatorClass) { |
64
|
|
|
self::$validatorTypes [$type] = $validatorClass; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|