@@ -28,60 +28,60 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class MetadataCache |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @param string $sCacheDir |
| 33 | 33 | */ |
| 34 | - public function __construct(private string $sCacheDir) |
|
| 35 | - {} |
|
| 34 | +public function __construct(private string $sCacheDir) |
|
| 35 | +{} |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @param string $sClass |
| 39 | 39 | * |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - private function filepath(string $sClass): string |
|
| 43 | - { |
|
| 44 | - $sFilename = trim(str_replace(['\\', '.'], DIRECTORY_SEPARATOR, |
|
| 45 | - strtolower($sClass)), DIRECTORY_SEPARATOR); |
|
| 46 | - return rtrim($this->sCacheDir, "/\\") . DIRECTORY_SEPARATOR . |
|
| 47 | - "metadata" . DIRECTORY_SEPARATOR . "{$sFilename}.php"; |
|
| 48 | - } |
|
| 42 | +private function filepath(string $sClass): string |
|
| 43 | +{ |
|
| 44 | +$sFilename = trim(str_replace(['\\', '.'], DIRECTORY_SEPARATOR, |
|
| 45 | +strtolower($sClass)), DIRECTORY_SEPARATOR); |
|
| 46 | +return rtrim($this->sCacheDir, "/\\") . DIRECTORY_SEPARATOR . |
|
| 47 | +"metadata" . DIRECTORY_SEPARATOR . "{$sFilename}.php"; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * Generate the PHP code to create a metadata object. |
| 52 | 52 | * |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - private function encode(Metadata $xMetadata): array |
|
| 55 | +private function encode(Metadata $xMetadata): array |
|
| 56 | +{ |
|
| 57 | +$sMetadataVar = '$xMetadata'; |
|
| 58 | +$sDataVar = '$xData'; |
|
| 59 | +$aCalls = ["$sMetadataVar = new " . Metadata::class . '();']; |
|
| 60 | +foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 61 | +{ |
|
| 62 | +foreach($aValues as $sMethod => $xData) |
|
| 63 | +{ |
|
| 64 | + $aCalls[] = "$sDataVar = {$sMetadataVar}->{$sType}('{$sMethod}');"; |
|
| 65 | + foreach($xData->encode($sDataVar) as $sCall) |
|
| 56 | 66 | { |
| 57 | - $sMetadataVar = '$xMetadata'; |
|
| 58 | - $sDataVar = '$xData'; |
|
| 59 | - $aCalls = ["$sMetadataVar = new " . Metadata::class . '();']; |
|
| 60 | - foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 61 | - { |
|
| 62 | - foreach($aValues as $sMethod => $xData) |
|
| 63 | - { |
|
| 64 | - $aCalls[] = "$sDataVar = {$sMetadataVar}->{$sType}('{$sMethod}');"; |
|
| 65 | - foreach($xData->encode($sDataVar) as $sCall) |
|
| 66 | - { |
|
| 67 | - $aCalls[] = $sCall; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - $aCalls[] = "return $sMetadataVar;"; |
|
| 72 | - return $aCalls; |
|
| 67 | + $aCalls[] = $sCall; |
|
| 73 | 68 | } |
| 69 | +} |
|
| 70 | +} |
|
| 71 | +$aCalls[] = "return $sMetadataVar;"; |
|
| 72 | +return $aCalls; |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @param string $sClass |
| 77 | 77 | * @param Metadata $xMetadata |
| 78 | 78 | * |
| 79 | 79 | * @return void |
| 80 | 80 | */ |
| 81 | - public function save(string $sClass, Metadata $xMetadata): void |
|
| 82 | - { |
|
| 83 | - $sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 84 | - $sPhpCode = <<<CODE |
|
| 81 | +public function save(string $sClass, Metadata $xMetadata): void |
|
| 82 | +{ |
|
| 83 | +$sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 84 | +$sPhpCode = <<<CODE |
|
| 85 | 85 | <?php |
| 86 | 86 | |
| 87 | 87 | return function() { |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | CODE; |
| 92 | - // Recursively create the directories. |
|
| 93 | - $sPath = $this->filepath($sClass); |
|
| 94 | - @mkdir(dirname($sPath), 0755, true); |
|
| 95 | - file_put_contents($sPath, $sPhpCode); |
|
| 96 | - } |
|
| 92 | +// Recursively create the directories. |
|
| 93 | +$sPath = $this->filepath($sClass); |
|
| 94 | +@mkdir(dirname($sPath), 0755, true); |
|
| 95 | +file_put_contents($sPath, $sPhpCode); |
|
| 96 | +} |
|
| 97 | 97 | |
| 98 | - /** |
|
| 98 | +/** |
|
| 99 | 99 | * @param string $sClass |
| 100 | 100 | * |
| 101 | 101 | * @return Metadata|null |
| 102 | 102 | */ |
| 103 | - public function read(string $sClass): ?Metadata |
|
| 104 | - { |
|
| 105 | - $sPath = $this->filepath($sClass); |
|
| 106 | - $fCreator = file_exists($sPath) ? require $sPath : null; |
|
| 107 | - return $fCreator instanceof Closure ? $fCreator() : null; |
|
| 108 | - } |
|
| 103 | +public function read(string $sClass): ?Metadata |
|
| 104 | +{ |
|
| 105 | +$sPath = $this->filepath($sClass); |
|
| 106 | +$fCreator = file_exists($sPath) ? require $sPath : null; |
|
| 107 | +return $fCreator instanceof Closure ? $fCreator() : null; |
|
| 108 | +} |
|
| 109 | 109 | } |
@@ -20,45 +20,45 @@ |
||
| 20 | 20 | |
| 21 | 21 | interface UploadHandlerInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Set the uploaded file name sanitizer |
| 25 | 25 | * |
| 26 | 26 | * @param Closure $cSanitizer The closure |
| 27 | 27 | * |
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | - public function sanitizer(Closure $cSanitizer); |
|
| 30 | +public function sanitizer(Closure $cSanitizer); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * Get the uploaded files |
| 34 | 34 | * |
| 35 | 35 | * @return FileInterface[] |
| 36 | 36 | */ |
| 37 | - public function files(): array; |
|
| 37 | +public function files(): array; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * Check if the current request contains uploaded files |
| 41 | 41 | * |
| 42 | 42 | * @param ServerRequestInterface $xRequest |
| 43 | 43 | * |
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | - public function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 46 | +public function canProcessRequest(ServerRequestInterface $xRequest): bool; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Process the uploaded files in the HTTP request |
| 50 | 50 | * |
| 51 | 51 | * @param ServerRequestInterface $xRequest |
| 52 | 52 | * |
| 53 | 53 | * @return bool |
| 54 | 54 | */ |
| 55 | - public function processRequest(ServerRequestInterface $xRequest): bool; |
|
| 55 | +public function processRequest(ServerRequestInterface $xRequest): bool; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @param string $sStorage |
| 59 | 59 | * @param Closure $cFactory |
| 60 | 60 | * |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - public function registerStorageAdapter(string $sStorage, Closure $cFactory); |
|
| 63 | +public function registerStorageAdapter(string $sStorage, Closure $cFactory); |
|
| 64 | 64 | } |
@@ -16,23 +16,23 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Jaxon |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @const string |
| 21 | 21 | */ |
| 22 | - public const VERSION = 'Jaxon 5.x'; |
|
| 22 | +public const VERSION = 'Jaxon 5.x'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @const string |
| 26 | 26 | */ |
| 27 | - public const CALLABLE_CLASS = 'CallableClass'; |
|
| 27 | +public const CALLABLE_CLASS = 'CallableClass'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @const string |
| 31 | 31 | */ |
| 32 | - public const CALLABLE_DIR = 'CallableDir'; |
|
| 32 | +public const CALLABLE_DIR = 'CallableDir'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @const string |
| 36 | 36 | */ |
| 37 | - public const CALLABLE_FUNCTION = 'CallableFunction'; |
|
| 37 | +public const CALLABLE_FUNCTION = 'CallableFunction'; |
|
| 38 | 38 | } |
@@ -17,56 +17,56 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | class Target implements TargetInterface |
| 19 | 19 | { |
| 20 | - /** |
|
| 20 | +/** |
|
| 21 | 21 | * The target type for function. |
| 22 | 22 | * |
| 23 | 23 | * @var string |
| 24 | 24 | */ |
| 25 | - const TYPE_FUNCTION = 'TargetFunction'; |
|
| 25 | +const TYPE_FUNCTION = 'TargetFunction'; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * The target type for class. |
| 29 | 29 | * |
| 30 | 30 | * @var string |
| 31 | 31 | */ |
| 32 | - const TYPE_CLASS = 'TargetClass'; |
|
| 32 | +const TYPE_CLASS = 'TargetClass'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * The target type. |
| 36 | 36 | * |
| 37 | 37 | * @var string |
| 38 | 38 | */ |
| 39 | - private $sType = ''; |
|
| 39 | +private $sType = ''; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * The target function name. |
| 43 | 43 | * |
| 44 | 44 | * @var string |
| 45 | 45 | */ |
| 46 | - private $sFunctionName = ''; |
|
| 46 | +private $sFunctionName = ''; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * The target class name. |
| 50 | 50 | * |
| 51 | 51 | * @var string |
| 52 | 52 | */ |
| 53 | - private $sClassName = ''; |
|
| 53 | +private $sClassName = ''; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * The target method name. |
| 57 | 57 | * |
| 58 | 58 | * @var string |
| 59 | 59 | */ |
| 60 | - private $sMethodName = ''; |
|
| 60 | +private $sMethodName = ''; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * The target method args. |
| 64 | 64 | * |
| 65 | 65 | * @var array |
| 66 | 66 | */ |
| 67 | - private $aMethodArgs = []; |
|
| 67 | +private $aMethodArgs = []; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * The constructor |
| 71 | 71 | * |
| 72 | 72 | * @param string $sType The target type |
@@ -75,116 +75,116 @@ discard block |
||
| 75 | 75 | * @param string $sMethodName The method name |
| 76 | 76 | * @param array $aMethodArgs The method args |
| 77 | 77 | */ |
| 78 | - private function __construct(string $sType, string $sFunctionName, string $sClassName, string $sMethodName, array $aMethodArgs = []) |
|
| 79 | - { |
|
| 80 | - $this->sType = $sType; |
|
| 81 | - $this->sFunctionName = $sFunctionName; |
|
| 82 | - $this->sClassName = $sClassName; |
|
| 83 | - $this->sMethodName = $sMethodName; |
|
| 84 | - $this->aMethodArgs = $aMethodArgs; |
|
| 85 | - } |
|
| 78 | +private function __construct(string $sType, string $sFunctionName, string $sClassName, string $sMethodName, array $aMethodArgs = []) |
|
| 79 | +{ |
|
| 80 | +$this->sType = $sType; |
|
| 81 | +$this->sFunctionName = $sFunctionName; |
|
| 82 | +$this->sClassName = $sClassName; |
|
| 83 | +$this->sMethodName = $sMethodName; |
|
| 84 | +$this->aMethodArgs = $aMethodArgs; |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * Create a target of type Function |
| 89 | 89 | * |
| 90 | 90 | * @param string $sFunctionName The function name |
| 91 | 91 | * |
| 92 | 92 | * @return Target |
| 93 | 93 | */ |
| 94 | - public static function makeFunction(string $sFunctionName): Target |
|
| 95 | - { |
|
| 96 | - return new Target(self::TYPE_FUNCTION, $sFunctionName, '', ''); |
|
| 97 | - } |
|
| 94 | +public static function makeFunction(string $sFunctionName): Target |
|
| 95 | +{ |
|
| 96 | +return new Target(self::TYPE_FUNCTION, $sFunctionName, '', ''); |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * Create a target of type Class |
| 101 | 101 | * |
| 102 | 102 | * @param array $aCall |
| 103 | 103 | * |
| 104 | 104 | * @return Target |
| 105 | 105 | */ |
| 106 | - public static function makeClass(array $aCall): Target |
|
| 107 | - { |
|
| 108 | - return new Target(self::TYPE_CLASS, '', trim($aCall['name']), trim($aCall['method'])); |
|
| 109 | - } |
|
| 106 | +public static function makeClass(array $aCall): Target |
|
| 107 | +{ |
|
| 108 | +return new Target(self::TYPE_CLASS, '', trim($aCall['name']), trim($aCall['method'])); |
|
| 109 | +} |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | +/** |
|
| 112 | 112 | * Check if the target type is Function. |
| 113 | 113 | * |
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | - public function isFunction(): bool |
|
| 117 | - { |
|
| 118 | - return $this->sType === self::TYPE_FUNCTION; |
|
| 119 | - } |
|
| 116 | +public function isFunction(): bool |
|
| 117 | +{ |
|
| 118 | +return $this->sType === self::TYPE_FUNCTION; |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Check if the target type is Class. |
| 123 | 123 | * |
| 124 | 124 | * @return bool |
| 125 | 125 | */ |
| 126 | - public function isClass(): bool |
|
| 127 | - { |
|
| 128 | - return $this->sType === self::TYPE_CLASS; |
|
| 129 | - } |
|
| 126 | +public function isClass(): bool |
|
| 127 | +{ |
|
| 128 | +return $this->sType === self::TYPE_CLASS; |
|
| 129 | +} |
|
| 130 | 130 | |
| 131 | - /** |
|
| 131 | +/** |
|
| 132 | 132 | * The target function name. |
| 133 | 133 | * |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function getFunctionName(): string |
|
| 137 | - { |
|
| 138 | - return $this->sFunctionName; |
|
| 139 | - } |
|
| 136 | +public function getFunctionName(): string |
|
| 137 | +{ |
|
| 138 | +return $this->sFunctionName; |
|
| 139 | +} |
|
| 140 | 140 | |
| 141 | - /** |
|
| 141 | +/** |
|
| 142 | 142 | * The target class name. |
| 143 | 143 | * |
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | - public function getClassName(): string |
|
| 147 | - { |
|
| 148 | - return $this->sClassName; |
|
| 149 | - } |
|
| 146 | +public function getClassName(): string |
|
| 147 | +{ |
|
| 148 | +return $this->sClassName; |
|
| 149 | +} |
|
| 150 | 150 | |
| 151 | - /** |
|
| 151 | +/** |
|
| 152 | 152 | * The target method name. |
| 153 | 153 | * |
| 154 | 154 | * @return string |
| 155 | 155 | */ |
| 156 | - public function getMethodName(): string |
|
| 157 | - { |
|
| 158 | - return $this->sMethodName; |
|
| 159 | - } |
|
| 156 | +public function getMethodName(): string |
|
| 157 | +{ |
|
| 158 | +return $this->sMethodName; |
|
| 159 | +} |
|
| 160 | 160 | |
| 161 | - /** |
|
| 161 | +/** |
|
| 162 | 162 | * Set the target method name. |
| 163 | 163 | * |
| 164 | 164 | * @param array $aMethodArgs |
| 165 | 165 | */ |
| 166 | - public function setMethodArgs(array $aMethodArgs): void |
|
| 167 | - { |
|
| 168 | - $this->aMethodArgs = $aMethodArgs; |
|
| 169 | - } |
|
| 166 | +public function setMethodArgs(array $aMethodArgs): void |
|
| 167 | +{ |
|
| 168 | +$this->aMethodArgs = $aMethodArgs; |
|
| 169 | +} |
|
| 170 | 170 | |
| 171 | - /** |
|
| 171 | +/** |
|
| 172 | 172 | * The target method name. |
| 173 | 173 | * |
| 174 | 174 | * @return string |
| 175 | 175 | */ |
| 176 | - public function method(): string |
|
| 177 | - { |
|
| 178 | - return $this->sMethodName; |
|
| 179 | - } |
|
| 176 | +public function method(): string |
|
| 177 | +{ |
|
| 178 | +return $this->sMethodName; |
|
| 179 | +} |
|
| 180 | 180 | |
| 181 | - /** |
|
| 181 | +/** |
|
| 182 | 182 | * The target method args. |
| 183 | 183 | * |
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - public function args(): array |
|
| 187 | - { |
|
| 188 | - return $this->aMethodArgs; |
|
| 189 | - } |
|
| 186 | +public function args(): array |
|
| 187 | +{ |
|
| 188 | +return $this->aMethodArgs; |
|
| 189 | +} |
|
| 190 | 190 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class DatabagAnnotation extends AbstractAnnotation |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The data bag name |
| 33 | 33 | * |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - protected $sName = ''; |
|
| 36 | +protected $sName = ''; |
|
| 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 @databag annotation requires a property "name" of type string'); |
|
| 56 | - } |
|
| 57 | - $this->sName = $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 @databag annotation requires a property "name" of type string'); |
|
| 56 | +} |
|
| 57 | +$this->sName = $properties['name']; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @inheritDoc |
| 62 | 62 | */ |
| 63 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | - { |
|
| 65 | - $xMetadata->databag($sMethod)->addValue($this->sName); |
|
| 66 | - } |
|
| 63 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 64 | +{ |
|
| 65 | +$xMetadata->databag($sMethod)->addValue($this->sName); |
|
| 66 | +} |
|
| 67 | 67 | } |
@@ -4,58 +4,58 @@ |
||
| 4 | 4 | |
| 5 | 5 | class DatabagContext |
| 6 | 6 | { |
| 7 | - /** |
|
| 7 | +/** |
|
| 8 | 8 | * @var Databag |
| 9 | 9 | */ |
| 10 | - protected $xDatabag; |
|
| 10 | +protected $xDatabag; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * @var string |
| 14 | 14 | */ |
| 15 | - protected $sName; |
|
| 15 | +protected $sName; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * The constructor |
| 19 | 19 | * |
| 20 | 20 | * @param Databag $xDatabag |
| 21 | 21 | * @param string $sName |
| 22 | 22 | */ |
| 23 | - public function __construct(Databag $xDatabag, string $sName) |
|
| 24 | - { |
|
| 25 | - $this->xDatabag = $xDatabag; |
|
| 26 | - $this->sName = $sName; |
|
| 27 | - } |
|
| 23 | +public function __construct(Databag $xDatabag, string $sName) |
|
| 24 | +{ |
|
| 25 | +$this->xDatabag = $xDatabag; |
|
| 26 | +$this->sName = $sName; |
|
| 27 | +} |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @param string $sKey |
| 31 | 31 | * @param mixed $xValue |
| 32 | 32 | * |
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | - public function set(string $sKey, $xValue): void |
|
| 36 | - { |
|
| 37 | - $this->xDatabag->set($this->sName, $sKey, $xValue); |
|
| 38 | - } |
|
| 35 | +public function set(string $sKey, $xValue): void |
|
| 36 | +{ |
|
| 37 | +$this->xDatabag->set($this->sName, $sKey, $xValue); |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @param string $sKey |
| 42 | 42 | * @param mixed $xValue |
| 43 | 43 | * |
| 44 | 44 | * @return void |
| 45 | 45 | */ |
| 46 | - public function new(string $sKey, $xValue): void |
|
| 47 | - { |
|
| 48 | - $this->xDatabag->new($this->sName, $sKey, $xValue); |
|
| 49 | - } |
|
| 46 | +public function new(string $sKey, $xValue): void |
|
| 47 | +{ |
|
| 48 | +$this->xDatabag->new($this->sName, $sKey, $xValue); |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * @param string $sKey |
| 53 | 53 | * @param mixed $xValue |
| 54 | 54 | * |
| 55 | 55 | * @return mixed |
| 56 | 56 | */ |
| 57 | - public function get(string $sKey, $xValue = null): mixed |
|
| 58 | - { |
|
| 59 | - return $this->xDatabag->get($this->sName, $sKey, $xValue); |
|
| 60 | - } |
|
| 57 | +public function get(string $sKey, $xValue = null): mixed |
|
| 58 | +{ |
|
| 59 | +return $this->xDatabag->get($this->sName, $sKey, $xValue); |
|
| 60 | +} |
|
| 61 | 61 | } |
@@ -11,110 +11,110 @@ |
||
| 11 | 11 | |
| 12 | 12 | class Databag implements JsonSerializable |
| 13 | 13 | { |
| 14 | - /** |
|
| 14 | +/** |
|
| 15 | 15 | * @var DatabagPlugin |
| 16 | 16 | */ |
| 17 | - protected $xPlugin; |
|
| 17 | +protected $xPlugin; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var array |
| 21 | 21 | */ |
| 22 | - protected $aData = []; |
|
| 22 | +protected $aData = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var bool |
| 26 | 26 | */ |
| 27 | - protected $bTouched = false; |
|
| 27 | +protected $bTouched = false; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The constructor |
| 31 | 31 | * |
| 32 | 32 | * @param array $aData |
| 33 | 33 | */ |
| 34 | - public function __construct(DatabagPlugin $xPlugin, array $aData) |
|
| 35 | - { |
|
| 36 | - $this->xPlugin = $xPlugin; |
|
| 37 | - // Ensure all contents are arrays. |
|
| 38 | - $this->aData = array_map(function($aValue) { |
|
| 39 | - return is_array($aValue) ? $aValue : []; |
|
| 40 | - }, $aData); |
|
| 41 | - } |
|
| 34 | +public function __construct(DatabagPlugin $xPlugin, array $aData) |
|
| 35 | +{ |
|
| 36 | +$this->xPlugin = $xPlugin; |
|
| 37 | +// Ensure all contents are arrays. |
|
| 38 | +$this->aData = array_map(function($aValue) { |
|
| 39 | +return is_array($aValue) ? $aValue : []; |
|
| 40 | +}, $aData); |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | - public function touched(): bool |
|
| 47 | - { |
|
| 48 | - return $this->bTouched; |
|
| 49 | - } |
|
| 46 | +public function touched(): bool |
|
| 47 | +{ |
|
| 48 | +return $this->bTouched; |
|
| 49 | +} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * @return array |
| 53 | 53 | */ |
| 54 | - public function getAll(): array |
|
| 55 | - { |
|
| 56 | - return $this->aData; |
|
| 57 | - } |
|
| 54 | +public function getAll(): array |
|
| 55 | +{ |
|
| 56 | +return $this->aData; |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @param string $sBag |
| 61 | 61 | * |
| 62 | 62 | * @return void |
| 63 | 63 | */ |
| 64 | - public function clear(string $sBag): void |
|
| 65 | - { |
|
| 66 | - $this->aData[$sBag] = []; |
|
| 67 | - $this->xPlugin->addCommand('databag.clear', ['bag' => $sBag]); |
|
| 68 | - } |
|
| 64 | +public function clear(string $sBag): void |
|
| 65 | +{ |
|
| 66 | +$this->aData[$sBag] = []; |
|
| 67 | +$this->xPlugin->addCommand('databag.clear', ['bag' => $sBag]); |
|
| 68 | +} |
|
| 69 | 69 | |
| 70 | - /** |
|
| 70 | +/** |
|
| 71 | 71 | * @param string $sBag |
| 72 | 72 | * @param string $sKey |
| 73 | 73 | * @param mixed $xValue |
| 74 | 74 | * |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function set(string $sBag, string $sKey, $xValue): void |
|
| 78 | - { |
|
| 79 | - $this->bTouched = true; |
|
| 80 | - $this->aData[$sBag][$sKey] = $xValue; |
|
| 81 | - } |
|
| 77 | +public function set(string $sBag, string $sKey, $xValue): void |
|
| 78 | +{ |
|
| 79 | +$this->bTouched = true; |
|
| 80 | +$this->aData[$sBag][$sKey] = $xValue; |
|
| 81 | +} |
|
| 82 | 82 | |
| 83 | - /** |
|
| 83 | +/** |
|
| 84 | 84 | * @param string $sBag |
| 85 | 85 | * @param string $sKey |
| 86 | 86 | * @param mixed $xValue |
| 87 | 87 | * |
| 88 | 88 | * @return void |
| 89 | 89 | */ |
| 90 | - public function new(string $sBag, string $sKey, $xValue): void |
|
| 91 | - { |
|
| 92 | - // Set the value only if it doesn't already exist. |
|
| 93 | - if(!isset($this->aData[$sBag]) || !key_exists($sKey, $this->aData[$sBag])) |
|
| 94 | - { |
|
| 95 | - $this->set($sBag, $sKey, $xValue); |
|
| 96 | - } |
|
| 97 | - } |
|
| 90 | +public function new(string $sBag, string $sKey, $xValue): void |
|
| 91 | +{ |
|
| 92 | +// Set the value only if it doesn't already exist. |
|
| 93 | +if(!isset($this->aData[$sBag]) || !key_exists($sKey, $this->aData[$sBag])) |
|
| 94 | +{ |
|
| 95 | +$this->set($sBag, $sKey, $xValue); |
|
| 96 | +} |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * @param string $sBag |
| 101 | 101 | * @param string $sKey |
| 102 | 102 | * @param mixed $xValue |
| 103 | 103 | * |
| 104 | 104 | * @return mixed |
| 105 | 105 | */ |
| 106 | - public function get(string $sBag, string $sKey, $xValue = null): mixed |
|
| 107 | - { |
|
| 108 | - return $this->aData[$sBag][$sKey] ?? $xValue; |
|
| 109 | - } |
|
| 106 | +public function get(string $sBag, string $sKey, $xValue = null): mixed |
|
| 107 | +{ |
|
| 108 | +return $this->aData[$sBag][$sKey] ?? $xValue; |
|
| 109 | +} |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | +/** |
|
| 112 | 112 | * Convert this call to array, when converting the response into json. |
| 113 | 113 | * |
| 114 | 114 | * @return array |
| 115 | 115 | */ |
| 116 | - public function jsonSerialize(): array |
|
| 117 | - { |
|
| 118 | - return $this->aData; |
|
| 119 | - } |
|
| 116 | +public function jsonSerialize(): array |
|
| 117 | +{ |
|
| 118 | +return $this->aData; |
|
| 119 | +} |
|
| 120 | 120 | } |
@@ -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 | } |