| 1 | <?php |
||
| 5 | class BaseAnnotation extends \Annotation { |
||
| 6 | |||
| 7 | public function getProperties(){ |
||
| 8 | $reflect = new \ReflectionClass($this); |
||
| 9 | $props = $reflect->getProperties(); |
||
| 10 | return $props; |
||
| 11 | } |
||
| 12 | |||
| 13 | public function getPropertiesAndValues($props=NULL){ |
||
| 14 | $ret=array(); |
||
| 15 | if(is_null($props)) |
||
| 16 | $props=$this->getProperties($this); |
||
| 17 | foreach ($props as $prop){ |
||
| 18 | $prop->setAccessible(true); |
||
| 19 | $v=$prop->getValue($this); |
||
| 20 | if($v!==null && $v!=="" && isset($v)){ |
||
| 21 | $ret[$prop->getName()]=$v; |
||
| 22 | } |
||
| 23 | } |
||
| 24 | return $ret; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function __toString(){ |
||
| 28 | $fields=$this->getPropertiesAndValues(); |
||
| 29 | $exts=array(); |
||
| 30 | $extsStr=""; |
||
| 31 | foreach ($fields as $k=>$v){ |
||
| 32 | if(\is_bool($v)===true){ |
||
| 33 | $exts[]=$k."=".StrUtils::getBooleanStr($v); |
||
| 34 | }else{ |
||
| 35 | $exts[]=$k."=\"".$v."\""; |
||
| 36 | } |
||
| 37 | } |
||
| 38 | if(\sizeof($exts)>0){ |
||
| 39 | $extsStr="(".\implode(",", $exts).")"; |
||
| 40 | } |
||
| 41 | |||
| 42 | return "@".get_class($this).$extsStr; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |