@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function configure(string $sName, string $sValue): void |
| 106 | 106 | { |
| 107 | - switch($sName) |
|
| 107 | + switch ($sName) |
|
| 108 | 108 | { |
| 109 | 109 | case 'class': // The user function is a method in the given class |
| 110 | 110 | $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function call(array $aArgs = []): void |
| 130 | 130 | { |
| 131 | - if($this->sInclude !== '') |
|
| 131 | + if ($this->sInclude !== '') |
|
| 132 | 132 | { |
| 133 | 133 | require_once $this->sInclude; |
| 134 | 134 | } |
| 135 | 135 | // If the function is an alias for a class method, then instantiate the class |
| 136 | - if(is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
| 136 | + if (is_array($this->xPhpFunction) && is_string($this->xPhpFunction[0])) |
|
| 137 | 137 | { |
| 138 | 138 | $sClassName = $this->xPhpFunction[0]; |
| 139 | 139 | $this->xPhpFunction[0] = $this->di->h($sClassName) ? |
@@ -28,29 +28,29 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class CallableFunction |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * A string or an array which defines the registered PHP function |
| 33 | 33 | * |
| 34 | 34 | * @var string|array |
| 35 | 35 | */ |
| 36 | - private $xPhpFunction; |
|
| 36 | +private $xPhpFunction; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * The path and file name of the include file where the function is defined |
| 40 | 40 | * |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - private $sInclude = ''; |
|
| 43 | +private $sInclude = ''; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * An associative array containing call options that will be sent |
| 47 | 47 | * to the browser with the client script. |
| 48 | 48 | * |
| 49 | 49 | * @var array |
| 50 | 50 | */ |
| 51 | - private $aOptions = []; |
|
| 51 | +private $aOptions = []; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * The constructor |
| 55 | 55 | * |
| 56 | 56 | * @param Container $di |
@@ -58,43 +58,43 @@ discard block |
||
| 58 | 58 | * @param string $sJsFunction |
| 59 | 59 | * @param string $sPhpFunction |
| 60 | 60 | */ |
| 61 | - public function __construct(private Container $di, private string $sFunction, |
|
| 62 | - private string $sJsFunction, string $sPhpFunction) |
|
| 63 | - { |
|
| 64 | - $this->xPhpFunction = $sPhpFunction; |
|
| 65 | - } |
|
| 61 | +public function __construct(private Container $di, private string $sFunction, |
|
| 62 | +private string $sJsFunction, string $sPhpFunction) |
|
| 63 | +{ |
|
| 64 | +$this->xPhpFunction = $sPhpFunction; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * Get the name of the function being referenced |
| 69 | 69 | * |
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | - public function getName(): string |
|
| 73 | - { |
|
| 74 | - return $this->sFunction; |
|
| 75 | - } |
|
| 72 | +public function getName(): string |
|
| 73 | +{ |
|
| 74 | +return $this->sFunction; |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * Get name of the corresponding javascript function |
| 79 | 79 | * |
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | - public function getJsName(): string |
|
| 83 | - { |
|
| 84 | - return $this->sJsFunction; |
|
| 85 | - } |
|
| 82 | +public function getJsName(): string |
|
| 83 | +{ |
|
| 84 | +return $this->sJsFunction; |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * Get the config options of the function being referenced |
| 89 | 89 | * |
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | - public function getOptions(): array |
|
| 93 | - { |
|
| 94 | - return $this->aOptions; |
|
| 95 | - } |
|
| 92 | +public function getOptions(): array |
|
| 93 | +{ |
|
| 94 | +return $this->aOptions; |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * Set call options for this instance |
| 99 | 99 | * |
| 100 | 100 | * @param string $sName The name of the configuration option |
@@ -102,20 +102,20 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | * @return void |
| 104 | 104 | */ |
| 105 | - public function configure(string $sName, string $sValue): void |
|
| 106 | - { |
|
| 107 | - switch($sName) |
|
| 108 | - { |
|
| 109 | - case 'class': // The user function is a method in the given class |
|
| 110 | - $this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
|
| 111 | - break; |
|
| 112 | - case 'include': |
|
| 113 | - $this->sInclude = $sValue; |
|
| 114 | - break; |
|
| 115 | - default: |
|
| 116 | - $this->aOptions[$sName] = $sValue; |
|
| 117 | - break; |
|
| 118 | - } |
|
| 105 | +public function configure(string $sName, string $sValue): void |
|
| 106 | +{ |
|
| 107 | +switch($sName) |
|
| 108 | +{ |
|
| 109 | +case 'class': // The user function is a method in the given class |
|
| 110 | +$this->xPhpFunction = [$sValue, $this->xPhpFunction]; |
|
| 111 | +break; |
|
| 112 | +case 'include': |
|
| 113 | +$this->sInclude = $sValue; |
|
| 114 | +break; |
|
| 115 | +default: |
|
| 116 | +$this->aOptions[$sName] = $sValue; |
|
| 117 | +break; |
|
| 118 | +} |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function checkOptions(string $sCallable, $xOptions): array |
| 87 | 87 | { |
| 88 | - if(!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 88 | + if (!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 89 | 89 | { |
| 90 | 90 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 91 | 91 | } |
| 92 | - if(is_string($xOptions)) |
|
| 92 | + if (is_string($xOptions)) |
|
| 93 | 93 | { |
| 94 | 94 | $xOptions = ['include' => $xOptions]; |
| 95 | 95 | } |
| 96 | - elseif(!is_array($xOptions)) |
|
| 96 | + elseif (!is_array($xOptions)) |
|
| 97 | 97 | { |
| 98 | 98 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 99 | 99 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $sPhpFunction = trim($sCallable); |
| 115 | 115 | $sFunction = $sPhpFunction; |
| 116 | 116 | // Check if an alias is defined |
| 117 | - if(isset($aOptions['alias'])) |
|
| 117 | + if (isset($aOptions['alias'])) |
|
| 118 | 118 | { |
| 119 | 119 | $sFunction = (string)$aOptions['alias']; |
| 120 | 120 | unset($aOptions['alias']); |
@@ -138,13 +138,13 @@ discard block |
||
| 138 | 138 | public function getCallable(string $sCallable): CallableFunction|null |
| 139 | 139 | { |
| 140 | 140 | $sFunction = trim($sCallable); |
| 141 | - if(!isset($this->aFunctions[$sFunction])) |
|
| 141 | + if (!isset($this->aFunctions[$sFunction])) |
|
| 142 | 142 | { |
| 143 | 143 | return null; |
| 144 | 144 | } |
| 145 | 145 | $xCallable = new CallableFunction($this->di, $sFunction, |
| 146 | 146 | $this->sPrefix . $sFunction, $this->aFunctions[$sFunction]); |
| 147 | - foreach($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 147 | + foreach ($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 148 | 148 | { |
| 149 | 149 | $xCallable->configure($sName, $sValue); |
| 150 | 150 | } |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | public function getScript(): string |
| 174 | 174 | { |
| 175 | 175 | $code = ''; |
| 176 | - foreach(array_keys($this->aFunctions) as $sFunction) |
|
| 176 | + foreach (array_keys($this->aFunctions) as $sFunction) |
|
| 177 | 177 | { |
| 178 | 178 | $xFunction = $this->getCallable($sFunction); |
| 179 | 179 | $code .= $this->getCallableScript($xFunction); |
@@ -211,8 +211,7 @@ discard block |
||
| 211 | 211 | private function throwException(Exception $xException, string $sErrorMessage): void |
| 212 | 212 | { |
| 213 | 213 | $this->di->getLogger()->error($xException->getMessage()); |
| 214 | - throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : |
|
| 215 | - "\n" . $xException->getMessage())); |
|
| 214 | + throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : "\n" . $xException->getMessage())); |
|
| 216 | 215 | } |
| 217 | 216 | |
| 218 | 217 | /** |
@@ -224,7 +223,7 @@ discard block |
||
| 224 | 223 | $sRequestedFunction = $this->xTarget->getFunctionName(); |
| 225 | 224 | |
| 226 | 225 | // Security check: make sure the requested function was registered. |
| 227 | - if(!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 226 | + if (!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 228 | 227 | !isset($this->aFunctions[$sRequestedFunction])) |
| 229 | 228 | { |
| 230 | 229 | // Unable to find the requested function |
@@ -237,7 +236,7 @@ discard block |
||
| 237 | 236 | /** @var CallableFunction */ |
| 238 | 237 | $xFunction = $this->getCallable($sRequestedFunction); |
| 239 | 238 | } |
| 240 | - catch(Exception $e) |
|
| 239 | + catch (Exception $e) |
|
| 241 | 240 | { |
| 242 | 241 | // Unable to find the requested function |
| 243 | 242 | $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
@@ -247,7 +246,7 @@ discard block |
||
| 247 | 246 | { |
| 248 | 247 | $xFunction->call($this->xTarget->args()); |
| 249 | 248 | } |
| 250 | - catch(Exception $e) |
|
| 249 | + catch (Exception $e) |
|
| 251 | 250 | { |
| 252 | 251 | // Unable to execute the requested function |
| 253 | 252 | $this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | if(is_string($xOptions)) |
| 93 | 93 | { |
| 94 | 94 | $xOptions = ['include' => $xOptions]; |
| 95 | - } |
|
| 96 | - elseif(!is_array($xOptions)) |
|
| 95 | + } elseif(!is_array($xOptions)) |
|
| 97 | 96 | { |
| 98 | 97 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 99 | 98 | } |
@@ -236,8 +235,7 @@ discard block |
||
| 236 | 235 | { |
| 237 | 236 | /** @var CallableFunction */ |
| 238 | 237 | $xFunction = $this->getCallable($sRequestedFunction); |
| 239 | - } |
|
| 240 | - catch(Exception $e) |
|
| 238 | + } catch(Exception $e) |
|
| 241 | 239 | { |
| 242 | 240 | // Unable to find the requested function |
| 243 | 241 | $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
@@ -246,8 +244,7 @@ discard block |
||
| 246 | 244 | try |
| 247 | 245 | { |
| 248 | 246 | $xFunction->call($this->xTarget->args()); |
| 249 | - } |
|
| 250 | - catch(Exception $e) |
|
| 247 | + } catch(Exception $e) |
|
| 251 | 248 | { |
| 252 | 249 | // Unable to execute the requested function |
| 253 | 250 | $this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
@@ -42,21 +42,21 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | class CallableFunctionPlugin extends AbstractRequestPlugin |
| 44 | 44 | { |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * The registered functions names |
| 47 | 47 | * |
| 48 | 48 | * @var array |
| 49 | 49 | */ |
| 50 | - protected $aFunctions = []; |
|
| 50 | +protected $aFunctions = []; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * The registered functions options |
| 54 | 54 | * |
| 55 | 55 | * @var array |
| 56 | 56 | */ |
| 57 | - protected $aOptions = []; |
|
| 57 | +protected $aOptions = []; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * The constructor |
| 61 | 61 | * |
| 62 | 62 | * @param string $sPrefix |
@@ -66,41 +66,41 @@ discard block |
||
| 66 | 66 | * @param Translator $xTranslator |
| 67 | 67 | * @param Validator $xValidator |
| 68 | 68 | */ |
| 69 | - public function __construct(private string $sPrefix, private bool $bDebug, |
|
| 70 | - private Container $di, private TemplateEngine $xTemplateEngine, |
|
| 71 | - private Translator $xTranslator, private Validator $xValidator) |
|
| 72 | - {} |
|
| 69 | +public function __construct(private string $sPrefix, private bool $bDebug, |
|
| 70 | +private Container $di, private TemplateEngine $xTemplateEngine, |
|
| 71 | +private Translator $xTranslator, private Validator $xValidator) |
|
| 72 | +{} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function getName(): string |
|
| 78 | - { |
|
| 79 | - return Jaxon::CALLABLE_FUNCTION; |
|
| 80 | - } |
|
| 77 | +public function getName(): string |
|
| 78 | +{ |
|
| 79 | +return Jaxon::CALLABLE_FUNCTION; |
|
| 80 | +} |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | +/** |
|
| 83 | 83 | * @inheritDoc |
| 84 | 84 | * @throws SetupException |
| 85 | 85 | */ |
| 86 | - public function checkOptions(string $sCallable, $xOptions): array |
|
| 87 | - { |
|
| 88 | - if(!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 89 | - { |
|
| 90 | - throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
|
| 91 | - } |
|
| 92 | - if(is_string($xOptions)) |
|
| 93 | - { |
|
| 94 | - $xOptions = ['include' => $xOptions]; |
|
| 95 | - } |
|
| 96 | - elseif(!is_array($xOptions)) |
|
| 97 | - { |
|
| 98 | - throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
|
| 99 | - } |
|
| 100 | - return $xOptions; |
|
| 101 | - } |
|
| 86 | +public function checkOptions(string $sCallable, $xOptions): array |
|
| 87 | +{ |
|
| 88 | +if(!$this->xValidator->validateFunction(trim($sCallable))) |
|
| 89 | +{ |
|
| 90 | +throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
|
| 91 | +} |
|
| 92 | +if(is_string($xOptions)) |
|
| 93 | +{ |
|
| 94 | +$xOptions = ['include' => $xOptions]; |
|
| 95 | +} |
|
| 96 | +elseif(!is_array($xOptions)) |
|
| 97 | +{ |
|
| 98 | +throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
|
| 99 | +} |
|
| 100 | +return $xOptions; |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Register a user defined function |
| 105 | 105 | * |
| 106 | 106 | * @param string $sType The type of request handler being registered |
@@ -109,149 +109,149 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @return bool |
| 111 | 111 | */ |
| 112 | - public function register(string $sType, string $sCallable, array $aOptions): bool |
|
| 113 | - { |
|
| 114 | - $sPhpFunction = trim($sCallable); |
|
| 115 | - $sFunction = $sPhpFunction; |
|
| 116 | - // Check if an alias is defined |
|
| 117 | - if(isset($aOptions['alias'])) |
|
| 118 | - { |
|
| 119 | - $sFunction = (string)$aOptions['alias']; |
|
| 120 | - unset($aOptions['alias']); |
|
| 121 | - } |
|
| 122 | - $this->aFunctions[$sFunction] = $sPhpFunction; |
|
| 123 | - $this->aOptions[$sFunction] = $aOptions; |
|
| 124 | - return true; |
|
| 125 | - } |
|
| 112 | +public function register(string $sType, string $sCallable, array $aOptions): bool |
|
| 113 | +{ |
|
| 114 | +$sPhpFunction = trim($sCallable); |
|
| 115 | +$sFunction = $sPhpFunction; |
|
| 116 | +// Check if an alias is defined |
|
| 117 | +if(isset($aOptions['alias'])) |
|
| 118 | +{ |
|
| 119 | +$sFunction = (string)$aOptions['alias']; |
|
| 120 | +unset($aOptions['alias']); |
|
| 121 | +} |
|
| 122 | +$this->aFunctions[$sFunction] = $sPhpFunction; |
|
| 123 | +$this->aOptions[$sFunction] = $aOptions; |
|
| 124 | +return true; |
|
| 125 | +} |
|
| 126 | 126 | |
| 127 | - /** |
|
| 127 | +/** |
|
| 128 | 128 | * @inheritDoc |
| 129 | 129 | */ |
| 130 | - public function getHash(): string |
|
| 131 | - { |
|
| 132 | - return md5(implode('', array_keys($this->aFunctions))); |
|
| 133 | - } |
|
| 130 | +public function getHash(): string |
|
| 131 | +{ |
|
| 132 | +return md5(implode('', array_keys($this->aFunctions))); |
|
| 133 | +} |
|
| 134 | 134 | |
| 135 | - /** |
|
| 135 | +/** |
|
| 136 | 136 | * @inheritDoc |
| 137 | 137 | */ |
| 138 | - public function getCallable(string $sCallable): CallableFunction|null |
|
| 139 | - { |
|
| 140 | - $sFunction = trim($sCallable); |
|
| 141 | - if(!isset($this->aFunctions[$sFunction])) |
|
| 142 | - { |
|
| 143 | - return null; |
|
| 144 | - } |
|
| 145 | - $xCallable = new CallableFunction($this->di, $sFunction, |
|
| 146 | - $this->sPrefix . $sFunction, $this->aFunctions[$sFunction]); |
|
| 147 | - foreach($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 148 | - { |
|
| 149 | - $xCallable->configure($sName, $sValue); |
|
| 150 | - } |
|
| 151 | - return $xCallable; |
|
| 152 | - } |
|
| 138 | +public function getCallable(string $sCallable): CallableFunction|null |
|
| 139 | +{ |
|
| 140 | +$sFunction = trim($sCallable); |
|
| 141 | +if(!isset($this->aFunctions[$sFunction])) |
|
| 142 | +{ |
|
| 143 | +return null; |
|
| 144 | +} |
|
| 145 | +$xCallable = new CallableFunction($this->di, $sFunction, |
|
| 146 | +$this->sPrefix . $sFunction, $this->aFunctions[$sFunction]); |
|
| 147 | +foreach($this->aOptions[$sFunction] as $sName => $sValue) |
|
| 148 | +{ |
|
| 149 | +$xCallable->configure($sName, $sValue); |
|
| 150 | +} |
|
| 151 | +return $xCallable; |
|
| 152 | +} |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | +/** |
|
| 155 | 155 | * Generate the javascript function stub that is sent to the browser on initial page load |
| 156 | 156 | * |
| 157 | 157 | * @param CallableFunction $xFunction |
| 158 | 158 | * |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - private function getCallableScript(CallableFunction $xFunction): string |
|
| 162 | - { |
|
| 163 | - return $this->xTemplateEngine->render('jaxon::callables/function.js', [ |
|
| 164 | - 'sName' => $xFunction->getName(), |
|
| 165 | - 'sJsName' => $xFunction->getJsName(), |
|
| 166 | - 'aOptions' => $xFunction->getOptions(), |
|
| 167 | - ]); |
|
| 168 | - } |
|
| 161 | +private function getCallableScript(CallableFunction $xFunction): string |
|
| 162 | +{ |
|
| 163 | +return $this->xTemplateEngine->render('jaxon::callables/function.js', [ |
|
| 164 | +'sName' => $xFunction->getName(), |
|
| 165 | +'sJsName' => $xFunction->getJsName(), |
|
| 166 | +'aOptions' => $xFunction->getOptions(), |
|
| 167 | +]); |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * @inheritDoc |
| 172 | 172 | */ |
| 173 | - public function getScript(): string |
|
| 174 | - { |
|
| 175 | - $code = ''; |
|
| 176 | - foreach(array_keys($this->aFunctions) as $sFunction) |
|
| 177 | - { |
|
| 178 | - $xFunction = $this->getCallable($sFunction); |
|
| 179 | - $code .= $this->getCallableScript($xFunction); |
|
| 180 | - } |
|
| 181 | - return $code; |
|
| 182 | - } |
|
| 173 | +public function getScript(): string |
|
| 174 | +{ |
|
| 175 | +$code = ''; |
|
| 176 | +foreach(array_keys($this->aFunctions) as $sFunction) |
|
| 177 | +{ |
|
| 178 | +$xFunction = $this->getCallable($sFunction); |
|
| 179 | +$code .= $this->getCallableScript($xFunction); |
|
| 180 | +} |
|
| 181 | +return $code; |
|
| 182 | +} |
|
| 183 | 183 | |
| 184 | - /** |
|
| 184 | +/** |
|
| 185 | 185 | * @inheritDoc |
| 186 | 186 | */ |
| 187 | - public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
|
| 188 | - { |
|
| 189 | - $aCall = $xRequest->getAttribute('jxncall'); |
|
| 190 | - // throw new \Exception(json_encode(['call' => $aCall])); |
|
| 191 | - return $aCall !== null && ($aCall['type'] ?? '') === 'func' && isset($aCall['name']); |
|
| 192 | - } |
|
| 187 | +public static function canProcessRequest(ServerRequestInterface $xRequest): bool |
|
| 188 | +{ |
|
| 189 | +$aCall = $xRequest->getAttribute('jxncall'); |
|
| 190 | +// throw new \Exception(json_encode(['call' => $aCall])); |
|
| 191 | +return $aCall !== null && ($aCall['type'] ?? '') === 'func' && isset($aCall['name']); |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * @inheritDoc |
| 196 | 196 | */ |
| 197 | - public function setTarget(ServerRequestInterface $xRequest): Target |
|
| 198 | - { |
|
| 199 | - $aCall = $xRequest->getAttribute('jxncall'); |
|
| 200 | - $this->xTarget = Target::makeFunction(trim($aCall['name'])); |
|
| 201 | - return $this->xTarget; |
|
| 202 | - } |
|
| 197 | +public function setTarget(ServerRequestInterface $xRequest): Target |
|
| 198 | +{ |
|
| 199 | +$aCall = $xRequest->getAttribute('jxncall'); |
|
| 200 | +$this->xTarget = Target::makeFunction(trim($aCall['name'])); |
|
| 201 | +return $this->xTarget; |
|
| 202 | +} |
|
| 203 | 203 | |
| 204 | - /** |
|
| 204 | +/** |
|
| 205 | 205 | * @param Exception $xException |
| 206 | 206 | * @param string $sErrorMessage |
| 207 | 207 | * |
| 208 | 208 | * @throws RequestException |
| 209 | 209 | * @return void |
| 210 | 210 | */ |
| 211 | - private function throwException(Exception $xException, string $sErrorMessage): void |
|
| 212 | - { |
|
| 213 | - $this->di->getLogger()->error($xException->getMessage()); |
|
| 214 | - throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : |
|
| 215 | - "\n" . $xException->getMessage())); |
|
| 216 | - } |
|
| 211 | +private function throwException(Exception $xException, string $sErrorMessage): void |
|
| 212 | +{ |
|
| 213 | +$this->di->getLogger()->error($xException->getMessage()); |
|
| 214 | +throw new RequestException($sErrorMessage . (!$this->bDebug ? '' : |
|
| 215 | +"\n" . $xException->getMessage())); |
|
| 216 | +} |
|
| 217 | 217 | |
| 218 | - /** |
|
| 218 | +/** |
|
| 219 | 219 | * @inheritDoc |
| 220 | 220 | * @throws RequestException |
| 221 | 221 | */ |
| 222 | - public function processRequest(): void |
|
| 223 | - { |
|
| 224 | - $sRequestedFunction = $this->xTarget->getFunctionName(); |
|
| 222 | +public function processRequest(): void |
|
| 223 | +{ |
|
| 224 | +$sRequestedFunction = $this->xTarget->getFunctionName(); |
|
| 225 | 225 | |
| 226 | - // Security check: make sure the requested function was registered. |
|
| 227 | - if(!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 228 | - !isset($this->aFunctions[$sRequestedFunction])) |
|
| 229 | - { |
|
| 230 | - // Unable to find the requested function |
|
| 231 | - throw new RequestException($this->xTranslator->trans('errors.functions.invalid', |
|
| 232 | - ['name' => $sRequestedFunction])); |
|
| 233 | - } |
|
| 226 | +// Security check: make sure the requested function was registered. |
|
| 227 | +if(!$this->xValidator->validateFunction($sRequestedFunction) || |
|
| 228 | +!isset($this->aFunctions[$sRequestedFunction])) |
|
| 229 | +{ |
|
| 230 | +// Unable to find the requested function |
|
| 231 | +throw new RequestException($this->xTranslator->trans('errors.functions.invalid', |
|
| 232 | + ['name' => $sRequestedFunction])); |
|
| 233 | +} |
|
| 234 | 234 | |
| 235 | - try |
|
| 236 | - { |
|
| 237 | - /** @var CallableFunction */ |
|
| 238 | - $xFunction = $this->getCallable($sRequestedFunction); |
|
| 239 | - } |
|
| 240 | - catch(Exception $e) |
|
| 241 | - { |
|
| 242 | - // Unable to find the requested function |
|
| 243 | - $this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
|
| 244 | - ['name' => $sRequestedFunction])); |
|
| 245 | - } |
|
| 246 | - try |
|
| 247 | - { |
|
| 248 | - $xFunction->call($this->xTarget->args()); |
|
| 249 | - } |
|
| 250 | - catch(Exception $e) |
|
| 251 | - { |
|
| 252 | - // Unable to execute the requested function |
|
| 253 | - $this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
|
| 254 | - ['name' => $sRequestedFunction])); |
|
| 255 | - } |
|
| 256 | - } |
|
| 235 | +try |
|
| 236 | +{ |
|
| 237 | +/** @var CallableFunction */ |
|
| 238 | +$xFunction = $this->getCallable($sRequestedFunction); |
|
| 239 | +} |
|
| 240 | +catch(Exception $e) |
|
| 241 | +{ |
|
| 242 | +// Unable to find the requested function |
|
| 243 | +$this->throwException($e, $this->xTranslator->trans('errors.functions.invalid', |
|
| 244 | + ['name' => $sRequestedFunction])); |
|
| 245 | +} |
|
| 246 | +try |
|
| 247 | +{ |
|
| 248 | +$xFunction->call($this->xTarget->args()); |
|
| 249 | +} |
|
| 250 | +catch(Exception $e) |
|
| 251 | +{ |
|
| 252 | +// Unable to execute the requested function |
|
| 253 | +$this->throwException($e, $this->xTranslator->trans('errors.functions.call', |
|
| 254 | + ['name' => $sRequestedFunction])); |
|
| 255 | +} |
|
| 256 | +} |
|
| 257 | 257 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | public function onChange(Config $xConfig, string $sName): void |
| 27 | 27 | { |
| 28 | 28 | // Set the library language any time the config is changed. |
| 29 | - if($sName === '' || $sName === 'core.language') |
|
| 29 | + if ($sName === '' || $sName === 'core.language') |
|
| 30 | 30 | { |
| 31 | 31 | $this->setLocale($xConfig->getOption('core.language')); |
| 32 | 32 | } |
@@ -20,15 +20,15 @@ |
||
| 20 | 20 | |
| 21 | 21 | class Translator extends BaseTranslator implements ConfigListenerInterface |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * @inheritDoc |
| 25 | 25 | */ |
| 26 | - public function onChange(Config $xConfig, string $sName): void |
|
| 27 | - { |
|
| 28 | - // Set the library language any time the config is changed. |
|
| 29 | - if($sName === '' || $sName === 'core.language') |
|
| 30 | - { |
|
| 31 | - $this->setLocale($xConfig->getOption('core.language')); |
|
| 32 | - } |
|
| 33 | - } |
|
| 26 | +public function onChange(Config $xConfig, string $sName): void |
|
| 27 | +{ |
|
| 28 | +// Set the library language any time the config is changed. |
|
| 29 | +if($sName === '' || $sName === 'core.language') |
|
| 30 | +{ |
|
| 31 | +$this->setLocale($xConfig->getOption('core.language')); |
|
| 32 | +} |
|
| 33 | +} |
|
| 34 | 34 | } |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | public function get(string $key, mixed $default = null): mixed |
| 32 | 32 | { |
| 33 | 33 | $value = $this->values[$key] ?? $default; |
| 34 | - if(is_callable($value)) |
|
| 34 | + if (is_callable($value)) |
|
| 35 | 35 | { |
| 36 | 36 | $value = $value(); |
| 37 | 37 | // Save the value returned by the callback in the stash. |
@@ -6,38 +6,38 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Stash |
| 8 | 8 | { |
| 9 | - /** |
|
| 9 | +/** |
|
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | - private array $values = []; |
|
| 12 | +private array $values = []; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 14 | +/** |
|
| 15 | 15 | * @param string $key |
| 16 | 16 | * @param mixed $value |
| 17 | 17 | * |
| 18 | 18 | * @return void |
| 19 | 19 | */ |
| 20 | - public function set(string $key, mixed $value): void |
|
| 21 | - { |
|
| 22 | - $this->values[$key] = $value; |
|
| 23 | - } |
|
| 20 | +public function set(string $key, mixed $value): void |
|
| 21 | +{ |
|
| 22 | +$this->values[$key] = $value; |
|
| 23 | +} |
|
| 24 | 24 | |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * @param string $key |
| 27 | 27 | * @param mixed $default |
| 28 | 28 | * |
| 29 | 29 | * @return mixed |
| 30 | 30 | */ |
| 31 | - public function get(string $key, mixed $default = null): mixed |
|
| 32 | - { |
|
| 33 | - $value = $this->values[$key] ?? $default; |
|
| 34 | - if(is_callable($value)) |
|
| 35 | - { |
|
| 36 | - $value = $value(); |
|
| 37 | - // Save the value returned by the callback in the stash. |
|
| 38 | - $this->values[$key] = $value; |
|
| 39 | - } |
|
| 31 | +public function get(string $key, mixed $default = null): mixed |
|
| 32 | +{ |
|
| 33 | +$value = $this->values[$key] ?? $default; |
|
| 34 | +if(is_callable($value)) |
|
| 35 | +{ |
|
| 36 | +$value = $value(); |
|
| 37 | +// Save the value returned by the callback in the stash. |
|
| 38 | +$this->values[$key] = $value; |
|
| 39 | +} |
|
| 40 | 40 | |
| 41 | - return $value; |
|
| 42 | - } |
|
| 41 | +return $value; |
|
| 42 | +} |
|
| 43 | 43 | } |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | 'export' => $bExport, |
| 92 | 92 | 'minify' => $bMinify, |
| 93 | 93 | ]; |
| 94 | - if($sUri !== '') |
|
| 94 | + if ($sUri !== '') |
|
| 95 | 95 | { |
| 96 | 96 | $aJsOptions['uri'] = $sUri; |
| 97 | 97 | } |
| 98 | - if($sDir !== '') |
|
| 98 | + if ($sDir !== '') |
|
| 99 | 99 | { |
| 100 | 100 | $aJsOptions['dir'] = $sDir; |
| 101 | 101 | } |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | { |
| 152 | 152 | // Popping the callbacks makes each of them to be called once. |
| 153 | 153 | $aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
| 154 | - foreach($aBootCallbacks as $aBootCallback) |
|
| 154 | + foreach ($aBootCallbacks as $aBootCallback) |
|
| 155 | 155 | { |
| 156 | 156 | call_user_func($aBootCallback); |
| 157 | 157 | } |
@@ -23,58 +23,58 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | class Bootstrap |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The library options |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - private $aLibOptions = []; |
|
| 31 | +private $aLibOptions = []; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The application options |
| 35 | 35 | * |
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - private $aAppOptions = []; |
|
| 38 | +private $aAppOptions = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The class constructor |
| 42 | 42 | * |
| 43 | 43 | * @param ConfigManager $xConfigManager |
| 44 | 44 | * @param PackageManager $xPackageManager |
| 45 | 45 | * @param CallbackManager $xCallbackManager |
| 46 | 46 | */ |
| 47 | - public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | - private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | - {} |
|
| 47 | +public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | +private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | +{} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Set the library options |
| 53 | 53 | * |
| 54 | 54 | * @param array $aLibOptions The library options |
| 55 | 55 | * |
| 56 | 56 | * @return Bootstrap |
| 57 | 57 | */ |
| 58 | - public function lib(array $aLibOptions): Bootstrap |
|
| 59 | - { |
|
| 60 | - $this->aLibOptions = $aLibOptions; |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 58 | +public function lib(array $aLibOptions): Bootstrap |
|
| 59 | +{ |
|
| 60 | +$this->aLibOptions = $aLibOptions; |
|
| 61 | +return $this; |
|
| 62 | +} |
|
| 63 | 63 | |
| 64 | - /** |
|
| 64 | +/** |
|
| 65 | 65 | * Set the applications options |
| 66 | 66 | * |
| 67 | 67 | * @param array $aAppOptions The application options |
| 68 | 68 | * |
| 69 | 69 | * @return Bootstrap |
| 70 | 70 | */ |
| 71 | - public function app(array $aAppOptions): Bootstrap |
|
| 72 | - { |
|
| 73 | - $this->aAppOptions = $aAppOptions; |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 71 | +public function app(array $aAppOptions): Bootstrap |
|
| 72 | +{ |
|
| 73 | +$this->aAppOptions = $aAppOptions; |
|
| 74 | +return $this; |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * Set the javascript asset |
| 79 | 79 | * |
| 80 | 80 | * @param bool $bExport Whether to export the js code in a file |
@@ -84,76 +84,76 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return Bootstrap |
| 86 | 86 | */ |
| 87 | - public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | - { |
|
| 89 | - // Jaxon library settings |
|
| 90 | - $aJsOptions = [ |
|
| 91 | - 'export' => $bExport, |
|
| 92 | - 'minify' => $bMinify, |
|
| 93 | - ]; |
|
| 94 | - if($sUri !== '') |
|
| 95 | - { |
|
| 96 | - $aJsOptions['uri'] = $sUri; |
|
| 97 | - } |
|
| 98 | - if($sDir !== '') |
|
| 99 | - { |
|
| 100 | - $aJsOptions['dir'] = $sDir; |
|
| 101 | - } |
|
| 102 | - $this->xConfigManager->setOptions($aJsOptions, 'js.app'); |
|
| 103 | - return $this; |
|
| 104 | - } |
|
| 87 | +public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | +{ |
|
| 89 | +// Jaxon library settings |
|
| 90 | +$aJsOptions = [ |
|
| 91 | +'export' => $bExport, |
|
| 92 | +'minify' => $bMinify, |
|
| 93 | +]; |
|
| 94 | +if($sUri !== '') |
|
| 95 | +{ |
|
| 96 | +$aJsOptions['uri'] = $sUri; |
|
| 97 | +} |
|
| 98 | +if($sDir !== '') |
|
| 99 | +{ |
|
| 100 | +$aJsOptions['dir'] = $sDir; |
|
| 101 | +} |
|
| 102 | +$this->xConfigManager->setOptions($aJsOptions, 'js.app'); |
|
| 103 | +return $this; |
|
| 104 | +} |
|
| 105 | 105 | |
| 106 | - /** |
|
| 106 | +/** |
|
| 107 | 107 | * Set the Jaxon application options. |
| 108 | 108 | * |
| 109 | 109 | * @return void |
| 110 | 110 | * @throws SetupException |
| 111 | 111 | */ |
| 112 | - private function setupApp(): void |
|
| 113 | - { |
|
| 114 | - // Save the app config. |
|
| 115 | - $this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 116 | - // Register user functions and classes |
|
| 117 | - $this->xPackageManager->registerFromConfig(); |
|
| 118 | - } |
|
| 112 | +private function setupApp(): void |
|
| 113 | +{ |
|
| 114 | +// Save the app config. |
|
| 115 | +$this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 116 | +// Register user functions and classes |
|
| 117 | +$this->xPackageManager->registerFromConfig(); |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - /** |
|
| 120 | +/** |
|
| 121 | 121 | * Wraps the module/package/bundle setup method. |
| 122 | 122 | * |
| 123 | 123 | * @return void |
| 124 | 124 | * @throws SetupException |
| 125 | 125 | */ |
| 126 | - public function setup(): void |
|
| 127 | - { |
|
| 128 | - // Prevent the Jaxon library from sending the response or exiting |
|
| 129 | - $this->xConfigManager->setOptions([ |
|
| 130 | - 'response' => [ |
|
| 131 | - 'send' => false, |
|
| 132 | - ], |
|
| 133 | - 'process' => [ |
|
| 134 | - 'exit' => false, |
|
| 135 | - ], |
|
| 136 | - ], 'core'); |
|
| 137 | - // Setup the lib config options. |
|
| 138 | - $this->xConfigManager->setOptions($this->aLibOptions); |
|
| 126 | +public function setup(): void |
|
| 127 | +{ |
|
| 128 | +// Prevent the Jaxon library from sending the response or exiting |
|
| 129 | +$this->xConfigManager->setOptions([ |
|
| 130 | +'response' => [ |
|
| 131 | + 'send' => false, |
|
| 132 | +], |
|
| 133 | +'process' => [ |
|
| 134 | + 'exit' => false, |
|
| 135 | +], |
|
| 136 | +], 'core'); |
|
| 137 | +// Setup the lib config options. |
|
| 138 | +$this->xConfigManager->setOptions($this->aLibOptions); |
|
| 139 | 139 | |
| 140 | - // Setup the app. |
|
| 141 | - $this->setupApp(); |
|
| 142 | - $this->onBoot(); |
|
| 143 | - } |
|
| 140 | +// Setup the app. |
|
| 141 | +$this->setupApp(); |
|
| 142 | +$this->onBoot(); |
|
| 143 | +} |
|
| 144 | 144 | |
| 145 | - /** |
|
| 145 | +/** |
|
| 146 | 146 | * These callbacks are called once, after the library is initialized. |
| 147 | 147 | * |
| 148 | 148 | * @return void |
| 149 | 149 | */ |
| 150 | - public function onBoot(): void |
|
| 151 | - { |
|
| 152 | - // Popping the callbacks makes each of them to be called once. |
|
| 153 | - $aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 154 | - foreach($aBootCallbacks as $aBootCallback) |
|
| 155 | - { |
|
| 156 | - call_user_func($aBootCallback); |
|
| 157 | - } |
|
| 158 | - } |
|
| 150 | +public function onBoot(): void |
|
| 151 | +{ |
|
| 152 | +// Popping the callbacks makes each of them to be called once. |
|
| 153 | +$aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 154 | +foreach($aBootCallbacks as $aBootCallback) |
|
| 155 | +{ |
|
| 156 | +call_user_func($aBootCallback); |
|
| 157 | +} |
|
| 158 | +} |
|
| 159 | 159 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function setup(string $sConfigFile = ''): void |
| 31 | 31 | { |
| 32 | - if(!file_exists($sConfigFile)) |
|
| 32 | + if (!file_exists($sConfigFile)) |
|
| 33 | 33 | { |
| 34 | 34 | throw new SetupException($this->translator() |
| 35 | 35 | ->trans('errors.file.access', ['path' => $sConfigFile])); |
@@ -39,14 +39,14 @@ discard block |
||
| 39 | 39 | $aOptions = $this->config()->read($sConfigFile); |
| 40 | 40 | $aLibOptions = $aOptions['lib'] ?? []; |
| 41 | 41 | $aAppOptions = $aOptions['app'] ?? []; |
| 42 | - if(!is_array($aLibOptions) || !is_array($aAppOptions)) |
|
| 42 | + if (!is_array($aLibOptions) || !is_array($aAppOptions)) |
|
| 43 | 43 | { |
| 44 | 44 | throw new SetupException($sMessage = $this->translator() |
| 45 | 45 | ->trans('errors.file.content', ['path' => $sConfigFile])); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // The bootstrap set this to false. It needs to be changed. |
| 49 | - if(!isset($aLibOptions['core']['response']['send'])) |
|
| 49 | + if (!isset($aLibOptions['core']['response']['send'])) |
|
| 50 | 50 | { |
| 51 | 51 | $aLibOptions['core']['response']['send'] = true; |
| 52 | 52 | } |
@@ -21,39 +21,39 @@ |
||
| 21 | 21 | |
| 22 | 22 | class App extends AbstractApp |
| 23 | 23 | { |
| 24 | - use Traits\SendResponseTrait; |
|
| 24 | +use Traits\SendResponseTrait; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @inheritDoc |
| 28 | 28 | * @throws SetupException |
| 29 | 29 | */ |
| 30 | - public function setup(string $sConfigFile = ''): void |
|
| 31 | - { |
|
| 32 | - if(!file_exists($sConfigFile)) |
|
| 33 | - { |
|
| 34 | - throw new SetupException($this->translator() |
|
| 35 | - ->trans('errors.file.access', ['path' => $sConfigFile])); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Read the config options. |
|
| 39 | - $aOptions = $this->config()->read($sConfigFile); |
|
| 40 | - $aLibOptions = $aOptions['lib'] ?? []; |
|
| 41 | - $aAppOptions = $aOptions['app'] ?? []; |
|
| 42 | - if(!is_array($aLibOptions) || !is_array($aAppOptions)) |
|
| 43 | - { |
|
| 44 | - throw new SetupException($sMessage = $this->translator() |
|
| 45 | - ->trans('errors.file.content', ['path' => $sConfigFile])); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // The bootstrap set this to false. It needs to be changed. |
|
| 49 | - if(!isset($aLibOptions['core']['response']['send'])) |
|
| 50 | - { |
|
| 51 | - $aLibOptions['core']['response']['send'] = true; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $this->bootstrap() |
|
| 55 | - ->lib($aLibOptions) |
|
| 56 | - ->app($aAppOptions) |
|
| 57 | - ->setup(); |
|
| 58 | - } |
|
| 30 | +public function setup(string $sConfigFile = ''): void |
|
| 31 | +{ |
|
| 32 | +if(!file_exists($sConfigFile)) |
|
| 33 | +{ |
|
| 34 | +throw new SetupException($this->translator() |
|
| 35 | + ->trans('errors.file.access', ['path' => $sConfigFile])); |
|
| 36 | +} |
|
| 37 | + |
|
| 38 | +// Read the config options. |
|
| 39 | +$aOptions = $this->config()->read($sConfigFile); |
|
| 40 | +$aLibOptions = $aOptions['lib'] ?? []; |
|
| 41 | +$aAppOptions = $aOptions['app'] ?? []; |
|
| 42 | +if(!is_array($aLibOptions) || !is_array($aAppOptions)) |
|
| 43 | +{ |
|
| 44 | +throw new SetupException($sMessage = $this->translator() |
|
| 45 | + ->trans('errors.file.content', ['path' => $sConfigFile])); |
|
| 46 | +} |
|
| 47 | + |
|
| 48 | +// The bootstrap set this to false. It needs to be changed. |
|
| 49 | +if(!isset($aLibOptions['core']['response']['send'])) |
|
| 50 | +{ |
|
| 51 | +$aLibOptions['core']['response']['send'] = true; |
|
| 52 | +} |
|
| 53 | + |
|
| 54 | +$this->bootstrap() |
|
| 55 | +->lib($aLibOptions) |
|
| 56 | +->app($aAppOptions) |
|
| 57 | +->setup(); |
|
| 58 | +} |
|
| 59 | 59 | } |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function httpResponse(string $sCode = '200'): mixed |
| 61 | 61 | { |
| 62 | - if(!$this->config()->getOption('core.response.send', false)) |
|
| 62 | + if (!$this->config()->getOption('core.response.send', false)) |
|
| 63 | 63 | { |
| 64 | 64 | return null; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // Check to see if headers have already been sent out, in which case we can't do our job |
| 68 | - if(headers_sent($sFilename, $nLineNumber)) |
|
| 68 | + if (headers_sent($sFilename, $nLineNumber)) |
|
| 69 | 69 | { |
| 70 | 70 | throw new RequestException($this->translator() |
| 71 | 71 | ->trans('errors.output.already-sent', [ |
| 72 | 72 | 'location' => "$sFilename:$nLineNumber", |
| 73 | 73 | ]) . "\n" . $this->translator()->trans('errors.output.advice')); |
| 74 | 74 | } |
| 75 | - if(empty($sContent = $this->getResponseManager()->getOutput())) |
|
| 75 | + if (empty($sContent = $this->getResponseManager()->getOutput())) |
|
| 76 | 76 | { |
| 77 | 77 | return null; |
| 78 | 78 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | // Set the HTTP response code |
| 81 | 81 | http_response_code(intval($sCode)); |
| 82 | 82 | |
| 83 | - if($this->di()->getRequest()->getMethod() === 'GET') |
|
| 83 | + if ($this->di()->getRequest()->getMethod() === 'GET') |
|
| 84 | 84 | { |
| 85 | 85 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
| 86 | 86 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | header('Content-Type: ' . $this->getResponseManager()->getContentType()); |
| 91 | 91 | |
| 92 | 92 | print $sContent; |
| 93 | - if($this->config()->getOption('core.process.exit', false)) |
|
| 93 | + if ($this->config()->getOption('core.process.exit', false)) |
|
| 94 | 94 | { |
| 95 | 95 | exit(); |
| 96 | 96 | } |
@@ -31,69 +31,69 @@ |
||
| 31 | 31 | |
| 32 | 32 | trait SendResponseTrait |
| 33 | 33 | { |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @return Container |
| 36 | 36 | */ |
| 37 | - abstract public function di(): Container; |
|
| 37 | +abstract public function di(): Container; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @return ConfigManager |
| 41 | 41 | */ |
| 42 | - abstract public function config(): ConfigManager; |
|
| 42 | +abstract public function config(): ConfigManager; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @return Translator |
| 46 | 46 | */ |
| 47 | - abstract public function translator(): Translator; |
|
| 47 | +abstract public function translator(): Translator; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * @return ResponseManager |
| 51 | 51 | */ |
| 52 | - abstract public function getResponseManager(): ResponseManager; |
|
| 52 | +abstract public function getResponseManager(): ResponseManager; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Prints the response to the output stream, thus sending the response to the browser |
| 56 | 56 | * |
| 57 | 57 | * @return mixed |
| 58 | 58 | * @throws RequestException |
| 59 | 59 | */ |
| 60 | - public function httpResponse(string $sCode = '200'): mixed |
|
| 61 | - { |
|
| 62 | - if(!$this->config()->getOption('core.response.send', false)) |
|
| 63 | - { |
|
| 64 | - return null; |
|
| 65 | - } |
|
| 60 | +public function httpResponse(string $sCode = '200'): mixed |
|
| 61 | +{ |
|
| 62 | +if(!$this->config()->getOption('core.response.send', false)) |
|
| 63 | +{ |
|
| 64 | +return null; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - // Check to see if headers have already been sent out, in which case we can't do our job |
|
| 68 | - if(headers_sent($sFilename, $nLineNumber)) |
|
| 69 | - { |
|
| 70 | - throw new RequestException($this->translator() |
|
| 71 | - ->trans('errors.output.already-sent', [ |
|
| 72 | - 'location' => "$sFilename:$nLineNumber", |
|
| 73 | - ]) . "\n" . $this->translator()->trans('errors.output.advice')); |
|
| 74 | - } |
|
| 75 | - if(empty($sContent = $this->getResponseManager()->getOutput())) |
|
| 76 | - { |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 67 | +// Check to see if headers have already been sent out, in which case we can't do our job |
|
| 68 | +if(headers_sent($sFilename, $nLineNumber)) |
|
| 69 | +{ |
|
| 70 | +throw new RequestException($this->translator() |
|
| 71 | + ->trans('errors.output.already-sent', [ |
|
| 72 | + 'location' => "$sFilename:$nLineNumber", |
|
| 73 | + ]) . "\n" . $this->translator()->trans('errors.output.advice')); |
|
| 74 | +} |
|
| 75 | +if(empty($sContent = $this->getResponseManager()->getOutput())) |
|
| 76 | +{ |
|
| 77 | +return null; |
|
| 78 | +} |
|
| 79 | 79 | |
| 80 | - // Set the HTTP response code |
|
| 81 | - http_response_code(intval($sCode)); |
|
| 80 | +// Set the HTTP response code |
|
| 81 | +http_response_code(intval($sCode)); |
|
| 82 | 82 | |
| 83 | - if($this->di()->getRequest()->getMethod() === 'GET') |
|
| 84 | - { |
|
| 85 | - header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 86 | - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 87 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 88 | - header("Pragma: no-cache"); |
|
| 89 | - } |
|
| 90 | - header('Content-Type: ' . $this->getResponseManager()->getContentType()); |
|
| 83 | +if($this->di()->getRequest()->getMethod() === 'GET') |
|
| 84 | +{ |
|
| 85 | +header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); |
|
| 86 | +header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); |
|
| 87 | +header("Cache-Control: no-cache, must-revalidate"); |
|
| 88 | +header("Pragma: no-cache"); |
|
| 89 | +} |
|
| 90 | +header('Content-Type: ' . $this->getResponseManager()->getContentType()); |
|
| 91 | 91 | |
| 92 | - print $sContent; |
|
| 93 | - if($this->config()->getOption('core.process.exit', false)) |
|
| 94 | - { |
|
| 95 | - exit(); |
|
| 96 | - } |
|
| 97 | - return null; |
|
| 98 | - } |
|
| 92 | +print $sContent; |
|
| 93 | +if($this->config()->getOption('core.process.exit', false)) |
|
| 94 | +{ |
|
| 95 | +exit(); |
|
| 96 | +} |
|
| 97 | +return null; |
|
| 98 | +} |
|
| 99 | 99 | } |
@@ -70,22 +70,22 @@ discard block |
||
| 70 | 70 | { |
| 71 | 71 | return $this->xConfigReader->read($sConfigFile); |
| 72 | 72 | } |
| 73 | - catch(YamlExtension $e) |
|
| 73 | + catch (YamlExtension $e) |
|
| 74 | 74 | { |
| 75 | 75 | $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
| 76 | 76 | throw new SetupException($sMessage); |
| 77 | 77 | } |
| 78 | - catch(FileExtension $e) |
|
| 78 | + catch (FileExtension $e) |
|
| 79 | 79 | { |
| 80 | 80 | $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
| 81 | 81 | throw new SetupException($sMessage); |
| 82 | 82 | } |
| 83 | - catch(FileAccess $e) |
|
| 83 | + catch (FileAccess $e) |
|
| 84 | 84 | { |
| 85 | 85 | $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
| 86 | 86 | throw new SetupException($sMessage); |
| 87 | 87 | } |
| 88 | - catch(FileContent $e) |
|
| 88 | + catch (FileContent $e) |
|
| 89 | 89 | { |
| 90 | 90 | $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
| 91 | 91 | throw new SetupException($sMessage); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | // Call the config change listeners. |
| 112 | 112 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 113 | 113 | } |
| 114 | - catch(DataDepth $e) |
|
| 114 | + catch (DataDepth $e) |
|
| 115 | 115 | { |
| 116 | 116 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 117 | 117 | 'key' => $e->sPrefix, |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 141 | 141 | return $this->xLibConfig->changed(); |
| 142 | 142 | } |
| 143 | - catch(DataDepth $e) |
|
| 143 | + catch (DataDepth $e) |
|
| 144 | 144 | { |
| 145 | 145 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 146 | 146 | 'key' => $e->sPrefix, |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
| 248 | 248 | return $this->xAppConfig->changed(); |
| 249 | 249 | } |
| 250 | - catch(DataDepth $e) |
|
| 250 | + catch (DataDepth $e) |
|
| 251 | 251 | { |
| 252 | 252 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 253 | 253 | 'key' => $e->sPrefix, |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | { |
| 298 | 298 | return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
| 299 | 299 | } |
| 300 | - catch(DataDepth $e) |
|
| 300 | + catch (DataDepth $e) |
|
| 301 | 301 | { |
| 302 | 302 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 303 | 303 | 'key' => $e->sPrefix, |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | */ |
| 337 | 337 | public function globals(bool $bForce = false): void |
| 338 | 338 | { |
| 339 | - if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 339 | + if ($bForce || $this->getAppOption('helpers.global', true)) |
|
| 340 | 340 | { |
| 341 | 341 | require_once dirname(__DIR__, 2) . '/globals.php'; |
| 342 | 342 | } |
@@ -69,23 +69,19 @@ discard block |
||
| 69 | 69 | try |
| 70 | 70 | { |
| 71 | 71 | return $this->xConfigReader->read($sConfigFile); |
| 72 | - } |
|
| 73 | - catch(YamlExtension $e) |
|
| 72 | + } catch(YamlExtension $e) |
|
| 74 | 73 | { |
| 75 | 74 | $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
| 76 | 75 | throw new SetupException($sMessage); |
| 77 | - } |
|
| 78 | - catch(FileExtension $e) |
|
| 76 | + } catch(FileExtension $e) |
|
| 79 | 77 | { |
| 80 | 78 | $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
| 81 | 79 | throw new SetupException($sMessage); |
| 82 | - } |
|
| 83 | - catch(FileAccess $e) |
|
| 80 | + } catch(FileAccess $e) |
|
| 84 | 81 | { |
| 85 | 82 | $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
| 86 | 83 | throw new SetupException($sMessage); |
| 87 | - } |
|
| 88 | - catch(FileContent $e) |
|
| 84 | + } catch(FileContent $e) |
|
| 89 | 85 | { |
| 90 | 86 | $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
| 91 | 87 | throw new SetupException($sMessage); |
@@ -110,8 +106,7 @@ discard block |
||
| 110 | 106 | ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
| 111 | 107 | // Call the config change listeners. |
| 112 | 108 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 113 | - } |
|
| 114 | - catch(DataDepth $e) |
|
| 109 | + } catch(DataDepth $e) |
|
| 115 | 110 | { |
| 116 | 111 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 117 | 112 | 'key' => $e->sPrefix, |
@@ -139,8 +134,7 @@ discard block |
||
| 139 | 134 | // Call the config change listeners. |
| 140 | 135 | $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
| 141 | 136 | return $this->xLibConfig->changed(); |
| 142 | - } |
|
| 143 | - catch(DataDepth $e) |
|
| 137 | + } catch(DataDepth $e) |
|
| 144 | 138 | { |
| 145 | 139 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 146 | 140 | 'key' => $e->sPrefix, |
@@ -246,8 +240,7 @@ discard block |
||
| 246 | 240 | // Call the config change listeners. |
| 247 | 241 | $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
| 248 | 242 | return $this->xAppConfig->changed(); |
| 249 | - } |
|
| 250 | - catch(DataDepth $e) |
|
| 243 | + } catch(DataDepth $e) |
|
| 251 | 244 | { |
| 252 | 245 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 253 | 246 | 'key' => $e->sPrefix, |
@@ -296,8 +289,7 @@ discard block |
||
| 296 | 289 | try |
| 297 | 290 | { |
| 298 | 291 | return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
| 299 | - } |
|
| 300 | - catch(DataDepth $e) |
|
| 292 | + } catch(DataDepth $e) |
|
| 301 | 293 | { |
| 302 | 294 | $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
| 303 | 295 | 'key' => $e->sPrefix, |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class ConfigManager |
| 31 | 31 | { |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @var Config |
| 34 | 34 | */ |
| 35 | - protected $xLibConfig; |
|
| 35 | +protected $xLibConfig; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @var Config |
| 39 | 39 | */ |
| 40 | - protected $xAppConfig; |
|
| 40 | +protected $xAppConfig; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * The constructor |
| 44 | 44 | * |
| 45 | 45 | * @param array $aDefaultOptions |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | * @param ConfigSetter $xConfigSetter |
| 49 | 49 | * @param ConfigEventManager $xEventManager |
| 50 | 50 | */ |
| 51 | - public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | - private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | - private ConfigEventManager $xEventManager) |
|
| 54 | - { |
|
| 55 | - $this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | - $this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | - } |
|
| 51 | +public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | +private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | +private ConfigEventManager $xEventManager) |
|
| 54 | +{ |
|
| 55 | +$this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | +$this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * Read a config file |
| 61 | 61 | * |
| 62 | 62 | * @param string $sConfigFile |
@@ -64,35 +64,35 @@ discard block |
||
| 64 | 64 | * @return array |
| 65 | 65 | * @throws SetupException |
| 66 | 66 | */ |
| 67 | - public function read(string $sConfigFile): array |
|
| 68 | - { |
|
| 69 | - try |
|
| 70 | - { |
|
| 71 | - return $this->xConfigReader->read($sConfigFile); |
|
| 72 | - } |
|
| 73 | - catch(YamlExtension $e) |
|
| 74 | - { |
|
| 75 | - $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | - throw new SetupException($sMessage); |
|
| 77 | - } |
|
| 78 | - catch(FileExtension $e) |
|
| 79 | - { |
|
| 80 | - $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | - throw new SetupException($sMessage); |
|
| 82 | - } |
|
| 83 | - catch(FileAccess $e) |
|
| 84 | - { |
|
| 85 | - $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | - throw new SetupException($sMessage); |
|
| 87 | - } |
|
| 88 | - catch(FileContent $e) |
|
| 89 | - { |
|
| 90 | - $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | - throw new SetupException($sMessage); |
|
| 92 | - } |
|
| 93 | - } |
|
| 67 | +public function read(string $sConfigFile): array |
|
| 68 | +{ |
|
| 69 | +try |
|
| 70 | +{ |
|
| 71 | +return $this->xConfigReader->read($sConfigFile); |
|
| 72 | +} |
|
| 73 | +catch(YamlExtension $e) |
|
| 74 | +{ |
|
| 75 | +$sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | +throw new SetupException($sMessage); |
|
| 77 | +} |
|
| 78 | +catch(FileExtension $e) |
|
| 79 | +{ |
|
| 80 | +$sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | +throw new SetupException($sMessage); |
|
| 82 | +} |
|
| 83 | +catch(FileAccess $e) |
|
| 84 | +{ |
|
| 85 | +$sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | +throw new SetupException($sMessage); |
|
| 87 | +} |
|
| 88 | +catch(FileContent $e) |
|
| 89 | +{ |
|
| 90 | +$sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | +throw new SetupException($sMessage); |
|
| 92 | +} |
|
| 93 | +} |
|
| 94 | 94 | |
| 95 | - /** |
|
| 95 | +/** |
|
| 96 | 96 | * Read options from a config file and set the library config |
| 97 | 97 | * |
| 98 | 98 | * @param string $sConfigFile The full path to the config file |
@@ -101,27 +101,27 @@ discard block |
||
| 101 | 101 | * @return void |
| 102 | 102 | * @throws SetupException |
| 103 | 103 | */ |
| 104 | - public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | - { |
|
| 106 | - try |
|
| 107 | - { |
|
| 108 | - // Read the options and save in the config. |
|
| 109 | - $this->xLibConfig = $this->xConfigSetter |
|
| 110 | - ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | - // Call the config change listeners. |
|
| 112 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | - } |
|
| 114 | - catch(DataDepth $e) |
|
| 115 | - { |
|
| 116 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | - 'key' => $e->sPrefix, |
|
| 118 | - 'depth' => $e->nDepth, |
|
| 119 | - ]); |
|
| 120 | - throw new SetupException($sMessage); |
|
| 121 | - } |
|
| 122 | - } |
|
| 104 | +public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | +{ |
|
| 106 | +try |
|
| 107 | +{ |
|
| 108 | +// Read the options and save in the config. |
|
| 109 | +$this->xLibConfig = $this->xConfigSetter |
|
| 110 | + ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | +// Call the config change listeners. |
|
| 112 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | +} |
|
| 114 | +catch(DataDepth $e) |
|
| 115 | +{ |
|
| 116 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | + 'key' => $e->sPrefix, |
|
| 118 | + 'depth' => $e->nDepth, |
|
| 119 | +]); |
|
| 120 | +throw new SetupException($sMessage); |
|
| 121 | +} |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Set the config options of the library |
| 126 | 126 | * |
| 127 | 127 | * @param array $aOptions |
@@ -130,27 +130,27 @@ discard block |
||
| 130 | 130 | * @return bool |
| 131 | 131 | * @throws SetupException |
| 132 | 132 | */ |
| 133 | - public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | - { |
|
| 135 | - try |
|
| 136 | - { |
|
| 137 | - $this->xLibConfig = $this->xConfigSetter |
|
| 138 | - ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | - // Call the config change listeners. |
|
| 140 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | - return $this->xLibConfig->changed(); |
|
| 142 | - } |
|
| 143 | - catch(DataDepth $e) |
|
| 144 | - { |
|
| 145 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | - 'key' => $e->sPrefix, |
|
| 147 | - 'depth' => $e->nDepth, |
|
| 148 | - ]); |
|
| 149 | - throw new SetupException($sMessage); |
|
| 150 | - } |
|
| 151 | - } |
|
| 133 | +public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | +{ |
|
| 135 | +try |
|
| 136 | +{ |
|
| 137 | +$this->xLibConfig = $this->xConfigSetter |
|
| 138 | + ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | +// Call the config change listeners. |
|
| 140 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | +return $this->xLibConfig->changed(); |
|
| 142 | +} |
|
| 143 | +catch(DataDepth $e) |
|
| 144 | +{ |
|
| 145 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | + 'key' => $e->sPrefix, |
|
| 147 | + 'depth' => $e->nDepth, |
|
| 148 | +]); |
|
| 149 | +throw new SetupException($sMessage); |
|
| 150 | +} |
|
| 151 | +} |
|
| 152 | 152 | |
| 153 | - /** |
|
| 153 | +/** |
|
| 154 | 154 | * Set the value of a config option |
| 155 | 155 | * |
| 156 | 156 | * @param string $sName The option name |
@@ -158,15 +158,15 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return void |
| 160 | 160 | */ |
| 161 | - public function setOption(string $sName, $xValue): void |
|
| 162 | - { |
|
| 163 | - $this->xLibConfig = $this->xConfigSetter |
|
| 164 | - ->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | - // Call the config change listeners. |
|
| 166 | - $this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | - } |
|
| 161 | +public function setOption(string $sName, $xValue): void |
|
| 162 | +{ |
|
| 163 | +$this->xLibConfig = $this->xConfigSetter |
|
| 164 | +->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | +// Call the config change listeners. |
|
| 166 | +$this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * Get the value of a config option |
| 171 | 171 | * |
| 172 | 172 | * @param string $sName The option name |
@@ -174,36 +174,36 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return mixed |
| 176 | 176 | */ |
| 177 | - public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | - { |
|
| 179 | - return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | - } |
|
| 177 | +public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | +{ |
|
| 179 | +return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Check the presence of a config option |
| 184 | 184 | * |
| 185 | 185 | * @param string $sName The option name |
| 186 | 186 | * |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - public function hasOption(string $sName): bool |
|
| 190 | - { |
|
| 191 | - return $this->xLibConfig->hasOption($sName); |
|
| 192 | - } |
|
| 189 | +public function hasOption(string $sName): bool |
|
| 190 | +{ |
|
| 191 | +return $this->xLibConfig->hasOption($sName); |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * Get the names of the options matching a given prefix |
| 196 | 196 | * |
| 197 | 197 | * @param string $sPrefix The prefix to match |
| 198 | 198 | * |
| 199 | 199 | * @return array |
| 200 | 200 | */ |
| 201 | - public function getOptionNames(string $sPrefix): array |
|
| 202 | - { |
|
| 203 | - return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | - } |
|
| 201 | +public function getOptionNames(string $sPrefix): array |
|
| 202 | +{ |
|
| 203 | +return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Set the value of a config option |
| 208 | 208 | * |
| 209 | 209 | * @param string $sName The option name |
@@ -211,25 +211,25 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | - public function setAppOption(string $sName, $xValue): void |
|
| 215 | - { |
|
| 216 | - $this->xAppConfig = $this->xConfigSetter |
|
| 217 | - ->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | - // Call the config change listeners. |
|
| 219 | - $this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | - } |
|
| 214 | +public function setAppOption(string $sName, $xValue): void |
|
| 215 | +{ |
|
| 216 | +$this->xAppConfig = $this->xConfigSetter |
|
| 217 | +->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | +// Call the config change listeners. |
|
| 219 | +$this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | +} |
|
| 221 | 221 | |
| 222 | - /** |
|
| 222 | +/** |
|
| 223 | 223 | * Get the application config |
| 224 | 224 | * |
| 225 | 225 | * @return Config |
| 226 | 226 | */ |
| 227 | - public function getAppConfig(): Config |
|
| 228 | - { |
|
| 229 | - return $this->xAppConfig; |
|
| 230 | - } |
|
| 227 | +public function getAppConfig(): Config |
|
| 228 | +{ |
|
| 229 | +return $this->xAppConfig; |
|
| 230 | +} |
|
| 231 | 231 | |
| 232 | - /** |
|
| 232 | +/** |
|
| 233 | 233 | * Set the application config options |
| 234 | 234 | * |
| 235 | 235 | * @param array $aAppOptions |
@@ -237,27 +237,27 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | - { |
|
| 242 | - try |
|
| 243 | - { |
|
| 244 | - $this->xAppConfig = $this->xConfigSetter |
|
| 245 | - ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | - // Call the config change listeners. |
|
| 247 | - $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | - return $this->xAppConfig->changed(); |
|
| 249 | - } |
|
| 250 | - catch(DataDepth $e) |
|
| 251 | - { |
|
| 252 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | - 'key' => $e->sPrefix, |
|
| 254 | - 'depth' => $e->nDepth, |
|
| 255 | - ]); |
|
| 256 | - throw new SetupException($sMessage); |
|
| 257 | - } |
|
| 258 | - } |
|
| 240 | +public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | +{ |
|
| 242 | +try |
|
| 243 | +{ |
|
| 244 | +$this->xAppConfig = $this->xConfigSetter |
|
| 245 | + ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | +// Call the config change listeners. |
|
| 247 | +$this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | +return $this->xAppConfig->changed(); |
|
| 249 | +} |
|
| 250 | +catch(DataDepth $e) |
|
| 251 | +{ |
|
| 252 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | + 'key' => $e->sPrefix, |
|
| 254 | + 'depth' => $e->nDepth, |
|
| 255 | +]); |
|
| 256 | +throw new SetupException($sMessage); |
|
| 257 | +} |
|
| 258 | +} |
|
| 259 | 259 | |
| 260 | - /** |
|
| 260 | +/** |
|
| 261 | 261 | * Get the value of an application config option |
| 262 | 262 | * |
| 263 | 263 | * @param string $sName The option name |
@@ -265,24 +265,24 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return mixed |
| 267 | 267 | */ |
| 268 | - public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | - { |
|
| 270 | - return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | - } |
|
| 268 | +public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | +{ |
|
| 270 | +return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | +} |
|
| 272 | 272 | |
| 273 | - /** |
|
| 273 | +/** |
|
| 274 | 274 | * Check the presence of an application config option |
| 275 | 275 | * |
| 276 | 276 | * @param string $sName The option name |
| 277 | 277 | * |
| 278 | 278 | * @return bool |
| 279 | 279 | */ |
| 280 | - public function hasAppOption(string $sName): bool |
|
| 281 | - { |
|
| 282 | - return $this->xAppConfig->hasOption($sName); |
|
| 283 | - } |
|
| 280 | +public function hasAppOption(string $sName): bool |
|
| 281 | +{ |
|
| 282 | +return $this->xAppConfig->hasOption($sName); |
|
| 283 | +} |
|
| 284 | 284 | |
| 285 | - /** |
|
| 285 | +/** |
|
| 286 | 286 | * Create a new the config object |
| 287 | 287 | * |
| 288 | 288 | * @param array $aOptions The options array |
@@ -291,54 +291,54 @@ discard block |
||
| 291 | 291 | * @return Config |
| 292 | 292 | * @throws SetupException |
| 293 | 293 | */ |
| 294 | - public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | - { |
|
| 296 | - try |
|
| 297 | - { |
|
| 298 | - return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | - } |
|
| 300 | - catch(DataDepth $e) |
|
| 301 | - { |
|
| 302 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | - 'key' => $e->sPrefix, |
|
| 304 | - 'depth' => $e->nDepth, |
|
| 305 | - ]); |
|
| 306 | - throw new SetupException($sMessage); |
|
| 307 | - } |
|
| 308 | - } |
|
| 294 | +public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | +{ |
|
| 296 | +try |
|
| 297 | +{ |
|
| 298 | +return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | +} |
|
| 300 | +catch(DataDepth $e) |
|
| 301 | +{ |
|
| 302 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | + 'key' => $e->sPrefix, |
|
| 304 | + 'depth' => $e->nDepth, |
|
| 305 | +]); |
|
| 306 | +throw new SetupException($sMessage); |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | |
| 310 | - /** |
|
| 310 | +/** |
|
| 311 | 311 | * @param string $sClassName |
| 312 | 312 | * |
| 313 | 313 | * @return void |
| 314 | 314 | */ |
| 315 | - public function addLibEventListener(string $sClassName): void |
|
| 316 | - { |
|
| 317 | - $this->xEventManager->addLibConfigListener($sClassName); |
|
| 318 | - } |
|
| 315 | +public function addLibEventListener(string $sClassName): void |
|
| 316 | +{ |
|
| 317 | +$this->xEventManager->addLibConfigListener($sClassName); |
|
| 318 | +} |
|
| 319 | 319 | |
| 320 | - /** |
|
| 320 | +/** |
|
| 321 | 321 | * @param string $sClassName |
| 322 | 322 | * |
| 323 | 323 | * @return void |
| 324 | 324 | */ |
| 325 | - public function addAppEventListener(string $sClassName): void |
|
| 326 | - { |
|
| 327 | - $this->xEventManager->addAppConfigListener($sClassName); |
|
| 328 | - } |
|
| 325 | +public function addAppEventListener(string $sClassName): void |
|
| 326 | +{ |
|
| 327 | +$this->xEventManager->addAppConfigListener($sClassName); |
|
| 328 | +} |
|
| 329 | 329 | |
| 330 | - /** |
|
| 330 | +/** |
|
| 331 | 331 | * Make the helpers functions available in the global namespace. |
| 332 | 332 | * |
| 333 | 333 | * @param bool $bForce |
| 334 | 334 | * |
| 335 | 335 | * @return void |
| 336 | 336 | */ |
| 337 | - public function globals(bool $bForce = false): void |
|
| 338 | - { |
|
| 339 | - if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 340 | - { |
|
| 341 | - require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 342 | - } |
|
| 343 | - } |
|
| 337 | +public function globals(bool $bForce = false): void |
|
| 338 | +{ |
|
| 339 | +if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 340 | +{ |
|
| 341 | +require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 342 | +} |
|
| 343 | +} |
|
| 344 | 344 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | public function libConfigChanged(Config $xConfig, string $sName): void |
| 62 | 62 | { |
| 63 | - foreach($this->aLibConfigListeners as $sListener) |
|
| 63 | + foreach ($this->aLibConfigListeners as $sListener) |
|
| 64 | 64 | { |
| 65 | 65 | $this->di->g($sListener)->onChange($xConfig, $sName); |
| 66 | 66 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | public function appConfigChanged(Config $xConfig, string $sName): void |
| 73 | 73 | { |
| 74 | - foreach($this->aAppConfigListeners as $sListener) |
|
| 74 | + foreach ($this->aAppConfigListeners as $sListener) |
|
| 75 | 75 | { |
| 76 | 76 | $this->di->g($sListener)->onChange($xConfig, $sName); |
| 77 | 77 | } |
@@ -19,61 +19,61 @@ |
||
| 19 | 19 | |
| 20 | 20 | class ConfigEventManager |
| 21 | 21 | { |
| 22 | - /** |
|
| 22 | +/** |
|
| 23 | 23 | * @var string[] |
| 24 | 24 | */ |
| 25 | - protected $aLibConfigListeners = []; |
|
| 25 | +protected $aLibConfigListeners = []; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * @var string[] |
| 29 | 29 | */ |
| 30 | - protected $aAppConfigListeners = []; |
|
| 30 | +protected $aAppConfigListeners = []; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @param Container $di |
| 34 | 34 | */ |
| 35 | - public function __construct(private Container $di) |
|
| 36 | - {} |
|
| 35 | +public function __construct(private Container $di) |
|
| 36 | +{} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @param string $sClassName |
| 40 | 40 | * |
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | - public function addLibConfigListener(string $sClassName): void |
|
| 44 | - { |
|
| 45 | - $this->aLibConfigListeners[] = $sClassName; |
|
| 46 | - } |
|
| 43 | +public function addLibConfigListener(string $sClassName): void |
|
| 44 | +{ |
|
| 45 | +$this->aLibConfigListeners[] = $sClassName; |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @param string $sClassName |
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - public function addAppConfigListener(string $sClassName): void |
|
| 54 | - { |
|
| 55 | - $this->aAppConfigListeners[] = $sClassName; |
|
| 56 | - } |
|
| 53 | +public function addAppConfigListener(string $sClassName): void |
|
| 54 | +{ |
|
| 55 | +$this->aAppConfigListeners[] = $sClassName; |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * @inheritDoc |
| 60 | 60 | */ |
| 61 | - public function libConfigChanged(Config $xConfig, string $sName): void |
|
| 62 | - { |
|
| 63 | - foreach($this->aLibConfigListeners as $sListener) |
|
| 64 | - { |
|
| 65 | - $this->di->g($sListener)->onChange($xConfig, $sName); |
|
| 66 | - } |
|
| 67 | - } |
|
| 61 | +public function libConfigChanged(Config $xConfig, string $sName): void |
|
| 62 | +{ |
|
| 63 | +foreach($this->aLibConfigListeners as $sListener) |
|
| 64 | +{ |
|
| 65 | +$this->di->g($sListener)->onChange($xConfig, $sName); |
|
| 66 | +} |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * @inheritDoc |
| 71 | 71 | */ |
| 72 | - public function appConfigChanged(Config $xConfig, string $sName): void |
|
| 73 | - { |
|
| 74 | - foreach($this->aAppConfigListeners as $sListener) |
|
| 75 | - { |
|
| 76 | - $this->di->g($sListener)->onChange($xConfig, $sName); |
|
| 77 | - } |
|
| 78 | - } |
|
| 72 | +public function appConfigChanged(Config $xConfig, string $sName): void |
|
| 73 | +{ |
|
| 74 | +foreach($this->aAppConfigListeners as $sListener) |
|
| 75 | +{ |
|
| 76 | +$this->di->g($sListener)->onChange($xConfig, $sName); |
|
| 77 | +} |
|
| 78 | +} |
|
| 79 | 79 | } |