Passed
Push — master ( 64da0c...c6d718 )
by Jean-Christophe
11:31
created

ValidatorsManagerInitTrait::initModelsValidators()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
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
	 * @param array $databaseOffset
21
	 */
22
	public static function initModelsValidators(&$config,$databaseOffset='default') {
23
		$models = CacheManager::getModels ( $config, true ,$databaseOffset);
24
		foreach ( $models as $model ) {
25
			self::initClassValidators ( $model );
26
		}
27
	}
28
29
	/**
30
	 *
31
	 * Parses a class and save validators in cache
32
	 * to use in dev only
33
	 *
34
	 * @param string $class
35
	 */
36 8
	public static function initClassValidators($class) {
37 8
		$parser = new ValidationModelParser ();
38 8
		$parser->parse ( $class );
39 8
		$validators = $parser->getValidators ();
40 8
		if (sizeof ( $validators ) > 0) {
41 8
			self::store ( $class, $parser->__toString () );
42
		}
43 8
	}
44
45
	/**
46
	 * Parses a class and save validators in cache
47
	 *
48
	 * @param string $class
49
	 */
50 3
	public static function addClassValidators($class) {
51 3
		$config = Startup::getConfig ();
52 3
		CacheManager::start ( $config );
53 3
		self::initClassValidators ( $class );
54 3
	}
55
56
	/**
57
	 * Registers a validator type for using with @validator annotation
58
	 *
59
	 * @param string $type
60
	 * @param string $validatorClass
61
	 */
62
	public static function registerType($type, $validatorClass) {
63
		self::$validatorTypes [$type] = $validatorClass;
64
	}
65
}
66
67