@@ -30,7 +30,7 @@ |
||
| 30 | 30 | function register(): void |
| 31 | 31 | { |
| 32 | 32 | // Do nothing if running in cli. |
| 33 | - if(php_sapi_name() !== 'cli') |
|
| 33 | + if (php_sapi_name() !== 'cli') |
|
| 34 | 34 | { |
| 35 | 35 | _register(); |
| 36 | 36 | }; |
@@ -74,20 +74,20 @@ discard block |
||
| 74 | 74 | private function readTypes(ReflectionClass $xClass) |
| 75 | 75 | { |
| 76 | 76 | $sClass = $xClass->getName(); |
| 77 | - if(isset($this->aTypes[$sClass])) |
|
| 77 | + if (isset($this->aTypes[$sClass])) |
|
| 78 | 78 | { |
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | $this->aTypes[$sClass] = []; |
| 83 | - $nFilter = ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED; |
|
| 83 | + $nFilter = ReflectionProperty::IS_PUBLIC|ReflectionProperty::IS_PROTECTED; |
|
| 84 | 84 | $aProperties = $xClass->getProperties($nFilter); |
| 85 | - foreach($aProperties as $xReflectionProperty) |
|
| 85 | + foreach ($aProperties as $xReflectionProperty) |
|
| 86 | 86 | { |
| 87 | 87 | $xType = $xReflectionProperty->getType(); |
| 88 | 88 | $sType = $xType?->getName() ?? ''; |
| 89 | 89 | // Check that the property has a valid type defined |
| 90 | - if($sType !== '' && is_a($xType, ReflectionNamedType::class)) |
|
| 90 | + if ($sType !== '' && is_a($xType, ReflectionNamedType::class)) |
|
| 91 | 91 | { |
| 92 | 92 | $this->aTypes[$sClass][$xReflectionProperty->getName()] = $sType; |
| 93 | 93 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | private function initAttribute(AbstractAttribute $xAttribute, |
| 105 | 105 | ReflectionClass $xClass, ReflectionAttribute $xReflectionAttribute): void |
| 106 | 106 | { |
| 107 | - if(is_a($xAttribute, InjectAttribute::class)) |
|
| 107 | + if (is_a($xAttribute, InjectAttribute::class)) |
|
| 108 | 108 | { |
| 109 | 109 | $this->readTypes($xClass); |
| 110 | 110 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $aClassAttributes = $xClass->getAttributes(); |
| 125 | 125 | $aAttributes = array_filter($aClassAttributes, fn($xAttribute) => |
| 126 | 126 | is_a($xAttribute->getName(), ExcludeAttribute::class, true)); |
| 127 | - foreach($aAttributes as $xReflectionAttribute) |
|
| 127 | + foreach ($aAttributes as $xReflectionAttribute) |
|
| 128 | 128 | { |
| 129 | 129 | $xReflectionAttribute->newInstance()->saveValue($this->xMetadata); |
| 130 | 130 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $aAttributes = array_filter($aClassAttributes, fn($xAttribute) => |
| 142 | 142 | is_a($xAttribute->getName(), AbstractAttribute::class, true) && |
| 143 | 143 | !is_a($xAttribute->getName(), ExcludeAttribute::class, true)); |
| 144 | - foreach($aAttributes as $xReflectionAttribute) |
|
| 144 | + foreach ($aAttributes as $xReflectionAttribute) |
|
| 145 | 145 | { |
| 146 | 146 | $xAttribute = $xReflectionAttribute->newInstance(); |
| 147 | 147 | $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute); |
@@ -160,16 +160,15 @@ discard block |
||
| 160 | 160 | private function getPropertyAttrs(ReflectionClass $xClass, string $sProperty): void |
| 161 | 161 | { |
| 162 | 162 | // Only Inject attributes are allowed on properties |
| 163 | - $aAttributes = !$xClass->hasProperty($sProperty) ? [] : |
|
| 164 | - $xClass->getProperty($sProperty)->getAttributes(); |
|
| 163 | + $aAttributes = !$xClass->hasProperty($sProperty) ? [] : $xClass->getProperty($sProperty)->getAttributes(); |
|
| 165 | 164 | $aAttributes = array_filter($aAttributes, fn($xAttribute) => |
| 166 | 165 | is_a($xAttribute->getName(), InjectAttribute::class, true)); |
| 167 | - if(count($aAttributes) > 1) |
|
| 166 | + if (count($aAttributes) > 1) |
|
| 168 | 167 | { |
| 169 | 168 | throw new SetupException('Only one Inject attribute is allowed on a property'); |
| 170 | 169 | } |
| 171 | 170 | |
| 172 | - foreach($aAttributes as $xReflectionAttribute) |
|
| 171 | + foreach ($aAttributes as $xReflectionAttribute) |
|
| 173 | 172 | { |
| 174 | 173 | /** @var InjectAttribute */ |
| 175 | 174 | $xAttribute = $xReflectionAttribute->newInstance(); |
@@ -188,11 +187,10 @@ discard block |
||
| 188 | 187 | */ |
| 189 | 188 | private function getMethodAttrs(ReflectionClass $xClass, string $sMethod): void |
| 190 | 189 | { |
| 191 | - $aAttributes = !$xClass->hasMethod($sMethod) ? [] : |
|
| 192 | - $xClass->getMethod($sMethod)->getAttributes(); |
|
| 190 | + $aAttributes = !$xClass->hasMethod($sMethod) ? [] : $xClass->getMethod($sMethod)->getAttributes(); |
|
| 193 | 191 | $aAttributes = array_filter($aAttributes, fn($xAttribute) => |
| 194 | 192 | is_a($xAttribute->getName(), AbstractAttribute::class, true)); |
| 195 | - foreach($aAttributes as $xReflectionAttribute) |
|
| 193 | + foreach ($aAttributes as $xReflectionAttribute) |
|
| 196 | 194 | { |
| 197 | 195 | $xAttribute = $xReflectionAttribute->newInstance(); |
| 198 | 196 | $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute); |
@@ -227,31 +225,31 @@ discard block |
||
| 227 | 225 | $xClass = $xInput->getReflectionClass(); |
| 228 | 226 | // First check if the class is exluded. |
| 229 | 227 | $this->getClassExcludeAttr($xClass); |
| 230 | - if($this->xMetadata->isExcluded()) |
|
| 228 | + if ($this->xMetadata->isExcluded()) |
|
| 231 | 229 | { |
| 232 | 230 | return $this->xMetadata; |
| 233 | 231 | } |
| 234 | 232 | |
| 235 | 233 | $aClasses = [$xClass]; |
| 236 | - while(($xClass = $this->getParentClass($xClass)) !== null) |
|
| 234 | + while (($xClass = $this->getParentClass($xClass)) !== null) |
|
| 237 | 235 | { |
| 238 | 236 | $aClasses[] = $xClass; |
| 239 | 237 | } |
| 240 | 238 | $aClasses = array_reverse($aClasses); |
| 241 | 239 | |
| 242 | - foreach($aClasses as $xClass) |
|
| 240 | + foreach ($aClasses as $xClass) |
|
| 243 | 241 | { |
| 244 | 242 | // Processing class attributes |
| 245 | 243 | $this->getClassAttrs($xClass); |
| 246 | 244 | |
| 247 | 245 | // Processing properties attributes |
| 248 | - foreach($xInput->getProperties() as $sProperty) |
|
| 246 | + foreach ($xInput->getProperties() as $sProperty) |
|
| 249 | 247 | { |
| 250 | 248 | $this->getPropertyAttrs($xClass, $sProperty); |
| 251 | 249 | } |
| 252 | 250 | |
| 253 | 251 | // Processing methods attributes |
| 254 | - foreach($xInput->getMethods() as $sMethod) |
|
| 252 | + foreach ($xInput->getMethods() as $sMethod) |
|
| 255 | 253 | { |
| 256 | 254 | $this->getMethodAttrs($xClass, $sMethod); |
| 257 | 255 | } |
@@ -259,7 +257,7 @@ discard block |
||
| 259 | 257 | |
| 260 | 258 | return $this->xMetadata; |
| 261 | 259 | } |
| 262 | - catch(Exception|Error $e) |
|
| 260 | + catch (Exception|Error $e) |
|
| 263 | 261 | { |
| 264 | 262 | throw new SetupException($e->getMessage()); |
| 265 | 263 | } |
@@ -258,8 +258,7 @@ |
||
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | return $this->xMetadata; |
| 261 | - } |
|
| 262 | - catch(Exception|Error $e) |
|
| 261 | + } catch(Exception|Error $e) |
|
| 263 | 262 | { |
| 264 | 263 | throw new SetupException($e->getMessage()); |
| 265 | 264 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Jaxon\App\Metadata\Metadata; |
| 19 | 19 | use Attribute; |
| 20 | 20 | |
| 21 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
|
| 21 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)] |
|
| 22 | 22 | class Before extends AbstractAttribute |
| 23 | 23 | { |
| 24 | 24 | /** |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Jaxon\App\Metadata\Metadata; |
| 19 | 19 | use Attribute; |
| 20 | 20 | |
| 21 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
|
| 21 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)] |
|
| 22 | 22 | class Callback extends AbstractAttribute |
| 23 | 23 | { |
| 24 | 24 | /** |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Jaxon\App\Metadata\Metadata; |
| 19 | 19 | use Attribute; |
| 20 | 20 | |
| 21 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
|
| 21 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)] |
|
| 22 | 22 | class DataBag extends AbstractAttribute |
| 23 | 23 | { |
| 24 | 24 | /** |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | use function ltrim; |
| 23 | 23 | |
| 24 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
|
| 24 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_PROPERTY|Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)] |
|
| 25 | 25 | class Inject extends AbstractAttribute |
| 26 | 26 | { |
| 27 | 27 | /** |
@@ -92,17 +92,17 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | public function validate(): void |
| 94 | 94 | { |
| 95 | - if($this->nTarget === Attribute::TARGET_CLASS) |
|
| 95 | + if ($this->nTarget === Attribute::TARGET_CLASS) |
|
| 96 | 96 | { |
| 97 | - if(!$this->attr || !$this->type) |
|
| 97 | + if (!$this->attr || !$this->type) |
|
| 98 | 98 | { |
| 99 | 99 | throw new SetupException('When applied to a class, the Inject attribute requires two arguments.'); |
| 100 | 100 | } |
| 101 | 101 | return; |
| 102 | 102 | } |
| 103 | - if($this->nTarget === Attribute::TARGET_METHOD) |
|
| 103 | + if ($this->nTarget === Attribute::TARGET_METHOD) |
|
| 104 | 104 | { |
| 105 | - if(!$this->attr) |
|
| 105 | + if (!$this->attr) |
|
| 106 | 106 | { |
| 107 | 107 | throw new SetupException('When applied to a method, the Inject attribute requires the "attr" argument.'); |
| 108 | 108 | } |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | private function getFullClassName(): void |
| 117 | 117 | { |
| 118 | - if(!$this->type) |
|
| 118 | + if (!$this->type) |
|
| 119 | 119 | { |
| 120 | 120 | // If no type is provided, take the attribute type. |
| 121 | 121 | $this->type = $this->aTypes[$this->attr] ?? ''; |
| 122 | 122 | return; |
| 123 | 123 | } |
| 124 | - if($this->type[0] === '\\') |
|
| 124 | + if ($this->type[0] === '\\') |
|
| 125 | 125 | { |
| 126 | 126 | $this->type = ltrim($this->type, '\\'); |
| 127 | 127 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Jaxon\App\Metadata\Metadata; |
| 19 | 19 | use Attribute; |
| 20 | 20 | |
| 21 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD)] |
|
| 21 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD)] |
|
| 22 | 22 | class Exclude extends AbstractAttribute |
| 23 | 23 | { |
| 24 | 24 | /** |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | use Jaxon\App\Metadata\Metadata; |
| 19 | 19 | use Attribute; |
| 20 | 20 | |
| 21 | -#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] |
|
| 21 | +#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)] |
|
| 22 | 22 | class After extends AbstractAttribute |
| 23 | 23 | { |
| 24 | 24 | /** |
@@ -95,7 +95,7 @@ |
||
| 95 | 95 | */ |
| 96 | 96 | public function delete(string $sKey): void |
| 97 | 97 | { |
| 98 | - if(isset($_SESSION[$sKey])) |
|
| 98 | + if (isset($_SESSION[$sKey])) |
|
| 99 | 99 | { |
| 100 | 100 | unset($_SESSION[$sKey]); |
| 101 | 101 | } |