@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | interface MinifierInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 7 | +/** |
|
| 8 | 8 | * Minify javascript code |
| 9 | 9 | * |
| 10 | 10 | * @param string $sJsFile The javascript file to be minified |
@@ -12,5 +12,5 @@ discard block |
||
| 12 | 12 | * |
| 13 | 13 | * @return bool |
| 14 | 14 | */ |
| 15 | - public function minify(string $sJsFile, string $sMinFile): bool; |
|
| 15 | +public function minify(string $sJsFile, string $sMinFile): bool; |
|
| 16 | 16 | } |
@@ -43,60 +43,60 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | class PaginatorPlugin extends AbstractResponsePlugin |
| 45 | 45 | { |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @const The plugin name |
| 48 | 48 | */ |
| 49 | - public const NAME = 'pg'; |
|
| 49 | +public const NAME = 'pg'; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * The constructor. |
| 53 | 53 | * |
| 54 | 54 | * @param RendererInterface $xRenderer |
| 55 | 55 | */ |
| 56 | - public function __construct(protected RendererInterface $xRenderer) |
|
| 57 | - {} |
|
| 56 | +public function __construct(protected RendererInterface $xRenderer) |
|
| 57 | +{} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | */ |
| 62 | - public function getName(): string |
|
| 63 | - { |
|
| 64 | - return self::NAME; |
|
| 65 | - } |
|
| 62 | +public function getName(): string |
|
| 63 | +{ |
|
| 64 | +return self::NAME; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * @inheritDoc |
| 69 | 69 | */ |
| 70 | - public function getHash(): string |
|
| 71 | - { |
|
| 72 | - return '5.0.0'; // Use the version number as hash |
|
| 73 | - } |
|
| 70 | +public function getHash(): string |
|
| 71 | +{ |
|
| 72 | +return '5.0.0'; // Use the version number as hash |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @inheritDoc |
| 77 | 77 | */ |
| 78 | - public function getCss(): string |
|
| 79 | - { |
|
| 80 | - return ' |
|
| 78 | +public function getCss(): string |
|
| 79 | +{ |
|
| 80 | +return ' |
|
| 81 | 81 | <style> |
| 82 | 82 | .pagination li a { |
| 83 | 83 | cursor: pointer; |
| 84 | 84 | } |
| 85 | 85 | </style> |
| 86 | 86 | '; |
| 87 | - } |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * Get the view renderer |
| 91 | 91 | * |
| 92 | 92 | * @return RendererInterface |
| 93 | 93 | */ |
| 94 | - public function renderer(): RendererInterface |
|
| 95 | - { |
|
| 96 | - return $this->xRenderer; |
|
| 97 | - } |
|
| 94 | +public function renderer(): RendererInterface |
|
| 95 | +{ |
|
| 96 | +return $this->xRenderer; |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * Create a paginator |
| 101 | 101 | * |
| 102 | 102 | * @param int $nPageNumber The current page number |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return Paginator |
| 107 | 107 | */ |
| 108 | - public function paginator(int $nPageNumber, int $nItemsPerPage, int $nTotalItems): Paginator |
|
| 109 | - { |
|
| 110 | - return new Paginator($this, $nPageNumber, $nItemsPerPage, $nTotalItems); |
|
| 111 | - } |
|
| 108 | +public function paginator(int $nPageNumber, int $nItemsPerPage, int $nTotalItems): Paginator |
|
| 109 | +{ |
|
| 110 | +return new Paginator($this, $nPageNumber, $nItemsPerPage, $nTotalItems); |
|
| 111 | +} |
|
| 112 | 112 | } |
@@ -26,56 +26,56 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | class ScriptPlugin extends AbstractResponsePlugin |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @const The plugin name |
| 31 | 31 | */ |
| 32 | - public const NAME = 'script'; |
|
| 32 | +public const NAME = 'script'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * The class constructor |
| 36 | 36 | * |
| 37 | 37 | * @param CallFactory $xFactory |
| 38 | 38 | */ |
| 39 | - public function __construct(private CallFactory $xFactory) |
|
| 40 | - {} |
|
| 39 | +public function __construct(private CallFactory $xFactory) |
|
| 40 | +{} |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * @return Closure |
| 44 | 44 | */ |
| 45 | - private function getCallback(): Closure |
|
| 46 | - { |
|
| 47 | - // The closure needs to capture the response object the script plugin is called with. |
|
| 48 | - $xResponse = $this->response(); |
|
| 49 | - return function(JsExpr $xJsExpr) use($xResponse) { |
|
| 50 | - // Add the newly created expression to the response |
|
| 51 | - $aOptions = [ |
|
| 52 | - 'expr' => $xJsExpr, |
|
| 53 | - 'context' => is_a($xResponse, NodeResponse::class) ? |
|
| 54 | - ['component' => true] : [], |
|
| 55 | - ]; |
|
| 56 | - $xResponse->addCommand('script.exec.expr', $aOptions) |
|
| 57 | - ->setOption('plugin', $this->getName()); |
|
| 58 | - }; |
|
| 59 | - } |
|
| 45 | +private function getCallback(): Closure |
|
| 46 | +{ |
|
| 47 | +// The closure needs to capture the response object the script plugin is called with. |
|
| 48 | +$xResponse = $this->response(); |
|
| 49 | +return function(JsExpr $xJsExpr) use($xResponse) { |
|
| 50 | +// Add the newly created expression to the response |
|
| 51 | +$aOptions = [ |
|
| 52 | + 'expr' => $xJsExpr, |
|
| 53 | + 'context' => is_a($xResponse, NodeResponse::class) ? |
|
| 54 | + ['component' => true] : [], |
|
| 55 | +]; |
|
| 56 | +$xResponse->addCommand('script.exec.expr', $aOptions) |
|
| 57 | + ->setOption('plugin', $this->getName()); |
|
| 58 | +}; |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @inheritDoc |
| 63 | 63 | */ |
| 64 | - public function getName(): string |
|
| 65 | - { |
|
| 66 | - return self::NAME; |
|
| 67 | - } |
|
| 64 | +public function getName(): string |
|
| 65 | +{ |
|
| 66 | +return self::NAME; |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * @inheritDoc |
| 71 | 71 | */ |
| 72 | - public function getHash(): string |
|
| 73 | - { |
|
| 74 | - // Use the version number as hash |
|
| 75 | - return '5.0.0'; |
|
| 76 | - } |
|
| 72 | +public function getHash(): string |
|
| 73 | +{ |
|
| 74 | +// Use the version number as hash |
|
| 75 | +return '5.0.0'; |
|
| 76 | +} |
|
| 77 | 77 | |
| 78 | - /** |
|
| 78 | +/** |
|
| 79 | 79 | * Create a JQuery selector expression, and link it to the current response. |
| 80 | 80 | * |
| 81 | 81 | * @param string $sPath The jQuery selector path |
@@ -83,32 +83,32 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return JqSelectorCall |
| 85 | 85 | */ |
| 86 | - public function jq(string $sPath = '', $xContext = null): JqSelectorCall |
|
| 87 | - { |
|
| 88 | - return $this->xFactory->jq($sPath, $xContext, $this->getCallback()); |
|
| 89 | - } |
|
| 86 | +public function jq(string $sPath = '', $xContext = null): JqSelectorCall |
|
| 87 | +{ |
|
| 88 | +return $this->xFactory->jq($sPath, $xContext, $this->getCallback()); |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * Create a Javascript object expression, and link it to the current response. |
| 93 | 93 | * |
| 94 | 94 | * @param string $sObject |
| 95 | 95 | * |
| 96 | 96 | * @return JsObjectCall |
| 97 | 97 | */ |
| 98 | - public function jo(string $sObject = ''): JsObjectCall |
|
| 99 | - { |
|
| 100 | - return $this->xFactory->jo($sObject, $this->getCallback()); |
|
| 101 | - } |
|
| 98 | +public function jo(string $sObject = ''): JsObjectCall |
|
| 99 | +{ |
|
| 100 | +return $this->xFactory->jo($sObject, $this->getCallback()); |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Create a Javascript element selector expression, and link it to the current response. |
| 105 | 105 | * |
| 106 | 106 | * @param string $sElementId |
| 107 | 107 | * |
| 108 | 108 | * @return JsSelectorCall |
| 109 | 109 | */ |
| 110 | - public function je(string $sElementId = ''): JsSelectorCall |
|
| 111 | - { |
|
| 112 | - return $this->xFactory->je($sElementId, $this->getCallback()); |
|
| 113 | - } |
|
| 110 | +public function je(string $sElementId = ''): JsSelectorCall |
|
| 111 | +{ |
|
| 112 | +return $this->xFactory->je($sElementId, $this->getCallback()); |
|
| 113 | +} |
|
| 114 | 114 | } |
@@ -24,107 +24,107 @@ |
||
| 24 | 24 | |
| 25 | 25 | class DialogPlugin implements PluginInterface, ResponsePluginInterface, ModalInterface, AlertInterface |
| 26 | 26 | { |
| 27 | - use ResponsePluginTrait; |
|
| 27 | +use ResponsePluginTrait; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @const The plugin name |
| 31 | 31 | */ |
| 32 | - public const NAME = 'dialog'; |
|
| 32 | +public const NAME = 'dialog'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * The constructor |
| 36 | 36 | * |
| 37 | 37 | * @param DialogCommand $xDialogCommand |
| 38 | 38 | */ |
| 39 | - public function __construct(private DialogCommand $xDialogCommand) |
|
| 40 | - {} |
|
| 39 | +public function __construct(private DialogCommand $xDialogCommand) |
|
| 40 | +{} |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * @inheritDoc |
| 44 | 44 | */ |
| 45 | - public function getName(): string |
|
| 46 | - { |
|
| 47 | - return self::NAME; |
|
| 48 | - } |
|
| 45 | +public function getName(): string |
|
| 46 | +{ |
|
| 47 | +return self::NAME; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * Initialize the plugin |
| 52 | 52 | * |
| 53 | 53 | * @return void |
| 54 | 54 | */ |
| 55 | - protected function init(): void |
|
| 56 | - {} |
|
| 55 | +protected function init(): void |
|
| 56 | +{} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Set the library to use for the next call. |
| 60 | 60 | * |
| 61 | 61 | * @param string $sLibrary The name of the library |
| 62 | 62 | * |
| 63 | 63 | * @return DialogPlugin |
| 64 | 64 | */ |
| 65 | - public function with(string $sLibrary): DialogPlugin |
|
| 66 | - { |
|
| 67 | - $this->xDialogCommand->library($sLibrary); |
|
| 68 | - return $this; |
|
| 69 | - } |
|
| 65 | +public function with(string $sLibrary): DialogPlugin |
|
| 66 | +{ |
|
| 67 | +$this->xDialogCommand->library($sLibrary); |
|
| 68 | +return $this; |
|
| 69 | +} |
|
| 70 | 70 | |
| 71 | - /** |
|
| 71 | +/** |
|
| 72 | 72 | * @inheritDoc |
| 73 | 73 | */ |
| 74 | - public function show(string $sTitle, string $sContent, array $aButtons = [], array $aOptions = []): void |
|
| 75 | - { |
|
| 76 | - // Show the modal dialog |
|
| 77 | - $this->addCommand('dialog.modal.show', |
|
| 78 | - $this->xDialogCommand->show($sTitle, $sContent, $aButtons, $aOptions)); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 74 | +public function show(string $sTitle, string $sContent, array $aButtons = [], array $aOptions = []): void |
|
| 75 | +{ |
|
| 76 | +// Show the modal dialog |
|
| 77 | +$this->addCommand('dialog.modal.show', |
|
| 78 | +$this->xDialogCommand->show($sTitle, $sContent, $aButtons, $aOptions)); |
|
| 79 | +} |
|
| 80 | + |
|
| 81 | +/** |
|
| 82 | 82 | * @inheritDoc |
| 83 | 83 | */ |
| 84 | - public function hide(): void |
|
| 85 | - { |
|
| 86 | - // Hide the modal dialog |
|
| 87 | - $this->addCommand('dialog.modal.hide', $this->xDialogCommand->hide()); |
|
| 88 | - } |
|
| 84 | +public function hide(): void |
|
| 85 | +{ |
|
| 86 | +// Hide the modal dialog |
|
| 87 | +$this->addCommand('dialog.modal.hide', $this->xDialogCommand->hide()); |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * @inheritDoc |
| 92 | 92 | */ |
| 93 | - public function title(string $sTitle): AlertInterface |
|
| 94 | - { |
|
| 95 | - $this->xDialogCommand->title($sTitle); |
|
| 96 | - return $this; |
|
| 97 | - } |
|
| 93 | +public function title(string $sTitle): AlertInterface |
|
| 94 | +{ |
|
| 95 | +$this->xDialogCommand->title($sTitle); |
|
| 96 | +return $this; |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * @inheritDoc |
| 101 | 101 | */ |
| 102 | - public function success(string $sMessage, ...$aArgs): void |
|
| 103 | - { |
|
| 104 | - $this->addCommand('dialog.alert.show', $this->xDialogCommand->success($sMessage, $aArgs)); |
|
| 105 | - } |
|
| 102 | +public function success(string $sMessage, ...$aArgs): void |
|
| 103 | +{ |
|
| 104 | +$this->addCommand('dialog.alert.show', $this->xDialogCommand->success($sMessage, $aArgs)); |
|
| 105 | +} |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * @inheritDoc |
| 109 | 109 | */ |
| 110 | - public function info(string $sMessage, ...$aArgs): void |
|
| 111 | - { |
|
| 112 | - $this->addCommand('dialog.alert.show', $this->xDialogCommand->info($sMessage, $aArgs)); |
|
| 113 | - } |
|
| 110 | +public function info(string $sMessage, ...$aArgs): void |
|
| 111 | +{ |
|
| 112 | +$this->addCommand('dialog.alert.show', $this->xDialogCommand->info($sMessage, $aArgs)); |
|
| 113 | +} |
|
| 114 | 114 | |
| 115 | - /** |
|
| 115 | +/** |
|
| 116 | 116 | * @inheritDoc |
| 117 | 117 | */ |
| 118 | - public function warning(string $sMessage, ...$aArgs): void |
|
| 119 | - { |
|
| 120 | - $this->addCommand('dialog.alert.show', $this->xDialogCommand->warning($sMessage, $aArgs)); |
|
| 121 | - } |
|
| 118 | +public function warning(string $sMessage, ...$aArgs): void |
|
| 119 | +{ |
|
| 120 | +$this->addCommand('dialog.alert.show', $this->xDialogCommand->warning($sMessage, $aArgs)); |
|
| 121 | +} |
|
| 122 | 122 | |
| 123 | - /** |
|
| 123 | +/** |
|
| 124 | 124 | * @inheritDoc |
| 125 | 125 | */ |
| 126 | - public function error(string $sMessage, ...$aArgs): void |
|
| 127 | - { |
|
| 128 | - $this->addCommand('dialog.alert.show', $this->xDialogCommand->error($sMessage, $aArgs)); |
|
| 129 | - } |
|
| 126 | +public function error(string $sMessage, ...$aArgs): void |
|
| 127 | +{ |
|
| 128 | +$this->addCommand('dialog.alert.show', $this->xDialogCommand->error($sMessage, $aArgs)); |
|
| 129 | +} |
|
| 130 | 130 | } |
@@ -23,56 +23,56 @@ |
||
| 23 | 23 | |
| 24 | 24 | class PsrPlugin extends AbstractResponsePlugin |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @const The plugin name |
| 28 | 28 | */ |
| 29 | - public const NAME = 'psr'; |
|
| 29 | +public const NAME = 'psr'; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The class constructor |
| 33 | 33 | * |
| 34 | 34 | * @param Psr17Factory $xPsr17Factory |
| 35 | 35 | * @param RequestInterface $xRequest |
| 36 | 36 | */ |
| 37 | - public function __construct(private Psr17Factory $xPsr17Factory, |
|
| 38 | - private RequestInterface $xRequest) |
|
| 39 | - {} |
|
| 37 | +public function __construct(private Psr17Factory $xPsr17Factory, |
|
| 38 | +private RequestInterface $xRequest) |
|
| 39 | +{} |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * @inheritDoc |
| 43 | 43 | */ |
| 44 | - public function getName(): string |
|
| 45 | - { |
|
| 46 | - return self::NAME; |
|
| 47 | - } |
|
| 44 | +public function getName(): string |
|
| 45 | +{ |
|
| 46 | +return self::NAME; |
|
| 47 | +} |
|
| 48 | 48 | |
| 49 | - /** |
|
| 49 | +/** |
|
| 50 | 50 | * @inheritDoc |
| 51 | 51 | */ |
| 52 | - public function getHash(): string |
|
| 53 | - { |
|
| 54 | - // Use the version number as hash |
|
| 55 | - return '5.0.0'; |
|
| 56 | - } |
|
| 52 | +public function getHash(): string |
|
| 53 | +{ |
|
| 54 | +// Use the version number as hash |
|
| 55 | +return '5.0.0'; |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Convert an ajax response to a PSR7 response object |
| 60 | 60 | * |
| 61 | 61 | * @return ResponseInterface |
| 62 | 62 | */ |
| 63 | - public function ajaxResponse(): ResponseInterface |
|
| 64 | - { |
|
| 65 | - $xPsrResponse = $this->xPsr17Factory->createResponse(200); |
|
| 66 | - if($this->xRequest->getMethod() === 'GET') |
|
| 67 | - { |
|
| 68 | - $xPsrResponse = $xPsrResponse |
|
| 69 | - ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
|
| 70 | - ->withHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT') |
|
| 71 | - ->withHeader('Cache-Control', 'no-cache, must-revalidate') |
|
| 72 | - ->withHeader('Pragma', 'no-cache'); |
|
| 73 | - } |
|
| 74 | - return $xPsrResponse |
|
| 75 | - ->withHeader('content-type', $this->response()->getContentType()) |
|
| 76 | - ->withBody(Stream::create($this->response()->getOutput())); |
|
| 77 | - } |
|
| 63 | +public function ajaxResponse(): ResponseInterface |
|
| 64 | +{ |
|
| 65 | +$xPsrResponse = $this->xPsr17Factory->createResponse(200); |
|
| 66 | +if($this->xRequest->getMethod() === 'GET') |
|
| 67 | +{ |
|
| 68 | +$xPsrResponse = $xPsrResponse |
|
| 69 | + ->withHeader('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT') |
|
| 70 | + ->withHeader('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT') |
|
| 71 | + ->withHeader('Cache-Control', 'no-cache, must-revalidate') |
|
| 72 | + ->withHeader('Pragma', 'no-cache'); |
|
| 73 | +} |
|
| 74 | +return $xPsrResponse |
|
| 75 | +->withHeader('content-type', $this->response()->getContentType()) |
|
| 76 | +->withBody(Stream::create($this->response()->getOutput())); |
|
| 77 | +} |
|
| 78 | 78 | } |
@@ -18,43 +18,43 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class AbstractCodeGenerator implements CodeGeneratorInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * @inheritDoc |
| 23 | 23 | */ |
| 24 | - public function getHash(): string |
|
| 25 | - { |
|
| 26 | - return ''; |
|
| 27 | - } |
|
| 24 | +public function getHash(): string |
|
| 25 | +{ |
|
| 26 | +return ''; |
|
| 27 | +} |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @inheritDoc |
| 31 | 31 | */ |
| 32 | - public function getCss(): string |
|
| 33 | - { |
|
| 34 | - return ''; |
|
| 35 | - } |
|
| 32 | +public function getCss(): string |
|
| 33 | +{ |
|
| 34 | +return ''; |
|
| 35 | +} |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @inheritDoc |
| 39 | 39 | */ |
| 40 | - public function getJs(): string |
|
| 41 | - { |
|
| 42 | - return ''; |
|
| 43 | - } |
|
| 40 | +public function getJs(): string |
|
| 41 | +{ |
|
| 42 | +return ''; |
|
| 43 | +} |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @inheritDoc |
| 47 | 47 | */ |
| 48 | - public function getScript(): string |
|
| 49 | - { |
|
| 50 | - return ''; |
|
| 51 | - } |
|
| 48 | +public function getScript(): string |
|
| 49 | +{ |
|
| 50 | +return ''; |
|
| 51 | +} |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * @inheritDoc |
| 55 | 55 | */ |
| 56 | - public function getJsCode(): ?JsCode |
|
| 57 | - { |
|
| 58 | - return null; |
|
| 59 | - } |
|
| 56 | +public function getJsCode(): ?JsCode |
|
| 57 | +{ |
|
| 58 | +return null; |
|
| 59 | +} |
|
| 60 | 60 | } |
@@ -31,48 +31,48 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | trait ResponsePluginTrait |
| 33 | 33 | { |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * The object used to build the response that will be sent to the client browser |
| 36 | 36 | * |
| 37 | 37 | * @var AbstractResponse |
| 38 | 38 | */ |
| 39 | - private $xResponse = null; |
|
| 39 | +private $xResponse = null; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * Get a unique name to identify the plugin. |
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - abstract public function getName(): string; |
|
| 46 | +abstract public function getName(): string; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Initialize the plugin |
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - abstract protected function init(); |
|
| 53 | +abstract protected function init(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * @param AbstractResponse $xResponse The response |
| 57 | 57 | * |
| 58 | 58 | * @return static |
| 59 | 59 | */ |
| 60 | - public function initPlugin(AbstractResponse $xResponse): static |
|
| 61 | - { |
|
| 62 | - $this->xResponse = $xResponse; |
|
| 63 | - $this->init(); |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 60 | +public function initPlugin(AbstractResponse $xResponse): static |
|
| 61 | +{ |
|
| 62 | +$this->xResponse = $xResponse; |
|
| 63 | +$this->init(); |
|
| 64 | +return $this; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * @inheritDoc |
| 69 | 69 | */ |
| 70 | - public function response(): ?AbstractResponse |
|
| 71 | - { |
|
| 72 | - return $this->xResponse; |
|
| 73 | - } |
|
| 70 | +public function response(): ?AbstractResponse |
|
| 71 | +{ |
|
| 72 | +return $this->xResponse; |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * Add a plugin command to the response |
| 77 | 77 | * |
| 78 | 78 | * @param string $sName The command name |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return Command |
| 82 | 82 | */ |
| 83 | - public function addCommand(string $sName, array|JsonSerializable $aOptions): Command |
|
| 84 | - { |
|
| 85 | - return $this->xResponse |
|
| 86 | - ->addCommand($sName, $aOptions) |
|
| 87 | - ->setOption('plugin', $this->getName()); |
|
| 88 | - } |
|
| 83 | +public function addCommand(string $sName, array|JsonSerializable $aOptions): Command |
|
| 84 | +{ |
|
| 85 | +return $this->xResponse |
|
| 86 | +->addCommand($sName, $aOptions) |
|
| 87 | +->setOption('plugin', $this->getName()); |
|
| 88 | +} |
|
| 89 | 89 | } |
@@ -17,46 +17,46 @@ |
||
| 17 | 17 | |
| 18 | 18 | interface CodeGeneratorInterface |
| 19 | 19 | { |
| 20 | - /** |
|
| 20 | +/** |
|
| 21 | 21 | * Get the value to be hashed |
| 22 | 22 | * |
| 23 | 23 | * @return string |
| 24 | 24 | */ |
| 25 | - public function getHash(): string; |
|
| 25 | +public function getHash(): string; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 27 | +/** |
|
| 28 | 28 | * Get the HTML tags to include CSS code and files into the page |
| 29 | 29 | * |
| 30 | 30 | * The code must be enclosed in the appropriate HTML tags. |
| 31 | 31 | * |
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function getCss(): string; |
|
| 34 | +public function getCss(): string; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the HTML tags to include javascript code and files into the page |
| 38 | 38 | * |
| 39 | 39 | * The code must be enclosed in the appropriate HTML tags. |
| 40 | 40 | * |
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | - public function getJs(): string; |
|
| 43 | +public function getJs(): string; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * Get the javascript code to include into the page |
| 47 | 47 | * |
| 48 | 48 | * The code must NOT be enclosed in HTML tags. |
| 49 | 49 | * |
| 50 | 50 | * @return string |
| 51 | 51 | */ |
| 52 | - public function getScript(): string; |
|
| 52 | +public function getScript(): string; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Get the javascript codes to include into the page |
| 56 | 56 | * |
| 57 | 57 | * The code must NOT be enclosed in HTML tags. |
| 58 | 58 | * |
| 59 | 59 | * @return JsCode|null |
| 60 | 60 | */ |
| 61 | - public function getJsCode(): ?JsCode; |
|
| 61 | +public function getJsCode(): ?JsCode; |
|
| 62 | 62 | } |
@@ -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 | } |