@@ -36,206 +36,206 @@ |
||
| 36 | 36 | |
| 37 | 37 | class AnnotationReader implements MetadataReaderInterface |
| 38 | 38 | { |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @var AnnotationManager |
| 41 | 41 | */ |
| 42 | - protected $xManager; |
|
| 42 | +protected $xManager; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @var Metadata |
| 46 | 46 | */ |
| 47 | - protected $xMetadata; |
|
| 47 | +protected $xMetadata; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * Properties types, read from the "var" annotations. |
| 51 | 51 | * |
| 52 | 52 | * @var array |
| 53 | 53 | */ |
| 54 | - protected $aPropTypes; |
|
| 54 | +protected $aPropTypes; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * The type of the class member being currently processed. |
| 58 | 58 | * |
| 59 | 59 | * @var string |
| 60 | 60 | */ |
| 61 | - protected $sCurrMemberType; |
|
| 61 | +protected $sCurrMemberType; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * The constructor |
| 65 | 65 | * |
| 66 | 66 | * @param AnnotationManager $xManager |
| 67 | 67 | */ |
| 68 | - public function __construct(AnnotationManager $xManager) |
|
| 69 | - { |
|
| 70 | - $this->xManager = $xManager; |
|
| 71 | - $this->xManager->registry['upload'] = UploadAnnotation::class; |
|
| 72 | - $this->xManager->registry['databag'] = DatabagAnnotation::class; |
|
| 73 | - $this->xManager->registry['exclude'] = ExcludeAnnotation::class; |
|
| 74 | - $this->xManager->registry['before'] = BeforeAnnotation::class; |
|
| 75 | - $this->xManager->registry['after'] = AfterAnnotation::class; |
|
| 76 | - $this->xManager->registry['di'] = ContainerAnnotation::class; |
|
| 77 | - $this->xManager->registry['callback'] = CallbackAnnotation::class; |
|
| 78 | - // Missing standard annotations. |
|
| 79 | - // We need to define this, otherwise they throw an exception, and make the whole processing fail. |
|
| 80 | - $this->xManager->registry['const'] = false; |
|
| 81 | - $this->xManager->registry['inheritDoc'] = false; |
|
| 82 | - $this->xManager->registry['template'] = false; |
|
| 83 | - $this->xManager->registry['param-closure-this'] = false; |
|
| 84 | - } |
|
| 68 | +public function __construct(AnnotationManager $xManager) |
|
| 69 | +{ |
|
| 70 | +$this->xManager = $xManager; |
|
| 71 | +$this->xManager->registry['upload'] = UploadAnnotation::class; |
|
| 72 | +$this->xManager->registry['databag'] = DatabagAnnotation::class; |
|
| 73 | +$this->xManager->registry['exclude'] = ExcludeAnnotation::class; |
|
| 74 | +$this->xManager->registry['before'] = BeforeAnnotation::class; |
|
| 75 | +$this->xManager->registry['after'] = AfterAnnotation::class; |
|
| 76 | +$this->xManager->registry['di'] = ContainerAnnotation::class; |
|
| 77 | +$this->xManager->registry['callback'] = CallbackAnnotation::class; |
|
| 78 | +// Missing standard annotations. |
|
| 79 | +// We need to define this, otherwise they throw an exception, and make the whole processing fail. |
|
| 80 | +$this->xManager->registry['const'] = false; |
|
| 81 | +$this->xManager->registry['inheritDoc'] = false; |
|
| 82 | +$this->xManager->registry['template'] = false; |
|
| 83 | +$this->xManager->registry['param-closure-this'] = false; |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * @return array |
| 88 | 88 | */ |
| 89 | - public function getPropTypes(): array |
|
| 90 | - { |
|
| 91 | - return $this->aPropTypes; |
|
| 92 | - } |
|
| 89 | +public function getPropTypes(): array |
|
| 90 | +{ |
|
| 91 | +return $this->aPropTypes; |
|
| 92 | +} |
|
| 93 | 93 | |
| 94 | - /** |
|
| 94 | +/** |
|
| 95 | 95 | * @return bool |
| 96 | 96 | */ |
| 97 | - public function annotationIsOnProperty(): bool |
|
| 98 | - { |
|
| 99 | - return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY; |
|
| 100 | - } |
|
| 97 | +public function annotationIsOnProperty(): bool |
|
| 98 | +{ |
|
| 99 | +return $this->sCurrMemberType === AnnotationManager::MEMBER_PROPERTY; |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - /** |
|
| 102 | +/** |
|
| 103 | 103 | * @param string $sClass |
| 104 | 104 | * |
| 105 | 105 | * @return void |
| 106 | 106 | * @throws AnnotationException |
| 107 | 107 | */ |
| 108 | - private function getClassAttrs(string $sClass): void |
|
| 109 | - { |
|
| 110 | - // Only keep the annotations declared in this package. |
|
| 111 | - /** @var array<AbstractAnnotation> */ |
|
| 112 | - $aAnnotations = array_filter( |
|
| 113 | - $this->xManager->getClassAnnotations($sClass), |
|
| 114 | - fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 115 | - ); |
|
| 116 | - // First check if the class is excluded. |
|
| 117 | - foreach($aAnnotations as $xAnnotation) |
|
| 118 | - { |
|
| 119 | - if(is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 120 | - { |
|
| 121 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - if($this->xMetadata->isExcluded()) |
|
| 125 | - { |
|
| 126 | - return; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - foreach($aAnnotations as $xAnnotation) |
|
| 130 | - { |
|
| 131 | - if(!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 132 | - { |
|
| 133 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 108 | +private function getClassAttrs(string $sClass): void |
|
| 109 | +{ |
|
| 110 | +// Only keep the annotations declared in this package. |
|
| 111 | +/** @var array<AbstractAnnotation> */ |
|
| 112 | +$aAnnotations = array_filter( |
|
| 113 | +$this->xManager->getClassAnnotations($sClass), |
|
| 114 | +fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 115 | +); |
|
| 116 | +// First check if the class is excluded. |
|
| 117 | +foreach($aAnnotations as $xAnnotation) |
|
| 118 | +{ |
|
| 119 | +if(is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 120 | +{ |
|
| 121 | + $xAnnotation->saveValue($this->xMetadata); |
|
| 122 | +} |
|
| 123 | +} |
|
| 124 | +if($this->xMetadata->isExcluded()) |
|
| 125 | +{ |
|
| 126 | +return; |
|
| 127 | +} |
|
| 137 | 128 | |
| 138 | - /** |
|
| 129 | +foreach($aAnnotations as $xAnnotation) |
|
| 130 | +{ |
|
| 131 | +if(!is_a($xAnnotation, ExcludeAnnotation::class)) |
|
| 132 | +{ |
|
| 133 | + $xAnnotation->saveValue($this->xMetadata); |
|
| 134 | +} |
|
| 135 | +} |
|
| 136 | +} |
|
| 137 | + |
|
| 138 | +/** |
|
| 139 | 139 | * @param string $sClass |
| 140 | 140 | * @param string $sProperty |
| 141 | 141 | * |
| 142 | 142 | * @return void |
| 143 | 143 | * @throws AnnotationException |
| 144 | 144 | */ |
| 145 | - private function getPropertyAttrs(string $sClass, string $sProperty): void |
|
| 145 | +private function getPropertyAttrs(string $sClass, string $sProperty): void |
|
| 146 | +{ |
|
| 147 | +/** @var array<ContainerAnnotation> */ |
|
| 148 | +// Only keep the annotations declared in this package. |
|
| 149 | +$aAnnotations = array_filter( |
|
| 150 | +$this->xManager->getPropertyAnnotations($sClass, $sProperty), |
|
| 151 | +function($xAnnotation) use($sProperty) { |
|
| 152 | + // Save the property type |
|
| 153 | + if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 146 | 154 | { |
| 147 | - /** @var array<ContainerAnnotation> */ |
|
| 148 | - // Only keep the annotations declared in this package. |
|
| 149 | - $aAnnotations = array_filter( |
|
| 150 | - $this->xManager->getPropertyAnnotations($sClass, $sProperty), |
|
| 151 | - function($xAnnotation) use($sProperty) { |
|
| 152 | - // Save the property type |
|
| 153 | - if(is_a($xAnnotation, VarAnnotation::class)) |
|
| 154 | - { |
|
| 155 | - $this->aPropTypes[$sProperty] = $xAnnotation->type; |
|
| 156 | - } |
|
| 157 | - // Only container annotations are allowed on properties |
|
| 158 | - return is_a($xAnnotation, ContainerAnnotation::class); |
|
| 159 | - } |
|
| 160 | - ); |
|
| 161 | - if(count($aAnnotations) > 1) |
|
| 162 | - { |
|
| 163 | - throw new AnnotationException('Only one @di annotation is allowed on a property'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - foreach($aAnnotations as $xAnnotation) |
|
| 167 | - { |
|
| 168 | - $xAnnotation->setAttr($sProperty); |
|
| 169 | - $xAnnotation->saveValue($this->xMetadata); |
|
| 170 | - } |
|
| 155 | + $this->aPropTypes[$sProperty] = $xAnnotation->type; |
|
| 171 | 156 | } |
| 157 | + // Only container annotations are allowed on properties |
|
| 158 | + return is_a($xAnnotation, ContainerAnnotation::class); |
|
| 159 | +} |
|
| 160 | +); |
|
| 161 | +if(count($aAnnotations) > 1) |
|
| 162 | +{ |
|
| 163 | +throw new AnnotationException('Only one @di annotation is allowed on a property'); |
|
| 164 | +} |
|
| 172 | 165 | |
| 173 | - /** |
|
| 166 | +foreach($aAnnotations as $xAnnotation) |
|
| 167 | +{ |
|
| 168 | +$xAnnotation->setAttr($sProperty); |
|
| 169 | +$xAnnotation->saveValue($this->xMetadata); |
|
| 170 | +} |
|
| 171 | +} |
|
| 172 | + |
|
| 173 | +/** |
|
| 174 | 174 | * @param string $sClass |
| 175 | 175 | * @param string $sMethod |
| 176 | 176 | * |
| 177 | 177 | * @return void |
| 178 | 178 | * @throws AnnotationException |
| 179 | 179 | */ |
| 180 | - private function getMethodAttrs(string $sClass, string $sMethod): void |
|
| 181 | - { |
|
| 182 | - // Only keep the annotations declared in this package. |
|
| 183 | - /** @var array<AbstractAnnotation> */ |
|
| 184 | - $aAnnotations = array_filter( |
|
| 185 | - $this->xManager->getMethodAnnotations($sClass, $sMethod), |
|
| 186 | - fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 187 | - ); |
|
| 188 | - foreach($aAnnotations as $xAnnotation) |
|
| 189 | - { |
|
| 190 | - $xAnnotation->saveValue($this->xMetadata, $sMethod); |
|
| 191 | - } |
|
| 192 | - } |
|
| 180 | +private function getMethodAttrs(string $sClass, string $sMethod): void |
|
| 181 | +{ |
|
| 182 | +// Only keep the annotations declared in this package. |
|
| 183 | +/** @var array<AbstractAnnotation> */ |
|
| 184 | +$aAnnotations = array_filter( |
|
| 185 | +$this->xManager->getMethodAnnotations($sClass, $sMethod), |
|
| 186 | +fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class) |
|
| 187 | +); |
|
| 188 | +foreach($aAnnotations as $xAnnotation) |
|
| 189 | +{ |
|
| 190 | +$xAnnotation->saveValue($this->xMetadata, $sMethod); |
|
| 191 | +} |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * @inheritDoc |
| 196 | 196 | * @throws SetupException |
| 197 | 197 | */ |
| 198 | - public function getAttributes(InputData $xInput): Metadata |
|
| 199 | - { |
|
| 200 | - ContainerAnnotation::$xReader = $this; |
|
| 201 | - $this->aPropTypes = []; |
|
| 202 | - $this->xMetadata = new Metadata(); |
|
| 203 | - $sClass = $xInput->getReflectionClass()->getName(); |
|
| 204 | - |
|
| 205 | - try |
|
| 206 | - { |
|
| 207 | - // Processing class annotations |
|
| 208 | - $this->sCurrMemberType = AnnotationManager::MEMBER_CLASS; |
|
| 209 | - |
|
| 210 | - $this->getClassAttrs($sClass); |
|
| 211 | - if($this->xMetadata->isExcluded()) |
|
| 212 | - { |
|
| 213 | - // The entire class is not to be exported. |
|
| 214 | - return $this->xMetadata; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Processing properties annotations |
|
| 218 | - $this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY; |
|
| 219 | - |
|
| 220 | - // Properties annotations |
|
| 221 | - foreach($xInput->getProperties() as $sProperty) |
|
| 222 | - { |
|
| 223 | - $this->getPropertyAttrs($sClass, $sProperty); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Processing methods annotations |
|
| 227 | - $this->sCurrMemberType = AnnotationManager::MEMBER_METHOD; |
|
| 228 | - |
|
| 229 | - foreach($xInput->getMethods() as $sMethod) |
|
| 230 | - { |
|
| 231 | - $this->getMethodAttrs($sClass, $sMethod); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return $this->xMetadata; |
|
| 235 | - } |
|
| 236 | - catch(AnnotationException $e) |
|
| 237 | - { |
|
| 238 | - throw new SetupException($e->getMessage()); |
|
| 239 | - } |
|
| 240 | - } |
|
| 198 | +public function getAttributes(InputData $xInput): Metadata |
|
| 199 | +{ |
|
| 200 | +ContainerAnnotation::$xReader = $this; |
|
| 201 | +$this->aPropTypes = []; |
|
| 202 | +$this->xMetadata = new Metadata(); |
|
| 203 | +$sClass = $xInput->getReflectionClass()->getName(); |
|
| 204 | + |
|
| 205 | +try |
|
| 206 | +{ |
|
| 207 | +// Processing class annotations |
|
| 208 | +$this->sCurrMemberType = AnnotationManager::MEMBER_CLASS; |
|
| 209 | + |
|
| 210 | +$this->getClassAttrs($sClass); |
|
| 211 | +if($this->xMetadata->isExcluded()) |
|
| 212 | +{ |
|
| 213 | + // The entire class is not to be exported. |
|
| 214 | + return $this->xMetadata; |
|
| 215 | +} |
|
| 216 | + |
|
| 217 | +// Processing properties annotations |
|
| 218 | +$this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY; |
|
| 219 | + |
|
| 220 | +// Properties annotations |
|
| 221 | +foreach($xInput->getProperties() as $sProperty) |
|
| 222 | +{ |
|
| 223 | + $this->getPropertyAttrs($sClass, $sProperty); |
|
| 224 | +} |
|
| 225 | + |
|
| 226 | +// Processing methods annotations |
|
| 227 | +$this->sCurrMemberType = AnnotationManager::MEMBER_METHOD; |
|
| 228 | + |
|
| 229 | +foreach($xInput->getMethods() as $sMethod) |
|
| 230 | +{ |
|
| 231 | + $this->getMethodAttrs($sClass, $sMethod); |
|
| 232 | +} |
|
| 233 | + |
|
| 234 | +return $this->xMetadata; |
|
| 235 | +} |
|
| 236 | +catch(AnnotationException $e) |
|
| 237 | +{ |
|
| 238 | +throw new SetupException($e->getMessage()); |
|
| 239 | +} |
|
| 240 | +} |
|
| 241 | 241 | } |
@@ -14,41 +14,41 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | trait ComponentTrait |
| 16 | 16 | { |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * Get the component helper |
| 19 | 19 | * |
| 20 | 20 | * @return ComponentHelper |
| 21 | 21 | */ |
| 22 | - abstract protected function helper(): ComponentHelper; |
|
| 22 | +abstract protected function helper(): ComponentHelper; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * Get the Ajax response |
| 26 | 26 | * |
| 27 | 27 | * @return AjaxResponse |
| 28 | 28 | */ |
| 29 | - abstract protected function response(): AjaxResponse; |
|
| 29 | +abstract protected function response(): AjaxResponse; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * Get the Jaxon request target |
| 33 | 33 | * |
| 34 | 34 | * @return TargetInterface|null |
| 35 | 35 | */ |
| 36 | - protected function target(): ?TargetInterface |
|
| 37 | - { |
|
| 38 | - return $this->helper()->xTarget; |
|
| 39 | - } |
|
| 36 | +protected function target(): ?TargetInterface |
|
| 37 | +{ |
|
| 38 | +return $this->helper()->xTarget; |
|
| 39 | +} |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * Get the temp cache |
| 43 | 43 | * |
| 44 | 44 | * @return Stash |
| 45 | 45 | */ |
| 46 | - protected function stash(): Stash |
|
| 47 | - { |
|
| 48 | - return $this->helper()->xStash; |
|
| 49 | - } |
|
| 46 | +protected function stash(): Stash |
|
| 47 | +{ |
|
| 48 | +return $this->helper()->xStash; |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Get an instance of a Jaxon class by name |
| 53 | 53 | * |
| 54 | 54 | * @template T |
@@ -57,60 +57,60 @@ discard block |
||
| 57 | 57 | * @return T|null |
| 58 | 58 | * @throws SetupException |
| 59 | 59 | */ |
| 60 | - protected function cl(string $sClassName): mixed |
|
| 61 | - { |
|
| 62 | - return $this->helper()->cl($sClassName); |
|
| 63 | - } |
|
| 60 | +protected function cl(string $sClassName): mixed |
|
| 61 | +{ |
|
| 62 | +return $this->helper()->cl($sClassName); |
|
| 63 | +} |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * Get the logger |
| 67 | 67 | * |
| 68 | 68 | * @return LoggerInterface |
| 69 | 69 | */ |
| 70 | - protected function logger(): LoggerInterface |
|
| 71 | - { |
|
| 72 | - return $this->helper()->xLogger; |
|
| 73 | - } |
|
| 70 | +protected function logger(): LoggerInterface |
|
| 71 | +{ |
|
| 72 | +return $this->helper()->xLogger; |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * Get the view renderer |
| 77 | 77 | * |
| 78 | 78 | * @return ViewRenderer |
| 79 | 79 | */ |
| 80 | - protected function view(): ViewRenderer |
|
| 81 | - { |
|
| 82 | - return $this->helper()->xViewRenderer; |
|
| 83 | - } |
|
| 80 | +protected function view(): ViewRenderer |
|
| 81 | +{ |
|
| 82 | +return $this->helper()->xViewRenderer; |
|
| 83 | +} |
|
| 84 | 84 | |
| 85 | - /** |
|
| 85 | +/** |
|
| 86 | 86 | * Get the session manager |
| 87 | 87 | * |
| 88 | 88 | * @return SessionInterface |
| 89 | 89 | */ |
| 90 | - protected function session(): SessionInterface |
|
| 91 | - { |
|
| 92 | - return $this->helper()->xSessionManager; |
|
| 93 | - } |
|
| 90 | +protected function session(): SessionInterface |
|
| 91 | +{ |
|
| 92 | +return $this->helper()->xSessionManager; |
|
| 93 | +} |
|
| 94 | 94 | |
| 95 | - /** |
|
| 95 | +/** |
|
| 96 | 96 | * Get the uploaded files |
| 97 | 97 | * |
| 98 | 98 | * @return array |
| 99 | 99 | */ |
| 100 | - protected function files(): array |
|
| 101 | - { |
|
| 102 | - return $this->helper()->xUploadHandler->files(); |
|
| 103 | - } |
|
| 100 | +protected function files(): array |
|
| 101 | +{ |
|
| 102 | +return $this->helper()->xUploadHandler->files(); |
|
| 103 | +} |
|
| 104 | 104 | |
| 105 | - /** |
|
| 105 | +/** |
|
| 106 | 106 | * Get a data bag. |
| 107 | 107 | * |
| 108 | 108 | * @param string $sBagName |
| 109 | 109 | * |
| 110 | 110 | * @return DatabagContext |
| 111 | 111 | */ |
| 112 | - protected function bag(string $sBagName): DatabagContext |
|
| 113 | - { |
|
| 114 | - return $this->response()->bag($sBagName); |
|
| 115 | - } |
|
| 112 | +protected function bag(string $sBagName): DatabagContext |
|
| 113 | +{ |
|
| 114 | +return $this->response()->bag($sBagName); |
|
| 115 | +} |
|
| 116 | 116 | } |
@@ -16,12 +16,12 @@ |
||
| 16 | 16 | |
| 17 | 17 | interface MetadataReaderInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * Get the component metadata |
| 21 | 21 | * |
| 22 | 22 | * @param InputData $xInput |
| 23 | 23 | * |
| 24 | 24 | * @return Metadata |
| 25 | 25 | */ |
| 26 | - public function getAttributes(InputData $xInput): Metadata; |
|
| 26 | +public function getAttributes(InputData $xInput): Metadata; |
|
| 27 | 27 | } |
@@ -22,61 +22,61 @@ |
||
| 22 | 22 | |
| 23 | 23 | class DatabagData extends AbstractData |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The databag names |
| 27 | 27 | * |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - protected $aNames = []; |
|
| 30 | +protected $aNames = []; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function getName(): string |
|
| 36 | - { |
|
| 37 | - return 'bags'; |
|
| 38 | - } |
|
| 35 | +public function getName(): string |
|
| 36 | +{ |
|
| 37 | +return 'bags'; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function getValue(): mixed |
|
| 44 | - { |
|
| 45 | - return array_values($this->aNames); |
|
| 46 | - } |
|
| 43 | +public function getValue(): mixed |
|
| 44 | +{ |
|
| 45 | +return array_values($this->aNames); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @param string $sName |
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - protected function validateName(string $sName): void |
|
| 54 | - { |
|
| 55 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | - { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - throw new SetupException("$sName is not a valid \"name\" value for databag"); |
|
| 60 | - } |
|
| 53 | +protected function validateName(string $sName): void |
|
| 54 | +{ |
|
| 55 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | +{ |
|
| 57 | +return; |
|
| 58 | +} |
|
| 59 | +throw new SetupException("$sName is not a valid \"name\" value for databag"); |
|
| 60 | +} |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * @param string $sName |
| 64 | 64 | * |
| 65 | 65 | * @return void |
| 66 | 66 | */ |
| 67 | - public function addValue(string $sName): void |
|
| 68 | - { |
|
| 69 | - $this->validateName($sName); |
|
| 67 | +public function addValue(string $sName): void |
|
| 68 | +{ |
|
| 69 | +$this->validateName($sName); |
|
| 70 | 70 | |
| 71 | - $this->aNames[$sName] = $sName; |
|
| 72 | - } |
|
| 71 | +$this->aNames[$sName] = $sName; |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function encode(string $sVarName): array |
|
| 78 | - { |
|
| 79 | - return array_map(fn($sName) => |
|
| 80 | - "{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | - } |
|
| 77 | +public function encode(string $sVarName): array |
|
| 78 | +{ |
|
| 79 | +return array_map(fn($sName) => |
|
| 80 | +"{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | +} |
|
| 82 | 82 | } |
@@ -22,61 +22,61 @@ |
||
| 22 | 22 | |
| 23 | 23 | class CallbackData extends AbstractData |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The callback js objects |
| 27 | 27 | * |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - protected $aNames = []; |
|
| 30 | +protected $aNames = []; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function getName(): string |
|
| 36 | - { |
|
| 37 | - return 'callback'; |
|
| 38 | - } |
|
| 35 | +public function getName(): string |
|
| 36 | +{ |
|
| 37 | +return 'callback'; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function getValue(): mixed |
|
| 44 | - { |
|
| 45 | - return array_values($this->aNames); |
|
| 46 | - } |
|
| 43 | +public function getValue(): mixed |
|
| 44 | +{ |
|
| 45 | +return array_values($this->aNames); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @param string $sName |
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - protected function validateObjectName(string $sName): void |
|
| 54 | - { |
|
| 55 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | - { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - throw new SetupException("$sName is not a valid \"name\" value for callback"); |
|
| 60 | - } |
|
| 53 | +protected function validateObjectName(string $sName): void |
|
| 54 | +{ |
|
| 55 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | +{ |
|
| 57 | +return; |
|
| 58 | +} |
|
| 59 | +throw new SetupException("$sName is not a valid \"name\" value for callback"); |
|
| 60 | +} |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * @param string $sName |
| 64 | 64 | * |
| 65 | 65 | * @return void |
| 66 | 66 | */ |
| 67 | - public function addValue(string $sName): void |
|
| 68 | - { |
|
| 69 | - $this->validateObjectName($sName); |
|
| 67 | +public function addValue(string $sName): void |
|
| 68 | +{ |
|
| 69 | +$this->validateObjectName($sName); |
|
| 70 | 70 | |
| 71 | - $this->aNames[$sName] = $sName; |
|
| 72 | - } |
|
| 71 | +$this->aNames[$sName] = $sName; |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function encode(string $sVarName): array |
|
| 78 | - { |
|
| 79 | - return array_map(fn($sName) => |
|
| 80 | - "{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | - } |
|
| 77 | +public function encode(string $sVarName): array |
|
| 78 | +{ |
|
| 79 | +return array_map(fn($sName) => |
|
| 80 | +"{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | +} |
|
| 82 | 82 | } |
@@ -45,49 +45,49 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | class PluginManager |
| 47 | 47 | { |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Request plugins, indexed by name |
| 50 | 50 | * |
| 51 | 51 | * @var array<string> |
| 52 | 52 | */ |
| 53 | - private $aRegistryPlugins = []; |
|
| 53 | +private $aRegistryPlugins = []; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Request handlers, indexed by name |
| 57 | 57 | * |
| 58 | 58 | * @var array<string> |
| 59 | 59 | */ |
| 60 | - private $aRequestHandlers = []; |
|
| 60 | +private $aRequestHandlers = []; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * Response plugins, indexed by name |
| 64 | 64 | * |
| 65 | 65 | * @var array<string> |
| 66 | 66 | */ |
| 67 | - private $aResponsePlugins = []; |
|
| 67 | +private $aResponsePlugins = []; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * The constructor |
| 71 | 71 | * |
| 72 | 72 | * @param Container $di |
| 73 | 73 | * @param CodeGenerator $xCodeGenerator |
| 74 | 74 | * @param Translator $xTranslator |
| 75 | 75 | */ |
| 76 | - public function __construct(private Container $di, |
|
| 77 | - private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 78 | - {} |
|
| 76 | +public function __construct(private Container $di, |
|
| 77 | +private CodeGenerator $xCodeGenerator, private Translator $xTranslator) |
|
| 78 | +{} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * Get the request plugins |
| 82 | 82 | * |
| 83 | 83 | * @return array<class-string> |
| 84 | 84 | */ |
| 85 | - public function getRequestHandlers(): array |
|
| 86 | - { |
|
| 87 | - return $this->aRequestHandlers; |
|
| 88 | - } |
|
| 85 | +public function getRequestHandlers(): array |
|
| 86 | +{ |
|
| 87 | +return $this->aRequestHandlers; |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register a plugin |
| 92 | 92 | * |
| 93 | 93 | * @param class-string $sClassName The plugin class |
@@ -97,40 +97,40 @@ discard block |
||
| 97 | 97 | * @return int |
| 98 | 98 | * @throws SetupException |
| 99 | 99 | */ |
| 100 | - private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 101 | - { |
|
| 102 | - // Any plugin must implement the PluginInterface interface. |
|
| 103 | - if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 104 | - { |
|
| 105 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 106 | - 'name' => $sClassName, |
|
| 107 | - ]); |
|
| 108 | - throw new SetupException($sMessage); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Response plugin. |
|
| 112 | - if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 113 | - { |
|
| 114 | - $this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 115 | - return 1; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // Request plugin. |
|
| 119 | - $nCount = 0; |
|
| 120 | - if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 121 | - { |
|
| 122 | - $this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 123 | - $nCount++; |
|
| 124 | - } |
|
| 125 | - if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 126 | - { |
|
| 127 | - $this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 128 | - $nCount++; |
|
| 129 | - } |
|
| 130 | - return $nCount; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 100 | +private function _registerPlugin(string $sClassName, string $sPluginName, array $aInterfaces): int |
|
| 101 | +{ |
|
| 102 | +// Any plugin must implement the PluginInterface interface. |
|
| 103 | +if(!in_array(PluginInterface::class, $aInterfaces)) |
|
| 104 | +{ |
|
| 105 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 106 | + 'name' => $sClassName, |
|
| 107 | +]); |
|
| 108 | +throw new SetupException($sMessage); |
|
| 109 | +} |
|
| 110 | + |
|
| 111 | +// Response plugin. |
|
| 112 | +if(in_array(ResponsePluginInterface::class, $aInterfaces)) |
|
| 113 | +{ |
|
| 114 | +$this->aResponsePlugins[$sPluginName] = $sClassName; |
|
| 115 | +return 1; |
|
| 116 | +} |
|
| 117 | + |
|
| 118 | +// Request plugin. |
|
| 119 | +$nCount = 0; |
|
| 120 | +if(in_array(CallableRegistryInterface::class, $aInterfaces)) |
|
| 121 | +{ |
|
| 122 | +$this->aRegistryPlugins[$sPluginName] = $sClassName; |
|
| 123 | +$nCount++; |
|
| 124 | +} |
|
| 125 | +if(in_array(RequestHandlerInterface::class, $aInterfaces)) |
|
| 126 | +{ |
|
| 127 | +$this->aRequestHandlers[$sPluginName] = $sClassName; |
|
| 128 | +$nCount++; |
|
| 129 | +} |
|
| 130 | +return $nCount; |
|
| 131 | +} |
|
| 132 | + |
|
| 133 | +/** |
|
| 134 | 134 | * Register a plugin |
| 135 | 135 | * |
| 136 | 136 | * Below is a table for priorities and their description: |
@@ -145,34 +145,34 @@ discard block |
||
| 145 | 145 | * @return void |
| 146 | 146 | * @throws SetupException |
| 147 | 147 | */ |
| 148 | - public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 149 | - { |
|
| 150 | - $aInterfaces = class_implements($sClassName); |
|
| 151 | - $nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 152 | - |
|
| 153 | - // Any plugin can implement the CodeGeneratorInterface interface. |
|
| 154 | - if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 155 | - { |
|
| 156 | - $this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 157 | - $nCount++; |
|
| 158 | - } |
|
| 159 | - // The class is not a valid plugin. |
|
| 160 | - if($nCount === 0) |
|
| 161 | - { |
|
| 162 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 163 | - 'name' => $sClassName, |
|
| 164 | - ]); |
|
| 165 | - throw new SetupException($sMessage); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Register the plugin in the DI container, if necessary |
|
| 169 | - if(!$this->di->has($sClassName)) |
|
| 170 | - { |
|
| 171 | - $this->di->auto($sClassName); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 148 | +public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000): void |
|
| 149 | +{ |
|
| 150 | +$aInterfaces = class_implements($sClassName); |
|
| 151 | +$nCount = $this->_registerPlugin($sClassName, $sPluginName, $aInterfaces); |
|
| 152 | + |
|
| 153 | +// Any plugin can implement the CodeGeneratorInterface interface. |
|
| 154 | +if(in_array(CodeGeneratorInterface::class, $aInterfaces)) |
|
| 155 | +{ |
|
| 156 | +$this->xCodeGenerator->addCodeGenerator($sClassName, $nPriority); |
|
| 157 | +$nCount++; |
|
| 158 | +} |
|
| 159 | +// The class is not a valid plugin. |
|
| 160 | +if($nCount === 0) |
|
| 161 | +{ |
|
| 162 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', [ |
|
| 163 | + 'name' => $sClassName, |
|
| 164 | +]); |
|
| 165 | +throw new SetupException($sMessage); |
|
| 166 | +} |
|
| 167 | + |
|
| 168 | +// Register the plugin in the DI container, if necessary |
|
| 169 | +if(!$this->di->has($sClassName)) |
|
| 170 | +{ |
|
| 171 | +$this->di->auto($sClassName); |
|
| 172 | +} |
|
| 173 | +} |
|
| 174 | + |
|
| 175 | +/** |
|
| 176 | 176 | * Find the specified response plugin by name or class name |
| 177 | 177 | * |
| 178 | 178 | * @template R of ResponsePluginInterface |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * |
| 181 | 181 | * @return ($sName is class-string ? R : ResponsePluginInterface)|null |
| 182 | 182 | */ |
| 183 | - public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 184 | - { |
|
| 185 | - return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 186 | - (!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 187 | - $this->di->g($this->aResponsePlugins[$sName])); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 183 | +public function getResponsePlugin(string $sName): ?ResponsePluginInterface |
|
| 184 | +{ |
|
| 185 | +return $this->di->h($sName) ? $this->di->g($sName) : |
|
| 186 | +(!isset($this->aResponsePlugins[$sName]) ? null : |
|
| 187 | +$this->di->g($this->aResponsePlugins[$sName])); |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +/** |
|
| 191 | 191 | * Register a callable function or class |
| 192 | 192 | * |
| 193 | 193 | * Call the request plugin with the $sType defined as name. |
@@ -199,46 +199,46 @@ discard block |
||
| 199 | 199 | * @return void |
| 200 | 200 | * @throws SetupException |
| 201 | 201 | */ |
| 202 | - public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 203 | - { |
|
| 204 | - if(isset($this->aRegistryPlugins[$sType]) && |
|
| 205 | - ($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 206 | - { |
|
| 207 | - $xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 208 | - return; |
|
| 209 | - } |
|
| 210 | - throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 211 | - ['name' => $sType, 'callable' => $sCallable])); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 202 | +public function registerCallable(string $sType, string $sCallable, $xOptions = []): void |
|
| 203 | +{ |
|
| 204 | +if(isset($this->aRegistryPlugins[$sType]) && |
|
| 205 | +($xPlugin = $this->di->g($this->aRegistryPlugins[$sType]))) |
|
| 206 | +{ |
|
| 207 | +$xPlugin->register($sType, $sCallable, $xPlugin->checkOptions($sCallable, $xOptions)); |
|
| 208 | +return; |
|
| 209 | +} |
|
| 210 | +throw new SetupException($this->xTranslator->trans('errors.register.plugin', |
|
| 211 | +['name' => $sType, 'callable' => $sCallable])); |
|
| 212 | +} |
|
| 213 | + |
|
| 214 | +/** |
|
| 215 | 215 | * Register the Jaxon request plugins |
| 216 | 216 | * |
| 217 | 217 | * @return void |
| 218 | 218 | * @throws SetupException |
| 219 | 219 | */ |
| 220 | - public function registerPlugins(): void |
|
| 221 | - { |
|
| 222 | - // Request plugins |
|
| 223 | - $this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 224 | - $this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 225 | - $this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 226 | - |
|
| 227 | - // Response plugins |
|
| 228 | - $this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 229 | - $this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 230 | - $this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 231 | - $this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 232 | - $this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 220 | +public function registerPlugins(): void |
|
| 221 | +{ |
|
| 222 | +// Request plugins |
|
| 223 | +$this->registerPlugin(CallableClassPlugin::class, Jaxon::CALLABLE_CLASS, 101); |
|
| 224 | +$this->registerPlugin(CallableFunctionPlugin::class, Jaxon::CALLABLE_FUNCTION, 102); |
|
| 225 | +$this->registerPlugin(CallableDirPlugin::class, Jaxon::CALLABLE_DIR, 103); |
|
| 226 | + |
|
| 227 | +// Response plugins |
|
| 228 | +$this->registerPlugin(ScriptPlugin::class, ScriptPlugin::NAME, 700); |
|
| 229 | +$this->registerPlugin(DatabagPlugin::class, DatabagPlugin::NAME, 700); |
|
| 230 | +$this->registerPlugin(DialogPlugin::class, DialogPlugin::NAME, 750); |
|
| 231 | +$this->registerPlugin(PaginatorPlugin::class, PaginatorPlugin::NAME, 800); |
|
| 232 | +$this->registerPlugin(PsrPlugin::class, PsrPlugin::NAME, 850); |
|
| 233 | +} |
|
| 234 | + |
|
| 235 | +/** |
|
| 236 | 236 | * Get the parameter reader |
| 237 | 237 | * |
| 238 | 238 | * @return ParameterReader |
| 239 | 239 | */ |
| 240 | - public function getParameterReader(): ParameterReader |
|
| 241 | - { |
|
| 242 | - return $this->di->g(ParameterReader::class); |
|
| 243 | - } |
|
| 240 | +public function getParameterReader(): ParameterReader |
|
| 241 | +{ |
|
| 242 | +return $this->di->g(ParameterReader::class); |
|
| 243 | +} |
|
| 244 | 244 | } |