Completed
Push — master ( f8bd36...f2dc96 )
by Jean-Christophe
01:33
created

ValidationModelParser::parse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace Ubiquity\contents\validation;
4
5
use Ubiquity\orm\parser\Reflexion;
6
use Ubiquity\utils\base\UArray;
7
8
/**
9
 * @author jc
10
 *
11
 */
12
class ValidationModelParser {
13
	
14
	protected $validators=[];
15
	
16
	public function parse($modelClass) {
17
		$instance=new $modelClass();
18
		$properties=Reflexion::getProperties($instance);
19
		foreach ( $properties as $property ) {
20
			$propName=$property->getName();
21
			$annots=Reflexion::getAnnotationsMember($modelClass, $propName, "@validator");
22
			if(sizeof($annots)>0){
23
				$this->validators[$propName]=[];
24
				foreach ($annots as $annotation){
25
					$this->validators[$propName][]=$annotation->getPropertiesAndValues();
26
				}
27
			}
28
		}
29
30
	}
31
	
32
	public function getValidators(){
33
		return $this->validators;
34
	}
35
	
36
	public function __toString() {
37
		return "return " . UArray::asPhpArray($this->validators, "array") . ";";
38
	}
39
}
40
41