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