@@ -16,42 +16,42 @@ |
||
| 16 | 16 | |
| 17 | 17 | class ExcludeData extends AbstractData |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var bool |
| 21 | 21 | */ |
| 22 | - private bool $bValue = true; |
|
| 22 | +private bool $bValue = true; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | - public function getName(): string |
|
| 28 | - { |
|
| 29 | - return 'protected'; |
|
| 30 | - } |
|
| 27 | +public function getName(): string |
|
| 28 | +{ |
|
| 29 | +return 'protected'; |
|
| 30 | +} |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return mixed |
| 34 | 34 | */ |
| 35 | - public function getValue(): mixed |
|
| 36 | - { |
|
| 37 | - return $this->bValue; |
|
| 38 | - } |
|
| 35 | +public function getValue(): mixed |
|
| 36 | +{ |
|
| 37 | +return $this->bValue; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @param bool $bValue |
| 42 | 42 | * |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public function setValue(bool $bValue): void |
|
| 46 | - { |
|
| 47 | - $this->bValue = $bValue; |
|
| 48 | - } |
|
| 45 | +public function setValue(bool $bValue): void |
|
| 46 | +{ |
|
| 47 | +$this->bValue = $bValue; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * @inheritDoc |
| 52 | 52 | */ |
| 53 | - public function encode(string $sVarName): array |
|
| 54 | - { |
|
| 55 | - return ["{$sVarName}->setValue(" . ($this->bValue ? 'true' : 'false') . ");"]; |
|
| 56 | - } |
|
| 53 | +public function encode(string $sVarName): array |
|
| 54 | +{ |
|
| 55 | +return ["{$sVarName}->setValue(" . ($this->bValue ? 'true' : 'false') . ");"]; |
|
| 56 | +} |
|
| 57 | 57 | } |
@@ -20,61 +20,61 @@ |
||
| 20 | 20 | |
| 21 | 21 | class UploadData extends AbstractData |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * The id of the upload field |
| 25 | 25 | * |
| 26 | 26 | * @var string |
| 27 | 27 | */ |
| 28 | - protected $sField = ''; |
|
| 28 | +protected $sField = ''; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function getName(): string |
|
| 34 | - { |
|
| 35 | - return 'upload'; |
|
| 36 | - } |
|
| 33 | +public function getName(): string |
|
| 34 | +{ |
|
| 35 | +return 'upload'; |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @return mixed |
| 40 | 40 | */ |
| 41 | - public function getValue(): mixed |
|
| 42 | - { |
|
| 43 | - // The field id is surrounded with simple quotes. |
|
| 44 | - return "'{$this->sField}'"; |
|
| 45 | - } |
|
| 41 | +public function getValue(): mixed |
|
| 42 | +{ |
|
| 43 | +// The field id is surrounded with simple quotes. |
|
| 44 | +return "'{$this->sField}'"; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @param string $sField |
| 49 | 49 | * |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - protected function validateField(string $sField): void |
|
| 53 | - { |
|
| 54 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sField) > 0) |
|
| 55 | - { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - throw new SetupException("$sField is not a valid \"field\" value for upload"); |
|
| 59 | - } |
|
| 52 | +protected function validateField(string $sField): void |
|
| 53 | +{ |
|
| 54 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sField) > 0) |
|
| 55 | +{ |
|
| 56 | +return; |
|
| 57 | +} |
|
| 58 | +throw new SetupException("$sField is not a valid \"field\" value for upload"); |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @param string $sField |
| 63 | 63 | * |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - public function setValue(string $sField): void |
|
| 67 | - { |
|
| 68 | - $this->validateField($sField); |
|
| 66 | +public function setValue(string $sField): void |
|
| 67 | +{ |
|
| 68 | +$this->validateField($sField); |
|
| 69 | 69 | |
| 70 | - $this->sField = $sField; |
|
| 71 | - } |
|
| 70 | +$this->sField = $sField; |
|
| 71 | +} |
|
| 72 | 72 | |
| 73 | - /** |
|
| 73 | +/** |
|
| 74 | 74 | * @inheritDoc |
| 75 | 75 | */ |
| 76 | - public function encode(string $sVarName): array |
|
| 77 | - { |
|
| 78 | - return ["{$sVarName}->setValue('{$this->sField}');"]; |
|
| 79 | - } |
|
| 76 | +public function encode(string $sVarName): array |
|
| 77 | +{ |
|
| 78 | +return ["{$sVarName}->setValue('{$this->sField}');"]; |
|
| 79 | +} |
|
| 80 | 80 | } |
@@ -21,81 +21,81 @@ |
||
| 21 | 21 | |
| 22 | 22 | class ContainerData extends AbstractData |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * The properties to get from the container |
| 26 | 26 | * |
| 27 | 27 | * @var string |
| 28 | 28 | */ |
| 29 | - protected $aProperties = []; |
|
| 29 | +protected $aProperties = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function getName(): string |
|
| 35 | - { |
|
| 36 | - return '__di'; |
|
| 37 | - } |
|
| 34 | +public function getName(): string |
|
| 35 | +{ |
|
| 36 | +return '__di'; |
|
| 37 | +} |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @return mixed |
| 41 | 41 | */ |
| 42 | - public function getValue(): mixed |
|
| 43 | - { |
|
| 44 | - return $this->aProperties; |
|
| 45 | - } |
|
| 42 | +public function getValue(): mixed |
|
| 43 | +{ |
|
| 44 | +return $this->aProperties; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @param string $sAttr |
| 49 | 49 | * |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - protected function validateAttr(string $sAttr): void |
|
| 53 | - { |
|
| 54 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 55 | - { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - throw new SetupException("$sAttr is not a valid \"attr\" value for di"); |
|
| 59 | - } |
|
| 52 | +protected function validateAttr(string $sAttr): void |
|
| 53 | +{ |
|
| 54 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 55 | +{ |
|
| 56 | +return; |
|
| 57 | +} |
|
| 58 | +throw new SetupException("$sAttr is not a valid \"attr\" value for di"); |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @param string $sClass |
| 63 | 63 | * |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - protected function validateClass(string $sClass): void |
|
| 67 | - { |
|
| 68 | - if(preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 69 | - { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - throw new SetupException("$sClass is not a valid \"class\" value for di"); |
|
| 73 | - } |
|
| 66 | +protected function validateClass(string $sClass): void |
|
| 67 | +{ |
|
| 68 | +if(preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 69 | +{ |
|
| 70 | +return; |
|
| 71 | +} |
|
| 72 | +throw new SetupException("$sClass is not a valid \"class\" value for di"); |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @param string $sAttr |
| 77 | 77 | * @param string $sClass |
| 78 | 78 | * |
| 79 | 79 | * @return void |
| 80 | 80 | */ |
| 81 | - public function addValue(string $sAttr, string $sClass): void |
|
| 82 | - { |
|
| 83 | - $this->validateAttr($sAttr); |
|
| 84 | - $this->validateClass($sClass); |
|
| 81 | +public function addValue(string $sAttr, string $sClass): void |
|
| 82 | +{ |
|
| 83 | +$this->validateAttr($sAttr); |
|
| 84 | +$this->validateClass($sClass); |
|
| 85 | 85 | |
| 86 | - $this->aProperties[$sAttr] = $sClass; |
|
| 87 | - } |
|
| 86 | +$this->aProperties[$sAttr] = $sClass; |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * @inheritDoc |
| 91 | 91 | */ |
| 92 | - public function encode(string $sVarName): array |
|
| 93 | - { |
|
| 94 | - $aCalls = []; |
|
| 95 | - foreach($this->aProperties as $sAttr => $sClass) |
|
| 96 | - { |
|
| 97 | - $aCalls[] = "{$sVarName}->addValue('$sAttr', '" . addslashes($sClass) . "');"; |
|
| 98 | - } |
|
| 99 | - return $aCalls; |
|
| 100 | - } |
|
| 92 | +public function encode(string $sVarName): array |
|
| 93 | +{ |
|
| 94 | +$aCalls = []; |
|
| 95 | +foreach($this->aProperties as $sAttr => $sClass) |
|
| 96 | +{ |
|
| 97 | +$aCalls[] = "{$sVarName}->addValue('$sAttr', '" . addslashes($sClass) . "');"; |
|
| 98 | +} |
|
| 99 | +return $aCalls; |
|
| 100 | +} |
|
| 101 | 101 | } |
@@ -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 | } |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | class RequestHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The request plugin that is able to process the current request |
| 35 | 35 | * |
| 36 | 36 | * @var RequestHandlerInterface |
| 37 | 37 | */ |
| 38 | - private $xRequestPlugin = null; |
|
| 38 | +private $xRequestPlugin = null; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The constructor |
| 42 | 42 | * |
| 43 | 43 | * @param Container $di |
@@ -46,110 +46,110 @@ discard block |
||
| 46 | 46 | * @param CallbackManager $xCallbackManager |
| 47 | 47 | * @param DatabagPlugin $xDatabagPlugin |
| 48 | 48 | */ |
| 49 | - public function __construct(private Container $di, private PluginManager $xPluginManager, |
|
| 50 | - private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager, |
|
| 51 | - private DatabagPlugin $xDatabagPlugin) |
|
| 52 | - {} |
|
| 49 | +public function __construct(private Container $di, private PluginManager $xPluginManager, |
|
| 50 | +private ResponseManager $xResponseManager, private CallbackManager $xCallbackManager, |
|
| 51 | +private DatabagPlugin $xDatabagPlugin) |
|
| 52 | +{} |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Check if the current request can be processed |
| 56 | 56 | * |
| 57 | 57 | * Calls each of the request plugins and determines if the current request can be processed by one of them. |
| 58 | 58 | * |
| 59 | 59 | * @return bool |
| 60 | 60 | */ |
| 61 | - public function canProcessRequest(): bool |
|
| 62 | - { |
|
| 63 | - // Return true if the request plugin was already found |
|
| 64 | - if($this->xRequestPlugin !== null) |
|
| 65 | - { |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 61 | +public function canProcessRequest(): bool |
|
| 62 | +{ |
|
| 63 | +// Return true if the request plugin was already found |
|
| 64 | +if($this->xRequestPlugin !== null) |
|
| 65 | +{ |
|
| 66 | +return true; |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - // The HTTP request |
|
| 70 | - $xRequest = $this->di->getRequest(); |
|
| 69 | +// The HTTP request |
|
| 70 | +$xRequest = $this->di->getRequest(); |
|
| 71 | 71 | |
| 72 | - // Find a plugin to process the request |
|
| 73 | - foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 74 | - { |
|
| 75 | - if($sClassName::canProcessRequest($xRequest)) |
|
| 76 | - { |
|
| 77 | - $this->xRequestPlugin = $this->di->g($sClassName); |
|
| 78 | - $xTarget = $this->xRequestPlugin->setTarget($xRequest); |
|
| 79 | - $xTarget->setMethodArgs($this->di->getRequestArguments()); |
|
| 80 | - return true; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - return false; |
|
| 84 | - } |
|
| 72 | +// Find a plugin to process the request |
|
| 73 | +foreach($this->xPluginManager->getRequestHandlers() as $sClassName) |
|
| 74 | +{ |
|
| 75 | +if($sClassName::canProcessRequest($xRequest)) |
|
| 76 | +{ |
|
| 77 | + $this->xRequestPlugin = $this->di->g($sClassName); |
|
| 78 | + $xTarget = $this->xRequestPlugin->setTarget($xRequest); |
|
| 79 | + $xTarget->setMethodArgs($this->di->getRequestArguments()); |
|
| 80 | + return true; |
|
| 81 | +} |
|
| 82 | +} |
|
| 83 | +return false; |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * Process the current request and handle errors and exceptions. |
| 88 | 88 | * |
| 89 | 89 | * @return void |
| 90 | 90 | * @throws RequestException |
| 91 | 91 | */ |
| 92 | - private function _processRequest(): void |
|
| 93 | - { |
|
| 94 | - // Process the request |
|
| 95 | - if($this->xRequestPlugin !== null) |
|
| 96 | - { |
|
| 97 | - $this->xRequestPlugin->processRequest(); |
|
| 98 | - // Process the databag |
|
| 99 | - $this->xDatabagPlugin->writeCommand(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 92 | +private function _processRequest(): void |
|
| 93 | +{ |
|
| 94 | +// Process the request |
|
| 95 | +if($this->xRequestPlugin !== null) |
|
| 96 | +{ |
|
| 97 | +$this->xRequestPlugin->processRequest(); |
|
| 98 | +// Process the databag |
|
| 99 | +$this->xDatabagPlugin->writeCommand(); |
|
| 100 | +} |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Process the current request. |
| 105 | 105 | * |
| 106 | 106 | * @return void |
| 107 | 107 | * @throws RequestException |
| 108 | 108 | */ |
| 109 | - public function processRequest(): void |
|
| 110 | - { |
|
| 111 | - // Check if there is a plugin to process this request |
|
| 112 | - if(!$this->canProcessRequest()) |
|
| 113 | - { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 109 | +public function processRequest(): void |
|
| 110 | +{ |
|
| 111 | +// Check if there is a plugin to process this request |
|
| 112 | +if(!$this->canProcessRequest()) |
|
| 113 | +{ |
|
| 114 | +return; |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - try |
|
| 118 | - { |
|
| 119 | - $bEndRequest = false; |
|
| 120 | - // Handle before processing event |
|
| 121 | - if($this->xRequestPlugin !== null) |
|
| 122 | - { |
|
| 123 | - $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 124 | - } |
|
| 125 | - if($bEndRequest) |
|
| 126 | - { |
|
| 127 | - return; |
|
| 128 | - } |
|
| 117 | +try |
|
| 118 | +{ |
|
| 119 | +$bEndRequest = false; |
|
| 120 | +// Handle before processing event |
|
| 121 | +if($this->xRequestPlugin !== null) |
|
| 122 | +{ |
|
| 123 | + $this->xCallbackManager->onBefore($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 124 | +} |
|
| 125 | +if($bEndRequest) |
|
| 126 | +{ |
|
| 127 | + return; |
|
| 128 | +} |
|
| 129 | 129 | |
| 130 | - $this->_processRequest(); |
|
| 130 | +$this->_processRequest(); |
|
| 131 | 131 | |
| 132 | - // Handle after processing event |
|
| 133 | - if($this->xRequestPlugin !== null) |
|
| 134 | - { |
|
| 135 | - $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - // An exception was thrown while processing the request. |
|
| 139 | - // The request missed the corresponding handler function, |
|
| 140 | - // or an error occurred while attempting to execute the handler. |
|
| 141 | - catch(RequestException $e) |
|
| 142 | - { |
|
| 143 | - $this->xResponseManager->error($e->getMessage()); |
|
| 144 | - $this->xCallbackManager->onInvalid($e); |
|
| 145 | - } |
|
| 146 | - catch(Exception $e) |
|
| 147 | - { |
|
| 148 | - $this->xResponseManager->error($e->getMessage()); |
|
| 149 | - $this->xCallbackManager->onError($e); |
|
| 150 | - } |
|
| 132 | +// Handle after processing event |
|
| 133 | +if($this->xRequestPlugin !== null) |
|
| 134 | +{ |
|
| 135 | + $this->xCallbackManager->onAfter($this->xRequestPlugin->getTarget(), $bEndRequest); |
|
| 136 | +} |
|
| 137 | +} |
|
| 138 | +// An exception was thrown while processing the request. |
|
| 139 | +// The request missed the corresponding handler function, |
|
| 140 | +// or an error occurred while attempting to execute the handler. |
|
| 141 | +catch(RequestException $e) |
|
| 142 | +{ |
|
| 143 | +$this->xResponseManager->error($e->getMessage()); |
|
| 144 | +$this->xCallbackManager->onInvalid($e); |
|
| 145 | +} |
|
| 146 | +catch(Exception $e) |
|
| 147 | +{ |
|
| 148 | +$this->xResponseManager->error($e->getMessage()); |
|
| 149 | +$this->xCallbackManager->onError($e); |
|
| 150 | +} |
|
| 151 | 151 | |
| 152 | - // Print the debug messages |
|
| 153 | - $this->xResponseManager->printDebug(); |
|
| 154 | - } |
|
| 152 | +// Print the debug messages |
|
| 153 | +$this->xResponseManager->printDebug(); |
|
| 154 | +} |
|
| 155 | 155 | } |
@@ -13,94 +13,94 @@ |
||
| 13 | 13 | |
| 14 | 14 | class DatabagPlugin extends AbstractResponsePlugin |
| 15 | 15 | { |
| 16 | - /** |
|
| 16 | +/** |
|
| 17 | 17 | * @const The plugin name |
| 18 | 18 | */ |
| 19 | - public const NAME = 'bags'; |
|
| 19 | +public const NAME = 'bags'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * @var Databag |
| 23 | 23 | */ |
| 24 | - protected $xDatabag = null; |
|
| 24 | +protected $xDatabag = null; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The constructor |
| 28 | 28 | */ |
| 29 | - public function __construct(protected Container $di) |
|
| 30 | - {} |
|
| 29 | +public function __construct(protected Container $di) |
|
| 30 | +{} |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return void |
| 34 | 34 | */ |
| 35 | - private function initDatabag(): void |
|
| 36 | - { |
|
| 37 | - if($this->xDatabag !== null) |
|
| 38 | - { |
|
| 39 | - return; |
|
| 40 | - } |
|
| 35 | +private function initDatabag(): void |
|
| 36 | +{ |
|
| 37 | +if($this->xDatabag !== null) |
|
| 38 | +{ |
|
| 39 | +return; |
|
| 40 | +} |
|
| 41 | 41 | |
| 42 | - // Get the databag contents from the HTTP request parameters. |
|
| 43 | - $xRequest = $this->di->getRequest(); |
|
| 44 | - $aBody = $xRequest->getParsedBody(); |
|
| 45 | - $aParams = $xRequest->getQueryParams(); |
|
| 46 | - $aData = is_array($aBody) ? |
|
| 47 | - $this->readData($aBody['jxnbags'] ?? []) : |
|
| 48 | - $this->readData($aParams['jxnbags'] ?? []); |
|
| 49 | - $this->xDatabag = new Databag($this, $aData); |
|
| 50 | - } |
|
| 42 | +// Get the databag contents from the HTTP request parameters. |
|
| 43 | +$xRequest = $this->di->getRequest(); |
|
| 44 | +$aBody = $xRequest->getParsedBody(); |
|
| 45 | +$aParams = $xRequest->getQueryParams(); |
|
| 46 | +$aData = is_array($aBody) ? |
|
| 47 | +$this->readData($aBody['jxnbags'] ?? []) : |
|
| 48 | +$this->readData($aParams['jxnbags'] ?? []); |
|
| 49 | +$this->xDatabag = new Databag($this, $aData); |
|
| 50 | +} |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * @inheritDoc |
| 54 | 54 | */ |
| 55 | - public function getName(): string |
|
| 56 | - { |
|
| 57 | - return self::NAME; |
|
| 58 | - } |
|
| 55 | +public function getName(): string |
|
| 56 | +{ |
|
| 57 | +return self::NAME; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @param mixed $xData |
| 62 | 62 | * |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - private function readData($xData): array |
|
| 66 | - { |
|
| 67 | - // Todo: clean input data. |
|
| 68 | - // Todo: verify the checksums. |
|
| 69 | - return is_string($xData) ? |
|
| 70 | - (json_decode($xData, true) ?: []) : |
|
| 71 | - (is_array($xData) ? $xData : []); |
|
| 72 | - } |
|
| 65 | +private function readData($xData): array |
|
| 66 | +{ |
|
| 67 | +// Todo: clean input data. |
|
| 68 | +// Todo: verify the checksums. |
|
| 69 | +return is_string($xData) ? |
|
| 70 | +(json_decode($xData, true) ?: []) : |
|
| 71 | +(is_array($xData) ? $xData : []); |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function getHash(): string |
|
| 78 | - { |
|
| 79 | - // Use the version number as hash |
|
| 80 | - return '4.0.0'; |
|
| 81 | - } |
|
| 77 | +public function getHash(): string |
|
| 78 | +{ |
|
| 79 | +// Use the version number as hash |
|
| 80 | +return '4.0.0'; |
|
| 81 | +} |
|
| 82 | 82 | |
| 83 | - /** |
|
| 83 | +/** |
|
| 84 | 84 | * @return void |
| 85 | 85 | */ |
| 86 | - public function writeCommand(): void |
|
| 87 | - { |
|
| 88 | - $this->initDatabag(); |
|
| 89 | - if($this->xDatabag->touched()) |
|
| 90 | - { |
|
| 91 | - // Todo: calculate the checksums. |
|
| 92 | - $this->addCommand('databag.set', ['values' => $this->xDatabag]); |
|
| 93 | - } |
|
| 94 | - } |
|
| 86 | +public function writeCommand(): void |
|
| 87 | +{ |
|
| 88 | +$this->initDatabag(); |
|
| 89 | +if($this->xDatabag->touched()) |
|
| 90 | +{ |
|
| 91 | +// Todo: calculate the checksums. |
|
| 92 | +$this->addCommand('databag.set', ['values' => $this->xDatabag]); |
|
| 93 | +} |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * @param string $sName |
| 98 | 98 | * |
| 99 | 99 | * @return DatabagContext |
| 100 | 100 | */ |
| 101 | - public function bag(string $sName): DatabagContext |
|
| 102 | - { |
|
| 103 | - $this->initDatabag(); |
|
| 104 | - return new DatabagContext($this->xDatabag, $sName); |
|
| 105 | - } |
|
| 101 | +public function bag(string $sName): DatabagContext |
|
| 102 | +{ |
|
| 103 | +$this->initDatabag(); |
|
| 104 | +return new DatabagContext($this->xDatabag, $sName); |
|
| 105 | +} |
|
| 106 | 106 | } |