@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public static function register(Container $di, bool $bForce = false) |
| 87 | 87 | { |
| 88 | - if(!$bForce && $di->h(AnnotationReader::class)) |
|
| 88 | + if (!$bForce && $di->h(AnnotationReader::class)) |
|
| 89 | 89 | { |
| 90 | 90 | return; |
| 91 | 91 | } |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | }); |
| 130 | 130 | |
| 131 | 131 | $aAttributes = []; |
| 132 | - foreach($aAnnotations as $xAnnotation) |
|
| 132 | + foreach ($aAnnotations as $xAnnotation) |
|
| 133 | 133 | { |
| 134 | 134 | $xAnnotation->setReader($this); |
| 135 | 135 | $sName = $xAnnotation->getName(); |
| 136 | 136 | $xAnnotation->setPrevValue($aAttributes[$sName] ?? null); |
| 137 | 137 | $xValue = $xAnnotation->getValue(); |
| 138 | - if($sName === 'protected' && !$xValue) |
|
| 138 | + if ($sName === 'protected' && !$xValue) |
|
| 139 | 139 | { |
| 140 | 140 | continue; // Ignore annotation @exclude with value false |
| 141 | 141 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | // Only keep the annotations declared in this package. |
| 157 | 157 | $aAnnotations = array_filter($aAnnotations, function($xAnnotation) use($sProperty) { |
| 158 | 158 | // Save the property type |
| 159 | - if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 159 | + if (is_a($xAnnotation, VarAnnotation::class)) |
|
| 160 | 160 | { |
| 161 | 161 | $this->aPropTypes[$sProperty] = $xAnnotation->type; |
| 162 | 162 | } |
@@ -165,11 +165,11 @@ discard block |
||
| 165 | 165 | }); |
| 166 | 166 | |
| 167 | 167 | $nCount = count($aAnnotations); |
| 168 | - if($nCount === 0) |
|
| 168 | + if ($nCount === 0) |
|
| 169 | 169 | { |
| 170 | 170 | return ['', null]; |
| 171 | 171 | } |
| 172 | - if($nCount > 1) |
|
| 172 | + if ($nCount > 1) |
|
| 173 | 173 | { |
| 174 | 174 | throw new AnnotationException('Only one @di annotation is allowed on a property'); |
| 175 | 175 | } |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | $this->aPropTypes = []; |
| 201 | 201 | $aPropAttrs = []; |
| 202 | 202 | // Properties annotations |
| 203 | - foreach($aProperties as $sProperty) |
|
| 203 | + foreach ($aProperties as $sProperty) |
|
| 204 | 204 | { |
| 205 | 205 | [$sName, $xValue] = $this->propAnnotations($sProperty, $this->xManager->getPropertyAnnotations($sClass, $sProperty)); |
| 206 | - if(!$xValue) |
|
| 206 | + if (!$xValue) |
|
| 207 | 207 | { |
| 208 | 208 | continue; |
| 209 | 209 | } |
@@ -214,19 +214,19 @@ discard block |
||
| 214 | 214 | $this->sMemberType = AnnotationManager::MEMBER_CLASS; |
| 215 | 215 | |
| 216 | 216 | $aClassAttrs = $this->filterAnnotations($this->xManager->getClassAnnotations($sClass)); |
| 217 | - if(isset($aClassAttrs['protected'])) |
|
| 217 | + if (isset($aClassAttrs['protected'])) |
|
| 218 | 218 | { |
| 219 | 219 | return [true, [], []]; // The entire class is not to be exported. |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | // Merge attributes and class annotations |
| 223 | - foreach($aPropAttrs as $sName => $xValue) |
|
| 223 | + foreach ($aPropAttrs as $sName => $xValue) |
|
| 224 | 224 | { |
| 225 | 225 | $aClassAttrs[$sName] = array_merge($aClassAttrs[$sName] ?? [], $xValue); |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $aAttributes = []; |
| 229 | - if(count($aClassAttrs) > 0) |
|
| 229 | + if (count($aClassAttrs) > 0) |
|
| 230 | 230 | { |
| 231 | 231 | $aAttributes['*'] = $aClassAttrs; |
| 232 | 232 | } |
@@ -235,21 +235,21 @@ discard block |
||
| 235 | 235 | $this->sMemberType = AnnotationManager::MEMBER_METHOD; |
| 236 | 236 | |
| 237 | 237 | $aProtected = []; |
| 238 | - foreach($aMethods as $sMethod) |
|
| 238 | + foreach ($aMethods as $sMethod) |
|
| 239 | 239 | { |
| 240 | 240 | $aMethodAttrs = $this->filterAnnotations($this->xManager->getMethodAnnotations($sClass, $sMethod)); |
| 241 | - if(isset($aMethodAttrs['protected'])) |
|
| 241 | + if (isset($aMethodAttrs['protected'])) |
|
| 242 | 242 | { |
| 243 | 243 | $aProtected[] = $sMethod; // The method is not to be exported. |
| 244 | 244 | } |
| 245 | - elseif(count($aMethodAttrs) > 0) |
|
| 245 | + elseif (count($aMethodAttrs) > 0) |
|
| 246 | 246 | { |
| 247 | 247 | $aAttributes[$sMethod] = $aMethodAttrs; |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | return [false, $aAttributes, $aProtected]; |
| 251 | 251 | } |
| 252 | - catch(AnnotationException $e) |
|
| 252 | + catch (AnnotationException $e) |
|
| 253 | 253 | { |
| 254 | 254 | throw new SetupException($e->getMessage()); |
| 255 | 255 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | private function getFullClassName(string $sClassName): string |
| 136 | 136 | { |
| 137 | - return ltrim($this->xClassFile->resolveType($sClassName), '\\');; |
|
| 137 | + return ltrim($this->xClassFile->resolveType($sClassName), '\\'); ; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -146,38 +146,38 @@ discard block |
||
| 146 | 146 | $value = $this->properties['__value__']; |
| 147 | 147 | $aParams = preg_split("/[\s]+/", $value, 3); |
| 148 | 148 | $nParamCount = count($aParams); |
| 149 | - if($nParamCount === 1) |
|
| 149 | + if ($nParamCount === 1) |
|
| 150 | 150 | { |
| 151 | 151 | // For a property, the only parameter is the class. Otherwise, it is the attribute. |
| 152 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 152 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 153 | 153 | { |
| 154 | - if(substr($aParams[0], 0, 1) === '$') |
|
| 154 | + if (substr($aParams[0], 0, 1) === '$') |
|
| 155 | 155 | { |
| 156 | 156 | throw new AnnotationException('The only property of the @di annotation must be a class name'); |
| 157 | 157 | } |
| 158 | 158 | $this->sClass = $this->getFullClassName($aParams[0]); |
| 159 | 159 | return; |
| 160 | 160 | } |
| 161 | - if(substr($aParams[0], 0, 1) !== '$') |
|
| 161 | + if (substr($aParams[0], 0, 1) !== '$') |
|
| 162 | 162 | { |
| 163 | 163 | throw new AnnotationException('The only property of the @di annotation must be a var name'); |
| 164 | 164 | } |
| 165 | 165 | $this->sAttr = substr($aParams[0], 1); |
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | - if($nParamCount === 2) |
|
| 168 | + if ($nParamCount === 2) |
|
| 169 | 169 | { |
| 170 | 170 | // For a property, having 2 parameters is not allowed. |
| 171 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 171 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 172 | 172 | { |
| 173 | 173 | throw new AnnotationException('The @di annotation accepts only one property on a class attribute'); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if(substr($aParams[0], 0, 1) !== '$') |
|
| 176 | + if (substr($aParams[0], 0, 1) !== '$') |
|
| 177 | 177 | { |
| 178 | 178 | throw new AnnotationException('The only property of the @di annotation must be a var name'); |
| 179 | 179 | } |
| 180 | - if(substr($aParams[1], 0, 1) === '$') |
|
| 180 | + if (substr($aParams[1], 0, 1) === '$') |
|
| 181 | 181 | { |
| 182 | 182 | throw new AnnotationException('The first property of the @di annotation must be a class name'); |
| 183 | 183 | } |
@@ -196,28 +196,28 @@ discard block |
||
| 196 | 196 | private function parseProperties() |
| 197 | 197 | { |
| 198 | 198 | $nCount = count($this->properties); |
| 199 | - if($nCount > 2 || |
|
| 199 | + if ($nCount > 2 || |
|
| 200 | 200 | ($nCount === 2 && !(isset($this->properties['attr']) && isset($this->properties['class']))) || |
| 201 | 201 | ($nCount === 1 && !(isset($this->properties['attr']) || isset($this->properties['class'])))) |
| 202 | 202 | { |
| 203 | 203 | throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if(isset($this->properties['attr'])) |
|
| 206 | + if (isset($this->properties['attr'])) |
|
| 207 | 207 | { |
| 208 | - if($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 208 | + if ($this->xReader->getMemberType() === AnnotationManager::MEMBER_PROPERTY) |
|
| 209 | 209 | { |
| 210 | 210 | throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
| 211 | 211 | } |
| 212 | - if(!is_string($this->properties['attr'])) |
|
| 212 | + if (!is_string($this->properties['attr'])) |
|
| 213 | 213 | { |
| 214 | 214 | throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
| 215 | 215 | } |
| 216 | 216 | $this->sAttr = $this->properties['attr']; |
| 217 | 217 | } |
| 218 | - if(isset($this->properties['class'])) |
|
| 218 | + if (isset($this->properties['class'])) |
|
| 219 | 219 | { |
| 220 | - if(!is_string($this->properties['class'])) |
|
| 220 | + if (!is_string($this->properties['class'])) |
|
| 221 | 221 | { |
| 222 | 222 | throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
| 223 | 223 | } |
@@ -235,21 +235,21 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | // The type in the @di annotations can be set from the values in the @var annotations |
| 237 | 237 | $aPropTypes = $this->xReader->getPropTypes(); |
| 238 | - if($this->sClass === '' && isset($aPropTypes[$this->sAttr])) |
|
| 238 | + if ($this->sClass === '' && isset($aPropTypes[$this->sAttr])) |
|
| 239 | 239 | { |
| 240 | 240 | $this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - if(!$this->validateAttrName($this->sAttr)) |
|
| 243 | + if (!$this->validateAttrName($this->sAttr)) |
|
| 244 | 244 | { |
| 245 | 245 | throw new AnnotationException($this->sAttr . ' is not a valid "attr" value for the @di annotation'); |
| 246 | 246 | } |
| 247 | - if(!$this->validateClassName($this->sClass)) |
|
| 247 | + if (!$this->validateClassName($this->sClass)) |
|
| 248 | 248 | { |
| 249 | 249 | throw new AnnotationException($this->sClass . ' is not a valid "class" value for the @di annotation'); |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - if(is_array($this->xPrevValue)) |
|
| 252 | + if (is_array($this->xPrevValue)) |
|
| 253 | 253 | { |
| 254 | 254 | $this->xPrevValue[$this->sAttr] = $this->sClass; // Append the current value to the array |
| 255 | 255 | return $this->xPrevValue; |