Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ValidatorAnnotation.php
Go to the documentation of this file.
1<?php
2
4
6use Ubiquity\utils\base\UArray;
7
23 public $type;
24 public $message;
25 public $severity;
26 public $group;
27 public $constraints = [ ];
28
32 public function initAnnotation(array $properties) {
33 if (isset ( $properties [0] )) {
34 $this->type = $properties [0];
35 unset ( $properties [0] );
36 if (isset ( $properties [1] )) {
37 if (! is_array ( $properties [1] )) {
38 $this->constraints = [ 'ref' => $properties [1] ];
39 } else {
40 $this->constraints = $properties [1];
41 }
42 unset ( $properties [1] );
43 }
44 }
45 parent::initAnnotation ( $properties );
46 if(!isset($this->type)){
47 throw new \Exception ( 'Validator annotation must have a type' );
48 }
49 if (! isset ( ValidatorsManager::$validatorTypes [$this->type] )) {
50 throw new \Exception ( 'This type of annotation does not exists : ' . $this->type );
51 }
52 }
53
54 public function asAnnotation() {
55 $fields = $this->getPropertiesAndValues ();
56 $result = [ ];
57 $result [] = $fields ['type'];
58 unset ( $fields ['type'] );
59 if (isset ( $fields ['constraints'] ) && isset ( $fields ['constraints'] ['ref'] )) {
60 $result [] = $fields ['constraints'] ['ref'];
61 unset ( $fields ['constraints'] ['ref'] );
62 }
63 if (sizeof ( $fields ) > 0) {
64 foreach ( $fields as $field => $value ) {
65 if ((\is_array ( $value ) && \count ( $value ) > 0) || ! \is_array ( $value )) {
66 $result [$field] = $value;
67 }
68 }
69 }
70 return UArray::asPhpArray ( $result );
71 }
72}
initAnnotation(array $properties)
Initialize the annotation.