Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
ClassToYuml.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\utils\yuml;
4
7
18 protected $class;
19 protected $displayProperties = true;
20 protected $displayMethods = false;
21 protected $displayMethodsParams = false;
22 protected $displayPropertiesTypes = false;
25 protected $displayForeignKeys = true;
26 protected $properties;
27 protected $parseResult;
28 protected $note;
29
31 $this->class = $class;
32 $this->displayProperties = $displayProperties;
33 $this->displayAssociations = $displayAssociations;
34 $this->displayMethods = $displayMethods;
35 $this->displayMethodsParams = $displayMethodsParams;
36 $this->displayPropertiesTypes = $displayPropertiesTypes;
37 $this->displayAssociationClassProperties = $displayAssociationClassProperties;
38 }
39
40 public function init($hasManyToOne, $hasOneToMany, $hasManyToMany) {
41 if ($hasManyToOne) {
42 $this->loadManyToOne ();
43 }
44 if ($hasOneToMany) {
45 $this->loadOneToManys ();
46 }
47 if ($hasManyToMany) {
48 $this->loadManyToManys ();
49 }
50 }
51
52 public function parse() {
53 $reflect = new \ReflectionClass ( $this->class );
54 $yumlAnnot = OrmUtils::getAnnotationInfo ( $this->class, "#yuml" );
55 $color = "";
56 if ($yumlAnnot !== false) {
57 if (isset ( $yumlAnnot ["color"] )) {
58 $color = "{bg:" . $yumlAnnot ["color"] . "}";
59 }
60 if (isset ( $yumlAnnot ["note"] )) {
61 $this->note = $yumlAnnot ["note"];
62 }
63 }
64 $parts = [ $reflect->getShortName () ];
65
66 if ($this->displayProperties) {
67 $prikeys = OrmUtils::getKeyMembers ( $this->class );
68 $types = OrmUtils::getFieldTypes ( $this->class );
69 $propertiesArray = [ ];
70 $properties = $reflect->getProperties ();
71 foreach ( $properties as $property ) {
72 $this->parseProperty ( $propertiesArray, $property, $prikeys, $types );
73 }
74 $parts [] = \implode ( Yuml::$memberSeparator, $propertiesArray );
75 }
76
77 if ($this->displayMethods) {
78 $methodsArray = [ ];
79 $methods = $reflect->getMethods ();
80 foreach ( $methods as $method ) {
81 $this->parseMethod ( $methodsArray, $method );
82 }
83 $parts [] = \implode ( Yuml::$memberSeparator, $methodsArray );
84 }
85
86 $result = \implode ( Yuml::$classSeparator, $parts ) . $color;
87 $result = Yuml::setClassContent ( $result );
88 if (isset ( $this->note )) {
89 $result .= $this->_getNote ();
90 }
91 $this->parseResult = $result;
92 return $result;
93 }
94
95 protected function parseProperty(&$propertiesArray, $property, $prikeys, $types) {
96 $propertyName = $property->getName ();
97 $type = "";
98 $isPri = "";
99 if ($this->displayPropertiesTypes) {
100 if (\array_key_exists ( $propertyName, $types )) {
101 $type = Yuml::$parameterTypeSeparator . $types [$propertyName];
102 }
103 }
104 if (\array_search ( $propertyName, $prikeys ) !== false) {
105 $isPri = Yuml::$primary;
106 }
107 $propertiesArray [] = Yuml::setPropertyVariables ( [ $this->getAccess ( $property ),$isPri,$propertyName,$type ] );
108 }
109
110 protected function parseMethod(&$methodsArray, $method) {
111 $parameters = "";
112 if ($this->displayMethodsParams) {
113 $parameters = $this->getMethodParameters ( $method );
114 }
115 $methodName = $method->getName ();
116 $type = "";
117 if ($method->hasReturnType ()) {
118 $type = Yuml::$parameterTypeSeparator . $method->getReturnType ();
119 }
120 $methodsArray [] = Yuml::setMethodVariables ( [ $this->getAccess ( $method ),$methodName,$parameters,$type ] );
121 }
122
123 protected function _getNote() {
124 return "-[note:" . $this->note . "]";
125 }
126
127 protected function getMethodParameters(\ReflectionMethod $method) {
128 $paramsValues = [ ];
129 $parameters = $method->getParameters ();
130 foreach ( $parameters as $parameter ) {
131 $v = $parameter->getName ();
132 if ($parameter->hasType ()) {
133 $v .= Yuml::$parameterTypeSeparator . $parameter->getType ();
134 }
135 $paramsValues [] = $v;
136 }
137 return \implode ( Yuml::$parameterSeparator, $paramsValues );
138 }
139
140 protected function getAccess($property) {
141 $result = Yuml::$private;
142 if ($property->isPublic ()) {
143 $result = Yuml::$public;
144 } elseif ($property->isProtected ()) {
145 $result = Yuml::$protected;
146 }
147 return $result;
148 }
149
150 public function manyToOneTostring() {
151 $this->loadManyToOne ();
152 return \implode ( Yuml::$groupeSeparator, $this->_getYumlManyToOne () );
153 }
154
155 public function oneToManyTostring() {
156 $this->loadOneToManys ();
157 return \implode ( Yuml::$groupeSeparator, $this->_getYumlOneToMany () );
158 }
159
160 public function manyToManyTostring($load = true) {
161 if ($load) {
162 $this->loadManyToManys ();
163 }
164 return \implode ( Yuml::$groupeSeparator, $this->_getYumlManyToMany () );
165 }
166
167 public function __toString() {
168 $result = [ $this->parse () ];
169 if ($this->displayAssociations) {
170 $result = \array_merge ( $result, $this->_getYumlManyToOne () );
171 $result = \array_merge ( $result, $this->_getYumlOneToMany () );
172 $result = \array_merge ( $result, $this->_getYumlManyToMany () );
173 }
174 return \implode ( Yuml::$groupeSeparator, $result );
175 }
176
178 $this->displayProperties = $displayProperties;
179 return $this;
180 }
181
183 $this->displayMethods = $displayMethods;
184 return $this;
185 }
186
188 $this->displayAssociations = $displayAssociations;
189 return $this;
190 }
191}
Object/relational mapping utilities.
Definition OrmUtils.php:17
yuml export tool for class Ubiquity\utils\yuml$ClassToYuml This class is part of Ubiquity
setDisplayProperties($displayProperties)
init($hasManyToOne, $hasOneToMany, $hasManyToMany)
getMethodParameters(\ReflectionMethod $method)
__construct($class, $displayProperties=true, $displayAssociations=true, $displayMethods=false, $displayMethodsParams=false, $displayPropertiesTypes=false, $displayAssociationClassProperties=false)
parseMethod(&$methodsArray, $method)
setDisplayAssociations($displayAssociations)
parseProperty(&$propertiesArray, $property, $prikeys, $types)
static setMethodVariables($values)
Definition Yuml.php:50
static setClassContent($content)
Definition Yuml.php:54
static setPropertyVariables($values)
Definition Yuml.php:46
static $parameterSeparator
Definition Yuml.php:9
static $parameterTypeSeparator
Definition Yuml.php:10
static $memberSeparator
Definition Yuml.php:8
Ubiquity\utils\yuml\traits$ClassToYumlRelationsTrait This class is part of Ubiquity.