@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | class ParameterReader |
| 42 | 42 | { |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The constructor |
| 45 | 45 | * |
| 46 | 46 | * @param Container $di |
@@ -48,28 +48,28 @@ discard block |
||
| 48 | 48 | * @param ConfigManager $xConfigManager |
| 49 | 49 | * @param UriDetector $xUriDetector |
| 50 | 50 | */ |
| 51 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 52 | - private ConfigManager $xConfigManager, private UriDetector $xUriDetector) |
|
| 53 | - {} |
|
| 51 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 52 | +private ConfigManager $xConfigManager, private UriDetector $xUriDetector) |
|
| 53 | +{} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Decode input data. |
| 57 | 57 | * |
| 58 | 58 | * @param string $sStr |
| 59 | 59 | * |
| 60 | 60 | * @return string |
| 61 | 61 | */ |
| 62 | - private function decodeStr(string $sStr): string |
|
| 63 | - { |
|
| 64 | - $aServerParams = $this->di->getServerParams(); |
|
| 65 | - $sContentType = $aServerParams['CONTENT_TYPE'] ?? $aServerParams['HTTP_CONTENT_TYPE'] ?? ''; |
|
| 66 | - $sType = 'multipart/form-data'; |
|
| 67 | - // Parameters are url encoded when uploading files |
|
| 68 | - return strncmp($sContentType, $sType, strlen($sType)) !== 0 ? |
|
| 69 | - $sStr : urldecode($sStr); |
|
| 70 | - } |
|
| 62 | +private function decodeStr(string $sStr): string |
|
| 63 | +{ |
|
| 64 | +$aServerParams = $this->di->getServerParams(); |
|
| 65 | +$sContentType = $aServerParams['CONTENT_TYPE'] ?? $aServerParams['HTTP_CONTENT_TYPE'] ?? ''; |
|
| 66 | +$sType = 'multipart/form-data'; |
|
| 67 | +// Parameters are url encoded when uploading files |
|
| 68 | +return strncmp($sContentType, $sType, strlen($sType)) !== 0 ? |
|
| 69 | +$sStr : urldecode($sStr); |
|
| 70 | +} |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * Decode input data. |
| 74 | 74 | * |
| 75 | 75 | * @param string $sStr |
@@ -77,73 +77,73 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | * @throws RequestException |
| 79 | 79 | */ |
| 80 | - private function decoderUtf8Str(string $sStr): string |
|
| 81 | - { |
|
| 82 | - $sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
|
| 83 | - if(function_exists('iconv')) |
|
| 84 | - { |
|
| 85 | - return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
|
| 86 | - } |
|
| 87 | - if(function_exists('mb_convert_encoding')) |
|
| 88 | - { |
|
| 89 | - return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
|
| 90 | - } |
|
| 91 | - // By default, no decoding |
|
| 92 | - // return $sStr; |
|
| 93 | - throw new RequestException($this->xTranslator->trans('errors.request.conversion')); |
|
| 94 | - } |
|
| 80 | +private function decoderUtf8Str(string $sStr): string |
|
| 81 | +{ |
|
| 82 | +$sEncoding = $this->xConfigManager->getOption('core.encoding', ''); |
|
| 83 | +if(function_exists('iconv')) |
|
| 84 | +{ |
|
| 85 | +return iconv("UTF-8", $sEncoding . '//TRANSLIT', $sStr); |
|
| 86 | +} |
|
| 87 | +if(function_exists('mb_convert_encoding')) |
|
| 88 | +{ |
|
| 89 | +return mb_convert_encoding($sStr, $sEncoding, "UTF-8"); |
|
| 90 | +} |
|
| 91 | +// By default, no decoding |
|
| 92 | +// return $sStr; |
|
| 93 | +throw new RequestException($this->xTranslator->trans('errors.request.conversion')); |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Choose the function to use to decode input data. |
| 98 | 98 | * |
| 99 | 99 | * @param string $sParam |
| 100 | 100 | * |
| 101 | 101 | * @return string |
| 102 | 102 | */ |
| 103 | - private function decodeRequestParameter(string $sParam): string |
|
| 104 | - { |
|
| 105 | - $sParam = $this->decodeStr($sParam); |
|
| 106 | - if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 107 | - { |
|
| 108 | - return $sParam; |
|
| 109 | - } |
|
| 110 | - $this->xConfigManager->setOption('core.decode_utf8', false); |
|
| 111 | - return $this->decoderUtf8Str($sParam); |
|
| 112 | - } |
|
| 103 | +private function decodeRequestParameter(string $sParam): string |
|
| 104 | +{ |
|
| 105 | +$sParam = $this->decodeStr($sParam); |
|
| 106 | +if(!$this->xConfigManager->getOption('core.decode_utf8')) |
|
| 107 | +{ |
|
| 108 | +return $sParam; |
|
| 109 | +} |
|
| 110 | +$this->xConfigManager->setOption('core.decode_utf8', false); |
|
| 111 | +return $this->decoderUtf8Str($sParam); |
|
| 112 | +} |
|
| 113 | 113 | |
| 114 | - /** |
|
| 114 | +/** |
|
| 115 | 115 | * @param ServerRequestInterface $xRequest |
| 116 | 116 | * |
| 117 | 117 | * @return array|null |
| 118 | 118 | */ |
| 119 | - public function getRequestParameter(ServerRequestInterface $xRequest): ?array |
|
| 120 | - { |
|
| 121 | - $aBody = $xRequest->getParsedBody(); |
|
| 122 | - $aParams = is_array($aBody) ? $aBody : $xRequest->getQueryParams(); |
|
| 123 | - // Check if Jaxon call parameters are present. |
|
| 124 | - return !isset($aParams['jxncall']) || !is_string($aParams['jxncall']) ? null : |
|
| 125 | - json_decode($this->decodeRequestParameter($aParams['jxncall']), true); |
|
| 126 | - } |
|
| 119 | +public function getRequestParameter(ServerRequestInterface $xRequest): ?array |
|
| 120 | +{ |
|
| 121 | +$aBody = $xRequest->getParsedBody(); |
|
| 122 | +$aParams = is_array($aBody) ? $aBody : $xRequest->getQueryParams(); |
|
| 123 | +// Check if Jaxon call parameters are present. |
|
| 124 | +return !isset($aParams['jxncall']) || !is_string($aParams['jxncall']) ? null : |
|
| 125 | +json_decode($this->decodeRequestParameter($aParams['jxncall']), true); |
|
| 126 | +} |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Get the URI of the current request |
| 130 | 130 | * |
| 131 | 131 | * @throws UriException |
| 132 | 132 | */ |
| 133 | - public function uri(): string |
|
| 134 | - { |
|
| 135 | - return $this->xUriDetector->detect($this->di->getServerParams()); |
|
| 136 | - } |
|
| 133 | +public function uri(): string |
|
| 134 | +{ |
|
| 135 | +return $this->xUriDetector->detect($this->di->getServerParams()); |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * Make the specified URL suitable for redirect |
| 140 | 140 | * |
| 141 | 141 | * @param string $sURL The relative or fully qualified URL |
| 142 | 142 | * |
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | - public function parseUrl(string $sURL): string |
|
| 146 | - { |
|
| 147 | - return $this->xUriDetector->redirect($sURL, $this->di->getServerParams()); |
|
| 148 | - } |
|
| 145 | +public function parseUrl(string $sURL): string |
|
| 146 | +{ |
|
| 147 | +return $this->xUriDetector->redirect($sURL, $this->di->getServerParams()); |
|
| 148 | +} |
|
| 149 | 149 | } |
@@ -18,52 +18,52 @@ |
||
| 18 | 18 | |
| 19 | 19 | interface FileInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Get the filesystem where the file is stored |
| 23 | 23 | * |
| 24 | 24 | * @return Filesystem |
| 25 | 25 | */ |
| 26 | - public function filesystem(): Filesystem; |
|
| 26 | +public function filesystem(): Filesystem; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * Get the uploaded file type |
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function type(): string; |
|
| 33 | +public function type(): string; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * Get the uploaded file name, without the extension and slugified |
| 37 | 37 | * |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - public function name(): string; |
|
| 40 | +public function name(): string; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * Get the uploaded file name, with the extension |
| 44 | 44 | * |
| 45 | 45 | * @return string |
| 46 | 46 | */ |
| 47 | - public function filename(): string; |
|
| 47 | +public function filename(): string; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * Get the uploaded file path |
| 51 | 51 | * |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public function path(): string; |
|
| 54 | +public function path(): string; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * Get the uploaded file size |
| 58 | 58 | * |
| 59 | 59 | * @return int |
| 60 | 60 | */ |
| 61 | - public function size(): int; |
|
| 61 | +public function size(): int; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * Get the uploaded file extension |
| 65 | 65 | * |
| 66 | 66 | * @return string |
| 67 | 67 | */ |
| 68 | - public function extension(): string; |
|
| 68 | +public function extension(): string; |
|
| 69 | 69 | } |
@@ -175,62 +175,62 @@ |
||
| 175 | 175 | 0 => true, |
| 176 | 176 | 1 => isset($this->properties['attr']) || isset($this->properties['class']), |
| 177 | 177 | 2 => isset($this->properties['attr']) && isset($this->properties['class']), |
| 178 | - default => false, |
|
| 179 | - }; |
|
| 180 | - } |
|
| 178 | +default => false, |
|
| 179 | +}; |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * @return void |
| 184 | 184 | * @throws AnnotationException |
| 185 | 185 | */ |
| 186 | - private function parseProperties() |
|
| 187 | - { |
|
| 188 | - if(!$this->checkPropertiesNames()) |
|
| 189 | - { |
|
| 190 | - throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
|
| 191 | - } |
|
| 186 | +private function parseProperties() |
|
| 187 | +{ |
|
| 188 | +if(!$this->checkPropertiesNames()) |
|
| 189 | +{ |
|
| 190 | +throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - if(isset($this->properties['attr'])) |
|
| 194 | - { |
|
| 195 | - if(self::$xReader->annotationIsOnProperty()) |
|
| 196 | - { |
|
| 197 | - throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
|
| 198 | - } |
|
| 199 | - if(!is_string($this->properties['attr'])) |
|
| 200 | - { |
|
| 201 | - throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
|
| 202 | - } |
|
| 203 | - $this->sAttr = $this->properties['attr']; |
|
| 204 | - } |
|
| 205 | - if(isset($this->properties['class'])) |
|
| 206 | - { |
|
| 207 | - if(!is_string($this->properties['class'])) |
|
| 208 | - { |
|
| 209 | - throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
|
| 210 | - } |
|
| 211 | - $this->sClass = $this->getFullClassName($this->properties['class']); |
|
| 212 | - } |
|
| 213 | - } |
|
| 193 | +if(isset($this->properties['attr'])) |
|
| 194 | +{ |
|
| 195 | +if(self::$xReader->annotationIsOnProperty()) |
|
| 196 | +{ |
|
| 197 | + throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
|
| 198 | +} |
|
| 199 | +if(!is_string($this->properties['attr'])) |
|
| 200 | +{ |
|
| 201 | + throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
|
| 202 | +} |
|
| 203 | +$this->sAttr = $this->properties['attr']; |
|
| 204 | +} |
|
| 205 | +if(isset($this->properties['class'])) |
|
| 206 | +{ |
|
| 207 | +if(!is_string($this->properties['class'])) |
|
| 208 | +{ |
|
| 209 | + throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
|
| 210 | +} |
|
| 211 | +$this->sClass = $this->getFullClassName($this->properties['class']); |
|
| 212 | +} |
|
| 213 | +} |
|
| 214 | 214 | |
| 215 | - /** |
|
| 215 | +/** |
|
| 216 | 216 | * @inheritDoc |
| 217 | 217 | */ |
| 218 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 219 | - { |
|
| 220 | - isset($this->properties['__value__']) ? $this->parseValue() : $this->parseProperties(); |
|
| 218 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 219 | +{ |
|
| 220 | +isset($this->properties['__value__']) ? $this->parseValue() : $this->parseProperties(); |
|
| 221 | 221 | |
| 222 | - // The type in the @di annotations can be set from the values in the @var annotations |
|
| 223 | - $aPropTypes = self::$xReader->getPropTypes(); |
|
| 224 | - if($this->sClass === '') |
|
| 225 | - { |
|
| 226 | - if(!isset($aPropTypes[$this->sAttr])) |
|
| 227 | - { |
|
| 228 | - throw new AnnotationException('No class defined for @di on attribute "' . |
|
| 229 | - $this->sAttr . '".'); |
|
| 230 | - } |
|
| 231 | - $this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
|
| 232 | - } |
|
| 222 | +// The type in the @di annotations can be set from the values in the @var annotations |
|
| 223 | +$aPropTypes = self::$xReader->getPropTypes(); |
|
| 224 | +if($this->sClass === '') |
|
| 225 | +{ |
|
| 226 | +if(!isset($aPropTypes[$this->sAttr])) |
|
| 227 | +{ |
|
| 228 | + throw new AnnotationException('No class defined for @di on attribute "' . |
|
| 229 | + $this->sAttr . '".'); |
|
| 230 | +} |
|
| 231 | +$this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - $xMetadata->container($sMethod)->addValue($this->sAttr, $this->sClass); |
|
| 235 | - } |
|
| 234 | +$xMetadata->container($sMethod)->addValue($this->sAttr, $this->sClass); |
|
| 235 | +} |
|
| 236 | 236 | } |
@@ -23,19 +23,19 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class AfterAnnotation extends HookAnnotation |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @inheritDoc |
| 28 | 28 | */ |
| 29 | - protected static function getType(): string |
|
| 30 | - { |
|
| 31 | - return 'after'; |
|
| 32 | - } |
|
| 29 | +protected static function getType(): string |
|
| 30 | +{ |
|
| 31 | +return 'after'; |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | - { |
|
| 39 | - $xMetadata->after($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | - } |
|
| 37 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | +{ |
|
| 39 | +$xMetadata->after($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | +} |
|
| 41 | 41 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class CallbackAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The javascript object name |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sJsObject; |
|
| 36 | +protected $sJsObject; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public static function parseAnnotation($value) |
|
| 42 | - { |
|
| 43 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | - return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | - } |
|
| 41 | +public static function parseAnnotation($value) |
|
| 42 | +{ |
|
| 43 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 44 | +return count($aParams) === 1 ? ['name' => $aParams[0]] : ['name' => $aParams[0], 'extra' => $aParams[1]]; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @inheritDoc |
| 49 | 49 | * @throws AnnotationException |
| 50 | 50 | */ |
| 51 | - public function initAnnotation(array $properties) |
|
| 52 | - { |
|
| 53 | - if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | - { |
|
| 55 | - throw new AnnotationException('the @callback annotation requires a single string as property'); |
|
| 56 | - } |
|
| 57 | - $this->sJsObject = $properties['name']; |
|
| 58 | - } |
|
| 51 | +public function initAnnotation(array $properties) |
|
| 52 | +{ |
|
| 53 | +if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
| 54 | +{ |
|
| 55 | +throw new AnnotationException('the @callback annotation requires a single string as property'); |
|
| 56 | +} |
|
| 57 | +$this->sJsObject = $properties['name']; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @inheritDoc |
| 62 | 62 | */ |
| 63 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | - { |
|
| 65 | - $xMetadata->callback($sMethod)->addValue($this->sJsObject); |
|
| 66 | - } |
|
| 63 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | +{ |
|
| 65 | +$xMetadata->callback($sMethod)->addValue($this->sJsObject); |
|
| 66 | +} |
|
| 67 | 67 | } |
@@ -23,19 +23,19 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class BeforeAnnotation extends HookAnnotation |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @inheritDoc |
| 28 | 28 | */ |
| 29 | - protected static function getType(): string |
|
| 30 | - { |
|
| 31 | - return 'before'; |
|
| 32 | - } |
|
| 29 | +protected static function getType(): string |
|
| 30 | +{ |
|
| 31 | +return 'before'; |
|
| 32 | +} |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | - { |
|
| 39 | - $xMetadata->before($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | - } |
|
| 37 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 38 | +{ |
|
| 39 | +$xMetadata->before($sMethod)->addCall($this->sMethod, $this->aParams); |
|
| 40 | +} |
|
| 41 | 41 | } |
@@ -27,38 +27,38 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class ExcludeAnnotation extends AbstractAnnotation |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @var bool |
| 32 | 32 | */ |
| 33 | - protected $bValue; |
|
| 33 | +protected $bValue; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @inheritDoc |
| 37 | 37 | */ |
| 38 | - public static function parseAnnotation($value) |
|
| 39 | - { |
|
| 40 | - return [$value === 'true' ? true : ($value === 'false' ? false : $value)]; |
|
| 41 | - } |
|
| 38 | +public static function parseAnnotation($value) |
|
| 39 | +{ |
|
| 40 | +return [$value === 'true' ? true : ($value === 'false' ? false : $value)]; |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * @inheritDoc |
| 45 | 45 | * @throws AnnotationException |
| 46 | 46 | */ |
| 47 | - public function initAnnotation(array $properties) |
|
| 48 | - { |
|
| 49 | - if(count($properties) !== 0 && (count($properties) !== 1 |
|
| 50 | - || !isset($properties[0]) || !is_bool($properties[0]))) |
|
| 51 | - { |
|
| 52 | - throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); |
|
| 53 | - } |
|
| 54 | - $this->bValue = $properties[0] ?? true; |
|
| 55 | - } |
|
| 47 | +public function initAnnotation(array $properties) |
|
| 48 | +{ |
|
| 49 | +if(count($properties) !== 0 && (count($properties) !== 1 |
|
| 50 | +|| !isset($properties[0]) || !is_bool($properties[0]))) |
|
| 51 | +{ |
|
| 52 | +throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); |
|
| 53 | +} |
|
| 54 | +$this->bValue = $properties[0] ?? true; |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @inheritDoc |
| 59 | 59 | */ |
| 60 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 61 | - { |
|
| 62 | - $xMetadata->exclude($sMethod)->setValue($this->bValue); |
|
| 63 | - } |
|
| 60 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 61 | +{ |
|
| 62 | +$xMetadata->exclude($sMethod)->setValue($this->bValue); |
|
| 63 | +} |
|
| 64 | 64 | } |
@@ -27,64 +27,64 @@ |
||
| 27 | 27 | |
| 28 | 28 | abstract class HookAnnotation extends AbstractAnnotation |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @var string |
| 32 | 32 | */ |
| 33 | - protected $sMethod = ''; |
|
| 33 | +protected $sMethod = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - protected $aParams = []; |
|
| 38 | +protected $aParams = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * |
| 42 | 42 | */ |
| 43 | - abstract protected static function getType(): string; |
|
| 43 | +abstract protected static function getType(): string; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @inheritDoc |
| 47 | 47 | */ |
| 48 | - public static function parseAnnotation($value) |
|
| 49 | - { |
|
| 50 | - $aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | - if(count($aParams) === 1) |
|
| 52 | - { |
|
| 53 | - return ['call' => rtrim($aParams[0])]; |
|
| 54 | - } |
|
| 55 | - // The second parameter must be an array of callback parameter in json format. |
|
| 56 | - return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | - } |
|
| 48 | +public static function parseAnnotation($value) |
|
| 49 | +{ |
|
| 50 | +$aParams = preg_split('/[\s]+/', $value, 2); |
|
| 51 | +if(count($aParams) === 1) |
|
| 52 | +{ |
|
| 53 | +return ['call' => rtrim($aParams[0])]; |
|
| 54 | +} |
|
| 55 | +// The second parameter must be an array of callback parameter in json format. |
|
| 56 | +return ['call' => rtrim($aParams[0]), 'with' => json_decode($aParams[1], false)]; |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | * @throws AnnotationException |
| 62 | 62 | */ |
| 63 | - public function initAnnotation(array $properties) |
|
| 64 | - { |
|
| 65 | - if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | - { |
|
| 67 | - throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | - ' annotation requires a property "call" of type string'); |
|
| 69 | - } |
|
| 70 | - foreach(array_keys($properties) as $propName) |
|
| 71 | - { |
|
| 72 | - if($propName !== 'call' && $propName !== 'with') |
|
| 73 | - { |
|
| 74 | - throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | - '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - // Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | - if(array_key_exists('with', $properties)) |
|
| 80 | - { |
|
| 81 | - if(!is_array($properties['with'])) |
|
| 82 | - { |
|
| 83 | - throw new AnnotationException('The "with" property of the @' . |
|
| 84 | - $this->getType() . ' annotation must be of type array'); |
|
| 85 | - } |
|
| 86 | - $this->aParams = $properties['with']; |
|
| 87 | - } |
|
| 88 | - $this->sMethod = $properties['call']; |
|
| 89 | - } |
|
| 63 | +public function initAnnotation(array $properties) |
|
| 64 | +{ |
|
| 65 | +if(!isset($properties['call']) || !is_string($properties['call'])) |
|
| 66 | +{ |
|
| 67 | +throw new AnnotationException('The @' . $this->getType() . |
|
| 68 | + ' annotation requires a property "call" of type string'); |
|
| 69 | +} |
|
| 70 | +foreach(array_keys($properties) as $propName) |
|
| 71 | +{ |
|
| 72 | +if($propName !== 'call' && $propName !== 'with') |
|
| 73 | +{ |
|
| 74 | + throw new AnnotationException('Unknown property "' . $propName . |
|
| 75 | + '" in the @' . $this->getType() . ' annotation'); |
|
| 76 | +} |
|
| 77 | +} |
|
| 78 | +// Cannot use isset here, because it will return false in case $properties['with'] === null |
|
| 79 | +if(array_key_exists('with', $properties)) |
|
| 80 | +{ |
|
| 81 | +if(!is_array($properties['with'])) |
|
| 82 | +{ |
|
| 83 | + throw new AnnotationException('The "with" property of the @' . |
|
| 84 | + $this->getType() . ' annotation must be of type array'); |
|
| 85 | +} |
|
| 86 | +$this->aParams = $properties['with']; |
|
| 87 | +} |
|
| 88 | +$this->sMethod = $properties['call']; |
|
| 89 | +} |
|
| 90 | 90 | } |
@@ -30,16 +30,16 @@ |
||
| 30 | 30 | |
| 31 | 31 | abstract class AbstractRequestPlugin extends AbstractPlugin implements CallableRegistryInterface, RequestHandlerInterface |
| 32 | 32 | { |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * @var Target |
| 35 | 35 | */ |
| 36 | - protected $xTarget = null; |
|
| 36 | +protected $xTarget = null; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @inheritDoc |
| 40 | 40 | */ |
| 41 | - public function getTarget(): ?Target |
|
| 42 | - { |
|
| 43 | - return $this->xTarget; |
|
| 44 | - } |
|
| 41 | +public function getTarget(): ?Target |
|
| 42 | +{ |
|
| 43 | +return $this->xTarget; |
|
| 44 | +} |
|
| 45 | 45 | } |