@@ -33,111 +33,111 @@ |
||
| 33 | 33 | |
| 34 | 34 | final class Jaxon |
| 35 | 35 | { |
| 36 | - use Traits\ConfigTrait; |
|
| 37 | - use Traits\ServicesTrait; |
|
| 38 | - use Traits\PluginTrait; |
|
| 39 | - use Traits\RequestTrait; |
|
| 40 | - use Traits\ResponseTrait; |
|
| 41 | - use Traits\SendResponseTrait; |
|
| 42 | - |
|
| 43 | - /** |
|
| 36 | +use Traits\ConfigTrait; |
|
| 37 | +use Traits\ServicesTrait; |
|
| 38 | +use Traits\PluginTrait; |
|
| 39 | +use Traits\RequestTrait; |
|
| 40 | +use Traits\ResponseTrait; |
|
| 41 | +use Traits\SendResponseTrait; |
|
| 42 | + |
|
| 43 | +/** |
|
| 44 | 44 | * @var Jaxon |
| 45 | 45 | */ |
| 46 | - private static $xInstance = null; |
|
| 46 | +private static $xInstance = null; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * The constructor |
| 50 | 50 | * |
| 51 | 51 | * @param Container $xContainer |
| 52 | 52 | * @param ComponentContainer $xComponentContainer |
| 53 | 53 | */ |
| 54 | - private function __construct(Container $xContainer, ComponentContainer $xComponentContainer) |
|
| 55 | - { |
|
| 56 | - $this->xContainer = $xContainer; |
|
| 57 | - $this->xComponentContainer = $xComponentContainer; |
|
| 58 | - } |
|
| 54 | +private function __construct(Container $xContainer, ComponentContainer $xComponentContainer) |
|
| 55 | +{ |
|
| 56 | +$this->xContainer = $xContainer; |
|
| 57 | +$this->xComponentContainer = $xComponentContainer; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @return Jaxon |
| 62 | 62 | */ |
| 63 | - private static function createInstance(): Jaxon |
|
| 64 | - { |
|
| 65 | - $xContainer = new Container(); |
|
| 66 | - $xComponentContainer = new ComponentContainer($xContainer); |
|
| 67 | - self::$xInstance = new Jaxon($xContainer, $xComponentContainer); |
|
| 63 | +private static function createInstance(): Jaxon |
|
| 64 | +{ |
|
| 65 | +$xContainer = new Container(); |
|
| 66 | +$xComponentContainer = new ComponentContainer($xContainer); |
|
| 67 | +self::$xInstance = new Jaxon($xContainer, $xComponentContainer); |
|
| 68 | 68 | |
| 69 | - // Save the Jaxon and container instances |
|
| 70 | - $xContainer->val(Jaxon::class, self::$xInstance); |
|
| 71 | - $xContainer->val(ComponentContainer::class, $xComponentContainer); |
|
| 69 | +// Save the Jaxon and container instances |
|
| 70 | +$xContainer->val(Jaxon::class, self::$xInstance); |
|
| 71 | +$xContainer->val(ComponentContainer::class, $xComponentContainer); |
|
| 72 | 72 | |
| 73 | - // Make the helpers functions available in the global namespace. |
|
| 74 | - self::$xInstance->getCallbackManager()->boot(function() { |
|
| 75 | - self::$xInstance->config()->globals(); |
|
| 76 | - }); |
|
| 73 | +// Make the helpers functions available in the global namespace. |
|
| 74 | +self::$xInstance->getCallbackManager()->boot(function() { |
|
| 75 | +self::$xInstance->config()->globals(); |
|
| 76 | +}); |
|
| 77 | 77 | |
| 78 | - return self::$xInstance; |
|
| 79 | - } |
|
| 78 | +return self::$xInstance; |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * @return Jaxon |
| 83 | 83 | */ |
| 84 | - public static function getInstance(): Jaxon |
|
| 85 | - { |
|
| 86 | - return self::$xInstance ?: self::$xInstance = self::createInstance(); |
|
| 87 | - } |
|
| 84 | +public static function getInstance(): Jaxon |
|
| 85 | +{ |
|
| 86 | +return self::$xInstance ?: self::$xInstance = self::createInstance(); |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | - public function getVersion(): string |
|
| 93 | - { |
|
| 94 | - return \Jaxon\Jaxon::VERSION; |
|
| 95 | - } |
|
| 92 | +public function getVersion(): string |
|
| 93 | +{ |
|
| 94 | +return \Jaxon\Jaxon::VERSION; |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * @return ConfigManager |
| 99 | 99 | */ |
| 100 | - public function config(): ConfigManager |
|
| 101 | - { |
|
| 102 | - return $this->di()->g(ConfigManager::class); |
|
| 103 | - } |
|
| 100 | +public function config(): ConfigManager |
|
| 101 | +{ |
|
| 102 | +return $this->di()->g(ConfigManager::class); |
|
| 103 | +} |
|
| 104 | 104 | |
| 105 | - /** |
|
| 105 | +/** |
|
| 106 | 106 | * Set the ajax endpoint URI |
| 107 | 107 | * |
| 108 | 108 | * @param string $sUri The ajax endpoint URI |
| 109 | 109 | * |
| 110 | 110 | * @return void |
| 111 | 111 | */ |
| 112 | - public function setUri(string $sUri): void |
|
| 113 | - { |
|
| 114 | - $this->config()->setOption('core.request.uri', $sUri); |
|
| 115 | - } |
|
| 112 | +public function setUri(string $sUri): void |
|
| 113 | +{ |
|
| 114 | +$this->config()->setOption('core.request.uri', $sUri); |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - /** |
|
| 117 | +/** |
|
| 118 | 118 | * @return AppInterface |
| 119 | 119 | */ |
| 120 | - public function app(): AppInterface |
|
| 121 | - { |
|
| 122 | - return $this->xContainer->getApp(); |
|
| 123 | - } |
|
| 120 | +public function app(): AppInterface |
|
| 121 | +{ |
|
| 122 | +return $this->xContainer->getApp(); |
|
| 123 | +} |
|
| 124 | 124 | |
| 125 | - /** |
|
| 125 | +/** |
|
| 126 | 126 | * Get the callback manager |
| 127 | 127 | * |
| 128 | 128 | * @return CallbackManager |
| 129 | 129 | */ |
| 130 | - public function callback(): CallbackManager |
|
| 131 | - { |
|
| 132 | - return $this->getCallbackManager(); |
|
| 133 | - } |
|
| 130 | +public function callback(): CallbackManager |
|
| 131 | +{ |
|
| 132 | +return $this->getCallbackManager(); |
|
| 133 | +} |
|
| 134 | 134 | |
| 135 | - /** |
|
| 135 | +/** |
|
| 136 | 136 | * @return void |
| 137 | 137 | * @throws SetupException |
| 138 | 138 | */ |
| 139 | - public function reset(): void |
|
| 140 | - { |
|
| 141 | - self::$xInstance = null; |
|
| 142 | - } |
|
| 139 | +public function reset(): void |
|
| 140 | +{ |
|
| 141 | +self::$xInstance = null; |
|
| 142 | +} |
|
| 143 | 143 | } |
@@ -22,58 +22,58 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | interface AppInterface |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * Set the logger. |
| 27 | 27 | * |
| 28 | 28 | * @param LoggerInterface|Closure $xLogger |
| 29 | 29 | * |
| 30 | 30 | * @return void |
| 31 | 31 | */ |
| 32 | - public function setLogger(LoggerInterface|Closure $xLogger): void; |
|
| 32 | +public function setLogger(LoggerInterface|Closure $xLogger): void; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * Get the configured character encoding |
| 36 | 36 | * |
| 37 | 37 | * @return string |
| 38 | 38 | */ |
| 39 | - public function getCharacterEncoding(): string; |
|
| 39 | +public function getCharacterEncoding(): string; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * Get the content type of the HTTP response |
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public function getContentType(): string; |
|
| 46 | +public function getContentType(): string; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Get the HTML tags to include Jaxon javascript files into the page. |
| 50 | 50 | * |
| 51 | 51 | * @return string |
| 52 | 52 | */ |
| 53 | - public function getJs(): string; |
|
| 53 | +public function getJs(): string; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Get the HTML tags to include Jaxon javascript files into the page. |
| 57 | 57 | * |
| 58 | 58 | * @return string the javascript code |
| 59 | 59 | */ |
| 60 | - public function js(): string; |
|
| 60 | +public function js(): string; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * Get the HTML tags to include Jaxon CSS code and files into the page. |
| 64 | 64 | * |
| 65 | 65 | * @return string |
| 66 | 66 | */ |
| 67 | - public function getCss(): string; |
|
| 67 | +public function getCss(): string; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * Get the HTML tags to include Jaxon CSS code and files into the page. |
| 71 | 71 | * |
| 72 | 72 | * @return string the javascript code |
| 73 | 73 | */ |
| 74 | - public function css(): string; |
|
| 74 | +public function css(): string; |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * Returns the js header and wrapper code to be printed into the page |
| 78 | 78 | * |
| 79 | 79 | * The javascript code returned by this function is dependent on the plugins |
@@ -84,9 +84,9 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | - public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string; |
|
| 87 | +public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * Returns the js header and wrapper code to be printed into the page |
| 91 | 91 | * |
| 92 | 92 | * @param bool $bIncludeJs Also get the JS files |
@@ -95,46 +95,46 @@ discard block |
||
| 95 | 95 | * @return string the javascript code |
| 96 | 96 | * @throws UriException |
| 97 | 97 | */ |
| 98 | - public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string; |
|
| 98 | +public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string; |
|
| 99 | 99 | |
| 100 | - /** |
|
| 100 | +/** |
|
| 101 | 101 | * Determine if a call is a jaxon request or a page load request |
| 102 | 102 | * |
| 103 | 103 | * @return bool |
| 104 | 104 | */ |
| 105 | - public function canProcessRequest(): bool; |
|
| 105 | +public function canProcessRequest(): bool; |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * Process an incoming Jaxon request, and return the response. |
| 109 | 109 | * |
| 110 | 110 | * @return mixed |
| 111 | 111 | */ |
| 112 | - public function processRequest(): mixed; |
|
| 112 | +public function processRequest(): mixed; |
|
| 113 | 113 | |
| 114 | - /** |
|
| 114 | +/** |
|
| 115 | 115 | * Get the Jaxon ajax response |
| 116 | 116 | * |
| 117 | 117 | * @return AjaxResponse |
| 118 | 118 | */ |
| 119 | - public function ajaxResponse(): AjaxResponse; |
|
| 119 | +public function ajaxResponse(): AjaxResponse; |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * @param Closure $xClosure A closure to create the session manager instance |
| 123 | 123 | * |
| 124 | 124 | * @return void |
| 125 | 125 | */ |
| 126 | - public function setSessionManager(Closure $xClosure); |
|
| 126 | +public function setSessionManager(Closure $xClosure); |
|
| 127 | 127 | |
| 128 | - /** |
|
| 128 | +/** |
|
| 129 | 129 | * Set the container provided by the integrated framework |
| 130 | 130 | * |
| 131 | 131 | * @param ContainerInterface $xContainer The container implementation |
| 132 | 132 | * |
| 133 | 133 | * @return void |
| 134 | 134 | */ |
| 135 | - public function setContainer(ContainerInterface $xContainer); |
|
| 135 | +public function setContainer(ContainerInterface $xContainer); |
|
| 136 | 136 | |
| 137 | - /** |
|
| 137 | +/** |
|
| 138 | 138 | * Add a view renderer with an id |
| 139 | 139 | * |
| 140 | 140 | * @param string $sRenderer The renderer name |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @return void |
| 145 | 145 | */ |
| 146 | - public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure); |
|
| 146 | +public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure); |
|
| 147 | 147 | |
| 148 | - /** |
|
| 148 | +/** |
|
| 149 | 149 | * Set the javascript asset |
| 150 | 150 | * |
| 151 | 151 | * @param bool $bExport Whether to export the js code in a file |
@@ -155,14 +155,14 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return void |
| 157 | 157 | */ |
| 158 | - public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): void; |
|
| 158 | +public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): void; |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * Read config options from a config file and set up the library |
| 162 | 162 | * |
| 163 | 163 | * @param string $sConfigFile The full path to the config file |
| 164 | 164 | * |
| 165 | 165 | * @return void |
| 166 | 166 | */ |
| 167 | - public function setup(string $sConfigFile = ''): void; |
|
| 167 | +public function setup(string $sConfigFile = ''): void; |
|
| 168 | 168 | } |
@@ -20,32 +20,32 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | abstract class AbstractApp implements AppInterface |
| 22 | 22 | { |
| 23 | - use Traits\ServicesTrait; |
|
| 24 | - use Traits\PluginTrait; |
|
| 25 | - use Traits\RequestTrait; |
|
| 26 | - use Traits\ResponseTrait; |
|
| 23 | +use Traits\ServicesTrait; |
|
| 24 | +use Traits\PluginTrait; |
|
| 25 | +use Traits\RequestTrait; |
|
| 26 | +use Traits\ResponseTrait; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * The class constructor |
| 30 | 30 | */ |
| 31 | - public function __construct() |
|
| 32 | - { |
|
| 33 | - // Declared in DiTrait. |
|
| 34 | - $this->xContainer = Jaxon::getInstance()->di(); |
|
| 35 | - $this->xComponentContainer = Jaxon::getInstance()->cdi(); |
|
| 36 | - } |
|
| 31 | +public function __construct() |
|
| 32 | +{ |
|
| 33 | +// Declared in DiTrait. |
|
| 34 | +$this->xContainer = Jaxon::getInstance()->di(); |
|
| 35 | +$this->xComponentContainer = Jaxon::getInstance()->cdi(); |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * Get the Jaxon application bootstrapper. |
| 40 | 40 | * |
| 41 | 41 | * @return Bootstrap |
| 42 | 42 | */ |
| 43 | - protected function bootstrap(): Bootstrap |
|
| 44 | - { |
|
| 45 | - return $this->xContainer->getBootstrap(); |
|
| 46 | - } |
|
| 43 | +protected function bootstrap(): Bootstrap |
|
| 44 | +{ |
|
| 45 | +return $this->xContainer->getBootstrap(); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * Set the javascript asset |
| 50 | 50 | * |
| 51 | 51 | * @param bool $bExport Whether to export the js code in a file |
@@ -55,26 +55,26 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): void |
|
| 59 | - { |
|
| 60 | - $this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir); |
|
| 61 | - } |
|
| 58 | +public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): void |
|
| 59 | +{ |
|
| 60 | +$this->bootstrap()->asset($bExport, $bMinify, $sUri, $sDir); |
|
| 61 | +} |
|
| 62 | 62 | |
| 63 | - /** |
|
| 63 | +/** |
|
| 64 | 64 | * Set the container provided by the integrated framework |
| 65 | 65 | * |
| 66 | 66 | * @param ContainerInterface $xContainer The container implementation |
| 67 | 67 | * |
| 68 | 68 | * @return void |
| 69 | 69 | */ |
| 70 | - public function setContainer(ContainerInterface $xContainer): void |
|
| 71 | - { |
|
| 72 | - $this->di()->setContainer($xContainer); |
|
| 73 | - } |
|
| 70 | +public function setContainer(ContainerInterface $xContainer): void |
|
| 71 | +{ |
|
| 72 | +$this->di()->setContainer($xContainer); |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @inheritDoc |
| 77 | 77 | */ |
| 78 | - public function setup(string $sConfigFile = ''): void |
|
| 79 | - {} |
|
| 78 | +public function setup(string $sConfigFile = ''): void |
|
| 79 | +{} |
|
| 80 | 80 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | interface ViewInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 7 | +/** |
|
| 8 | 8 | * Add a namespace to the view renderer |
| 9 | 9 | * |
| 10 | 10 | * @param string $sNamespace The namespace name |
@@ -13,14 +13,14 @@ discard block |
||
| 13 | 13 | * |
| 14 | 14 | * @return void |
| 15 | 15 | */ |
| 16 | - public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void; |
|
| 16 | +public function addNamespace(string $sNamespace, string $sDirectory, string $sExtension = ''): void; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * Render a view |
| 20 | 20 | * |
| 21 | 21 | * @param Store $store A store populated with the view data |
| 22 | 22 | * |
| 23 | 23 | * @return string |
| 24 | 24 | */ |
| 25 | - public function render(Store $store): string; |
|
| 25 | +public function render(Store $store): string; |
|
| 26 | 26 | } |
@@ -23,33 +23,33 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | class EventAttr |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * @var array |
| 28 | 28 | */ |
| 29 | - private array $aHandlers = []; |
|
| 29 | +private array $aHandlers = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * The constructor |
| 33 | 33 | * |
| 34 | 34 | * @param string $sSelector |
| 35 | 35 | */ |
| 36 | - public function __construct(private string $sSelector) |
|
| 37 | - {} |
|
| 36 | +public function __construct(private string $sSelector) |
|
| 37 | +{} |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * Set a selector for the next event handler |
| 41 | 41 | * |
| 42 | 42 | * @param string $sSelector |
| 43 | 43 | * |
| 44 | 44 | * @return self |
| 45 | 45 | */ |
| 46 | - public function select(string $sSelector): self |
|
| 47 | - { |
|
| 48 | - $this->sSelector = trim($sSelector); |
|
| 49 | - return $this; |
|
| 50 | - } |
|
| 46 | +public function select(string $sSelector): self |
|
| 47 | +{ |
|
| 48 | +$this->sSelector = trim($sSelector); |
|
| 49 | +return $this; |
|
| 50 | +} |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * Set an event handler with the "on" keyword |
| 54 | 54 | * |
| 55 | 55 | * @param string $event |
@@ -57,43 +57,43 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return self |
| 59 | 59 | */ |
| 60 | - public function on(string $event, JsExpr $xJsExpr): self |
|
| 61 | - { |
|
| 62 | - if($this->sSelector === '') |
|
| 63 | - { |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 60 | +public function on(string $event, JsExpr $xJsExpr): self |
|
| 61 | +{ |
|
| 62 | +if($this->sSelector === '') |
|
| 63 | +{ |
|
| 64 | +return $this; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - $this->aHandlers[] = [ |
|
| 68 | - 'select' => $this->sSelector, |
|
| 69 | - 'event' => trim($event), |
|
| 70 | - 'handler' => $xJsExpr, |
|
| 71 | - ]; |
|
| 72 | - $this->sSelector = ''; |
|
| 73 | - return $this; |
|
| 74 | - } |
|
| 67 | +$this->aHandlers[] = [ |
|
| 68 | +'select' => $this->sSelector, |
|
| 69 | +'event' => trim($event), |
|
| 70 | +'handler' => $xJsExpr, |
|
| 71 | +]; |
|
| 72 | +$this->sSelector = ''; |
|
| 73 | +return $this; |
|
| 74 | +} |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * Shortcut to set a click event handler |
| 78 | 78 | * |
| 79 | 79 | * @param JsExpr $xJsExpr |
| 80 | 80 | * |
| 81 | 81 | * @return self |
| 82 | 82 | */ |
| 83 | - public function click(JsExpr $xJsExpr): self |
|
| 84 | - { |
|
| 85 | - return $this->on('click', $xJsExpr); |
|
| 86 | - } |
|
| 83 | +public function click(JsExpr $xJsExpr): self |
|
| 84 | +{ |
|
| 85 | +return $this->on('click', $xJsExpr); |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * Convert to string. |
| 90 | 90 | * |
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | - public function __toString(): string |
|
| 94 | - { |
|
| 95 | - // No output if no handler is defined. |
|
| 96 | - return count($this->aHandlers) === 0 ? '' : 'jxn-event="' . |
|
| 97 | - htmlentities(json_encode($this->aHandlers)) . '"'; |
|
| 98 | - } |
|
| 93 | +public function __toString(): string |
|
| 94 | +{ |
|
| 95 | +// No output if no handler is defined. |
|
| 96 | +return count($this->aHandlers) === 0 ? '' : 'jxn-event="' . |
|
| 97 | +htmlentities(json_encode($this->aHandlers)) . '"'; |
|
| 98 | +} |
|
| 99 | 99 | } |
@@ -31,40 +31,40 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | class HtmlAttrHelper |
| 33 | 33 | { |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @var string|null |
| 36 | 36 | */ |
| 37 | - private string|null $sPaginationComponent = null; |
|
| 37 | +private string|null $sPaginationComponent = null; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * The constructor |
| 41 | 41 | * |
| 42 | 42 | * @param ComponentContainer $cdi |
| 43 | 43 | */ |
| 44 | - public function __construct(protected ComponentContainer $cdi) |
|
| 45 | - {} |
|
| 44 | +public function __construct(protected ComponentContainer $cdi) |
|
| 45 | +{} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * Get the component HTML code |
| 49 | 49 | * |
| 50 | 50 | * @param JxnCall $xJsCall |
| 51 | 51 | * |
| 52 | 52 | * @return string |
| 53 | 53 | */ |
| 54 | - public function html(JxnCall $xJsCall): string |
|
| 55 | - { |
|
| 56 | - $sClassName = $xJsCall->_class(); |
|
| 57 | - if(!$sClassName) |
|
| 58 | - { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $xComponent = $this->cdi->makeComponent($sClassName); |
|
| 63 | - return is_a($xComponent, NodeComponent::class) ? |
|
| 64 | - (string)$xComponent->html() : ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 54 | +public function html(JxnCall $xJsCall): string |
|
| 55 | +{ |
|
| 56 | +$sClassName = $xJsCall->_class(); |
|
| 57 | +if(!$sClassName) |
|
| 58 | +{ |
|
| 59 | +return ''; |
|
| 60 | +} |
|
| 61 | + |
|
| 62 | +$xComponent = $this->cdi->makeComponent($sClassName); |
|
| 63 | +return is_a($xComponent, NodeComponent::class) ? |
|
| 64 | +(string)$xComponent->html() : ''; |
|
| 65 | +} |
|
| 66 | + |
|
| 67 | +/** |
|
| 68 | 68 | * Attach a component to a DOM node |
| 69 | 69 | * |
| 70 | 70 | * @param JxnCall $xJsCall |
@@ -72,41 +72,41 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return string |
| 74 | 74 | */ |
| 75 | - public function bind(JxnCall $xJsCall, string $item = ''): string |
|
| 76 | - { |
|
| 77 | - $item = trim($item); |
|
| 78 | - return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"'); |
|
| 79 | - } |
|
| 75 | +public function bind(JxnCall $xJsCall, string $item = ''): string |
|
| 76 | +{ |
|
| 77 | +$item = trim($item); |
|
| 78 | +return 'jxn-bind="' . $xJsCall->_class() . (!$item ? '"' : '" jxn-item="' . $item . '"'); |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * Attach the pagination component to a DOM node |
| 83 | 83 | * |
| 84 | 84 | * @param JxnCall $xJsCall |
| 85 | 85 | * |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public function pagination(JxnCall $xJsCall): string |
|
| 89 | - { |
|
| 90 | - // The pagination is always rendered with the same Pagination component. |
|
| 91 | - $sComponent = $this->sPaginationComponent ?: |
|
| 92 | - ($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 93 | - $sItem = $xJsCall->_class(); |
|
| 94 | - return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\""; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 88 | +public function pagination(JxnCall $xJsCall): string |
|
| 89 | +{ |
|
| 90 | +// The pagination is always rendered with the same Pagination component. |
|
| 91 | +$sComponent = $this->sPaginationComponent ?: |
|
| 92 | +($this->sPaginationComponent = rq(Pagination::class)->_class()); |
|
| 93 | +$sItem = $xJsCall->_class(); |
|
| 94 | +return "jxn-bind=\"$sComponent\" jxn-item=\"$sItem\""; |
|
| 95 | +} |
|
| 96 | + |
|
| 97 | +/** |
|
| 98 | 98 | * Set a selector for the next event handler |
| 99 | 99 | * |
| 100 | 100 | * @param string $sSelector |
| 101 | 101 | * |
| 102 | 102 | * @return EventAttr |
| 103 | 103 | */ |
| 104 | - public function select(string $sSelector): EventAttr |
|
| 105 | - { |
|
| 106 | - return new EventAttr($sSelector); |
|
| 107 | - } |
|
| 104 | +public function select(string $sSelector): EventAttr |
|
| 105 | +{ |
|
| 106 | +return new EventAttr($sSelector); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Set an event handler |
| 111 | 111 | * |
| 112 | 112 | * @param string $event |
@@ -114,83 +114,83 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | - public function on(string $event, JsExpr $xJsExpr): string |
|
| 118 | - { |
|
| 119 | - $event = trim($event); |
|
| 120 | - $sCall = htmlentities(json_encode($xJsExpr->jsonSerialize())); |
|
| 121 | - return "jxn-on=\"$event\" jxn-call=\"$sCall\""; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 117 | +public function on(string $event, JsExpr $xJsExpr): string |
|
| 118 | +{ |
|
| 119 | +$event = trim($event); |
|
| 120 | +$sCall = htmlentities(json_encode($xJsExpr->jsonSerialize())); |
|
| 121 | +return "jxn-on=\"$event\" jxn-call=\"$sCall\""; |
|
| 122 | +} |
|
| 123 | + |
|
| 124 | +/** |
|
| 125 | 125 | * Shortcut to set a click event handler |
| 126 | 126 | * |
| 127 | 127 | * @param JsExpr $xJsExpr |
| 128 | 128 | * |
| 129 | 129 | * @return string |
| 130 | 130 | */ |
| 131 | - public function click(JsExpr $xJsExpr): string |
|
| 132 | - { |
|
| 133 | - return $this->on('click', $xJsExpr); |
|
| 134 | - } |
|
| 131 | +public function click(JsExpr $xJsExpr): string |
|
| 132 | +{ |
|
| 133 | +return $this->on('click', $xJsExpr); |
|
| 134 | +} |
|
| 135 | 135 | |
| 136 | - /** |
|
| 136 | +/** |
|
| 137 | 137 | * @param array $aHandler |
| 138 | 138 | * |
| 139 | 139 | * @return bool |
| 140 | 140 | */ |
| 141 | - private function eventIsValid(array $aHandler): bool |
|
| 142 | - { |
|
| 143 | - return count($aHandler) === 3 && |
|
| 144 | - isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) && |
|
| 145 | - is_string($aHandler[0]) && is_string($aHandler[1]) && |
|
| 146 | - is_a($aHandler[2], JsExpr::class); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 141 | +private function eventIsValid(array $aHandler): bool |
|
| 142 | +{ |
|
| 143 | +return count($aHandler) === 3 && |
|
| 144 | +isset($aHandler[0]) && isset($aHandler[1]) && isset($aHandler[2]) && |
|
| 145 | +is_string($aHandler[0]) && is_string($aHandler[1]) && |
|
| 146 | +is_a($aHandler[2], JsExpr::class); |
|
| 147 | +} |
|
| 148 | + |
|
| 149 | +/** |
|
| 150 | 150 | * @param array $aHandler |
| 151 | 151 | * @param EventAttr|null $xAttr |
| 152 | 152 | * |
| 153 | 153 | * @return EventAttr|null |
| 154 | 154 | */ |
| 155 | - private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null |
|
| 156 | - { |
|
| 157 | - if(!$this->eventIsValid($aHandler)) |
|
| 158 | - { |
|
| 159 | - return $xAttr; |
|
| 160 | - } |
|
| 161 | - // The array content is valid. |
|
| 162 | - [$sSelector, $sEvent, $xJsExpr] = $aHandler; |
|
| 163 | - return !$xAttr ? |
|
| 164 | - $this->select($sSelector)->on($sEvent, $xJsExpr) : |
|
| 165 | - $xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 155 | +private function setEventHandler(array $aHandler, ?EventAttr $xAttr = null): EventAttr|null |
|
| 156 | +{ |
|
| 157 | +if(!$this->eventIsValid($aHandler)) |
|
| 158 | +{ |
|
| 159 | +return $xAttr; |
|
| 160 | +} |
|
| 161 | +// The array content is valid. |
|
| 162 | +[$sSelector, $sEvent, $xJsExpr] = $aHandler; |
|
| 163 | +return !$xAttr ? |
|
| 164 | +$this->select($sSelector)->on($sEvent, $xJsExpr) : |
|
| 165 | +$xAttr->select($sSelector)->on($sEvent, $xJsExpr); |
|
| 166 | +} |
|
| 167 | + |
|
| 168 | +/** |
|
| 169 | 169 | * Set an event handler |
| 170 | 170 | * |
| 171 | 171 | * @param array $aHandler |
| 172 | 172 | * |
| 173 | 173 | * @return string |
| 174 | 174 | */ |
| 175 | - public function event(array $aHandler): string |
|
| 176 | - { |
|
| 177 | - return $this->setEventHandler($aHandler)?->__toString() ?? ''; |
|
| 178 | - } |
|
| 175 | +public function event(array $aHandler): string |
|
| 176 | +{ |
|
| 177 | +return $this->setEventHandler($aHandler)?->__toString() ?? ''; |
|
| 178 | +} |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | +/** |
|
| 181 | 181 | * Set event handlers |
| 182 | 182 | * |
| 183 | 183 | * @param array $aHandlers |
| 184 | 184 | * |
| 185 | 185 | * @return string |
| 186 | 186 | */ |
| 187 | - public function events(array $aHandlers): string |
|
| 188 | - { |
|
| 189 | - return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler) |
|
| 190 | - => $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? ''; |
|
| 191 | - } |
|
| 187 | +public function events(array $aHandlers): string |
|
| 188 | +{ |
|
| 189 | +return array_reduce($aHandlers, fn(EventAttr|null $xAttr, array $aHandler) |
|
| 190 | +=> $this->setEventHandler($aHandler, $xAttr), null)?->__toString() ?? ''; |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - /** |
|
| 193 | +/** |
|
| 194 | 194 | * Get the HTML or Javascript ready code for a package |
| 195 | 195 | * |
| 196 | 196 | * @param string $sClass |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | * |
| 199 | 199 | * @return string |
| 200 | 200 | */ |
| 201 | - public function package(string $sClass, string $sType = 'html'): string |
|
| 202 | - { |
|
| 203 | - $sCode = match($sType) { |
|
| 204 | - 'html' => jaxon()->package($sClass)?->getHtml() ?? '', |
|
| 205 | - 'ready' => jaxon()->package($sClass)?->getReadyScript() ?? '', |
|
| 206 | - default => '' |
|
| 207 | - }; |
|
| 208 | - $sCode = trim($sCode); |
|
| 209 | - |
|
| 210 | - return $sType !== 'ready' || $sCode === '' ? $sCode : |
|
| 211 | - // Call the ready code with the jaxon.dom.ready function. |
|
| 212 | - "jaxon.dom.ready(() => $sCode)"; |
|
| 213 | - } |
|
| 201 | +public function package(string $sClass, string $sType = 'html'): string |
|
| 202 | +{ |
|
| 203 | +$sCode = match($sType) { |
|
| 204 | +'html' => jaxon()->package($sClass)?->getHtml() ?? '', |
|
| 205 | +'ready' => jaxon()->package($sClass)?->getReadyScript() ?? '', |
|
| 206 | +default => '' |
|
| 207 | +}; |
|
| 208 | +$sCode = trim($sCode); |
|
| 209 | + |
|
| 210 | +return $sType !== 'ready' || $sCode === '' ? $sCode : |
|
| 211 | +// Call the ready code with the jaxon.dom.ready function. |
|
| 212 | +"jaxon.dom.ready(() => $sCode)"; |
|
| 213 | +} |
|
| 214 | 214 | } |
@@ -26,41 +26,41 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class ExportAnnotation extends AbstractAnnotation |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @var array |
| 31 | 31 | */ |
| 32 | - private $aMethods = []; |
|
| 32 | +private $aMethods = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public static function parseAnnotation($value) |
|
| 38 | - { |
|
| 39 | - $aParams = json_decode($value, true); |
|
| 40 | - return is_array($aParams) ? $aParams : []; |
|
| 41 | - } |
|
| 37 | +public static function parseAnnotation($value) |
|
| 38 | +{ |
|
| 39 | +$aParams = json_decode($value, true); |
|
| 40 | +return is_array($aParams) ? $aParams : []; |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * @inheritDoc |
| 45 | 45 | * @throws AnnotationException |
| 46 | 46 | */ |
| 47 | - public function initAnnotation(array $properties) |
|
| 48 | - { |
|
| 49 | - foreach(['base', 'only', 'except'] as $key) |
|
| 50 | - { |
|
| 51 | - if(isset($properties[$key]) && is_array($properties[$key]) && |
|
| 52 | - count($properties[$key]) > 0) |
|
| 53 | - { |
|
| 54 | - $this->aMethods[$key] = $properties[$key]; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 47 | +public function initAnnotation(array $properties) |
|
| 48 | +{ |
|
| 49 | +foreach(['base', 'only', 'except'] as $key) |
|
| 50 | +{ |
|
| 51 | +if(isset($properties[$key]) && is_array($properties[$key]) && |
|
| 52 | + count($properties[$key]) > 0) |
|
| 53 | +{ |
|
| 54 | + $this->aMethods[$key] = $properties[$key]; |
|
| 55 | +} |
|
| 56 | +} |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | */ |
| 62 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 63 | - { |
|
| 64 | - $xMetadata->export($sMethod)->setMethods($this->aMethods); |
|
| 65 | - } |
|
| 62 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 63 | +{ |
|
| 64 | +$xMetadata->export($sMethod)->setMethods($this->aMethods); |
|
| 65 | +} |
|
| 66 | 66 | } |
@@ -241,83 +241,83 @@ |
||
| 241 | 241 | $this->aComponentPublicMethods['node'], |
| 242 | 242 | $xReflectionClass->isSubclassOf(FuncComponent::class) => |
| 243 | 243 | $this->aComponentPublicMethods['func'], |
| 244 | - default => [[], []], |
|
| 245 | - }; |
|
| 244 | +default => [[], []], |
|
| 245 | +}; |
|
| 246 | 246 | |
| 247 | - return [$aMethods, ...$aBaseMethods]; |
|
| 248 | - } |
|
| 247 | +return [$aMethods, ...$aBaseMethods]; |
|
| 248 | +} |
|
| 249 | 249 | |
| 250 | - /** |
|
| 250 | +/** |
|
| 251 | 251 | * @param ReflectionClass $xReflectionClass |
| 252 | 252 | * @param array $aMethods |
| 253 | 253 | * @param array $aOptions |
| 254 | 254 | * |
| 255 | 255 | * @return Metadata|null |
| 256 | 256 | */ |
| 257 | - private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 258 | - array $aMethods, array $aOptions): Metadata|null |
|
| 259 | - { |
|
| 260 | - /** @var Config|null */ |
|
| 261 | - $xPackageConfig = $aOptions['config'] ?? null; |
|
| 262 | - if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 263 | - { |
|
| 264 | - return null; |
|
| 265 | - } |
|
| 266 | - $sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 267 | - if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 268 | - { |
|
| 269 | - return null; |
|
| 270 | - } |
|
| 257 | +private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 258 | +array $aMethods, array $aOptions): Metadata|null |
|
| 259 | +{ |
|
| 260 | +/** @var Config|null */ |
|
| 261 | +$xPackageConfig = $aOptions['config'] ?? null; |
|
| 262 | +if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 263 | +{ |
|
| 264 | +return null; |
|
| 265 | +} |
|
| 266 | +$sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 267 | +if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 268 | +{ |
|
| 269 | +return null; |
|
| 270 | +} |
|
| 271 | 271 | |
| 272 | - // Try to get the class metadata from the cache. |
|
| 273 | - $di = $this->cn(); |
|
| 274 | - $xMetadata = null; |
|
| 275 | - $xMetadataCache = null; |
|
| 276 | - $xConfig = $di->config(); |
|
| 277 | - if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 278 | - { |
|
| 279 | - if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 280 | - { |
|
| 281 | - $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 282 | - $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 283 | - } |
|
| 284 | - $xMetadataCache = $di->getMetadataCache(); |
|
| 285 | - $xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 286 | - if($xMetadata !== null) |
|
| 287 | - { |
|
| 288 | - return $xMetadata; |
|
| 289 | - } |
|
| 290 | - } |
|
| 272 | +// Try to get the class metadata from the cache. |
|
| 273 | +$di = $this->cn(); |
|
| 274 | +$xMetadata = null; |
|
| 275 | +$xMetadataCache = null; |
|
| 276 | +$xConfig = $di->config(); |
|
| 277 | +if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 278 | +{ |
|
| 279 | +if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 280 | +{ |
|
| 281 | + $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 282 | + $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 283 | +} |
|
| 284 | +$xMetadataCache = $di->getMetadataCache(); |
|
| 285 | +$xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 286 | +if($xMetadata !== null) |
|
| 287 | +{ |
|
| 288 | + return $xMetadata; |
|
| 289 | +} |
|
| 290 | +} |
|
| 291 | 291 | |
| 292 | - $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 293 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 294 | - ReflectionProperty::IS_PROTECTED)); |
|
| 292 | +$aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 293 | +$xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 294 | + ReflectionProperty::IS_PROTECTED)); |
|
| 295 | 295 | |
| 296 | - $xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 297 | - $xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 298 | - $xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 296 | +$xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 297 | +$xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 298 | +$xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 299 | 299 | |
| 300 | - // Try to save the metadata in the cache |
|
| 301 | - if($xMetadataCache !== null && $xMetadata !== null) |
|
| 302 | - { |
|
| 303 | - $xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 304 | - } |
|
| 300 | +// Try to save the metadata in the cache |
|
| 301 | +if($xMetadataCache !== null && $xMetadata !== null) |
|
| 302 | +{ |
|
| 303 | +$xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 304 | +} |
|
| 305 | 305 | |
| 306 | - return $xMetadata; |
|
| 307 | - } |
|
| 306 | +return $xMetadata; |
|
| 307 | +} |
|
| 308 | 308 | |
| 309 | - /** |
|
| 309 | +/** |
|
| 310 | 310 | * @param ReflectionClass $xReflectionClass |
| 311 | 311 | * @param array $aOptions |
| 312 | 312 | * |
| 313 | 313 | * @return ComponentOptions |
| 314 | 314 | */ |
| 315 | - public function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 316 | - array $aOptions): ComponentOptions |
|
| 317 | - { |
|
| 318 | - $aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 319 | - $xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 315 | +public function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 316 | +array $aOptions): ComponentOptions |
|
| 317 | +{ |
|
| 318 | +$aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 319 | +$xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 320 | 320 | |
| 321 | - return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 322 | - } |
|
| 321 | +return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 322 | +} |
|
| 323 | 323 | } |
@@ -39,73 +39,73 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | class ComponentContainer |
| 41 | 41 | { |
| 42 | - use Traits\DiAutoTrait; |
|
| 43 | - use Traits\ComponentTrait; |
|
| 42 | +use Traits\DiAutoTrait; |
|
| 43 | +use Traits\ComponentTrait; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * The Dependency Injection Container for registered classes |
| 47 | 47 | * |
| 48 | 48 | * @var PimpleContainer |
| 49 | 49 | */ |
| 50 | - private $xContainer; |
|
| 50 | +private $xContainer; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * This will be set only when getting the object targetted by the ajax request. |
| 54 | 54 | * |
| 55 | 55 | * @var Target |
| 56 | 56 | */ |
| 57 | - private $xTarget = null; |
|
| 57 | +private $xTarget = null; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * The class constructor |
| 61 | 61 | * |
| 62 | 62 | * @param Container $di |
| 63 | 63 | */ |
| 64 | - public function __construct(private Container $di) |
|
| 65 | - { |
|
| 66 | - $this->xContainer = new PimpleContainer(); |
|
| 67 | - $this->val(ComponentContainer::class, $this); |
|
| 68 | - |
|
| 69 | - // Register the call factory for registered functions |
|
| 70 | - $this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | - new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | - ->getOption('core.prefix.function', ''))); |
|
| 73 | - |
|
| 74 | - // Register the pagination component, but do not export to js. |
|
| 75 | - $this->saveComponent(Pagination::class, [ |
|
| 76 | - 'excluded' => true, |
|
| 77 | - 'separator' => '.', |
|
| 78 | - // The namespace has the same name as the Component class. |
|
| 79 | - 'namespace' => Component::class, |
|
| 80 | - ]); |
|
| 81 | - |
|
| 82 | - $this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 83 | - $this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 84 | - } |
|
| 64 | +public function __construct(private Container $di) |
|
| 65 | +{ |
|
| 66 | +$this->xContainer = new PimpleContainer(); |
|
| 67 | +$this->val(ComponentContainer::class, $this); |
|
| 68 | + |
|
| 69 | +// Register the call factory for registered functions |
|
| 70 | +$this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | +new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | + ->getOption('core.prefix.function', ''))); |
|
| 73 | + |
|
| 74 | +// Register the pagination component, but do not export to js. |
|
| 75 | +$this->saveComponent(Pagination::class, [ |
|
| 76 | +'excluded' => true, |
|
| 77 | +'separator' => '.', |
|
| 78 | +// The namespace has the same name as the Component class. |
|
| 79 | +'namespace' => Component::class, |
|
| 80 | +]); |
|
| 81 | + |
|
| 82 | +$this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 83 | +$this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * The container for parameters |
| 88 | 88 | * |
| 89 | 89 | * @return Container |
| 90 | 90 | */ |
| 91 | - protected function cn(): Container |
|
| 92 | - { |
|
| 93 | - return $this->di; |
|
| 94 | - } |
|
| 91 | +protected function cn(): Container |
|
| 92 | +{ |
|
| 93 | +return $this->di; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Check if a class is defined in the container |
| 98 | 98 | * |
| 99 | 99 | * @param class-string $sClass The full class name |
| 100 | 100 | * |
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | - public function has(string $sClass): bool |
|
| 104 | - { |
|
| 105 | - return $this->xContainer->offsetExists($sClass); |
|
| 106 | - } |
|
| 103 | +public function has(string $sClass): bool |
|
| 104 | +{ |
|
| 105 | +return $this->xContainer->offsetExists($sClass); |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Save a closure in the container |
| 110 | 110 | * |
| 111 | 111 | * @param class-string $sClass The full class name |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function set(string $sClass, Closure $xClosure) |
|
| 117 | - { |
|
| 118 | - $this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | - } |
|
| 116 | +public function set(string $sClass, Closure $xClosure) |
|
| 117 | +{ |
|
| 118 | +$this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Save a value in the container |
| 123 | 123 | * |
| 124 | 124 | * @param string|class-string $sKey The key |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function val(string $sKey, $xValue) |
|
| 130 | - { |
|
| 131 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | - } |
|
| 129 | +public function val(string $sKey, $xValue) |
|
| 130 | +{ |
|
| 131 | +$this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * Get a class instance |
| 136 | 136 | * |
| 137 | 137 | * @template T |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return T |
| 141 | 141 | */ |
| 142 | - public function get(string $sClass) |
|
| 143 | - { |
|
| 144 | - return $this->xContainer->offsetGet($sClass); |
|
| 145 | - } |
|
| 142 | +public function get(string $sClass) |
|
| 143 | +{ |
|
| 144 | +return $this->xContainer->offsetGet($sClass); |
|
| 145 | +} |
|
| 146 | 146 | |
| 147 | - /** |
|
| 147 | +/** |
|
| 148 | 148 | * Get a component when one of its method needs to be called |
| 149 | 149 | * |
| 150 | 150 | * @template T |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return T|null |
| 155 | 155 | */ |
| 156 | - public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | - { |
|
| 158 | - // Set the target only when getting the object targetted by the ajax request. |
|
| 159 | - $this->xTarget = $xTarget; |
|
| 160 | - $xComponent = $this->get($sClassName); |
|
| 161 | - $this->xTarget = null; |
|
| 156 | +public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | +{ |
|
| 158 | +// Set the target only when getting the object targetted by the ajax request. |
|
| 159 | +$this->xTarget = $xTarget; |
|
| 160 | +$xComponent = $this->get($sClassName); |
|
| 161 | +$this->xTarget = null; |
|
| 162 | 162 | |
| 163 | - return $xComponent; |
|
| 164 | - } |
|
| 163 | +return $xComponent; |
|
| 164 | +} |
|
| 165 | 165 | |
| 166 | - /** |
|
| 166 | +/** |
|
| 167 | 167 | * Register a component and its options |
| 168 | 168 | * |
| 169 | 169 | * @param class-string $sClassName The class name |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | - { |
|
| 176 | - try |
|
| 177 | - { |
|
| 178 | - // Make sure the registered class exists |
|
| 179 | - if(isset($aOptions['include'])) |
|
| 180 | - { |
|
| 181 | - require_once $aOptions['include']; |
|
| 182 | - } |
|
| 183 | - $xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | - // Check if the class is registrable |
|
| 185 | - if(!$xReflectionClass->isInstantiable()) |
|
| 186 | - { |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $this->_saveClassOptions($sClassName, $aOptions); |
|
| 191 | - |
|
| 192 | - $sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | - $this->val($sClassKey, $xReflectionClass); |
|
| 194 | - // Register the user class, but only if the user didn't already. |
|
| 195 | - if(!$this->has($sClassName)) |
|
| 196 | - { |
|
| 197 | - $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - catch(ReflectionException $e) |
|
| 201 | - { |
|
| 202 | - throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | - ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | - } |
|
| 205 | - } |
|
| 174 | +public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | +{ |
|
| 176 | +try |
|
| 177 | +{ |
|
| 178 | +// Make sure the registered class exists |
|
| 179 | +if(isset($aOptions['include'])) |
|
| 180 | +{ |
|
| 181 | + require_once $aOptions['include']; |
|
| 182 | +} |
|
| 183 | +$xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | +// Check if the class is registrable |
|
| 185 | +if(!$xReflectionClass->isInstantiable()) |
|
| 186 | +{ |
|
| 187 | + return; |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +$this->_saveClassOptions($sClassName, $aOptions); |
|
| 206 | 191 | |
| 207 | - /** |
|
| 192 | +$sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | +$this->val($sClassKey, $xReflectionClass); |
|
| 194 | +// Register the user class, but only if the user didn't already. |
|
| 195 | +if(!$this->has($sClassName)) |
|
| 196 | +{ |
|
| 197 | + $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | +} |
|
| 199 | +} |
|
| 200 | +catch(ReflectionException $e) |
|
| 201 | +{ |
|
| 202 | +throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | + ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | +} |
|
| 205 | +} |
|
| 206 | + |
|
| 207 | +/** |
|
| 208 | 208 | * Register a component |
| 209 | 209 | * |
| 210 | 210 | * @param string $sComponentId The component name |
@@ -212,74 +212,74 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | * @throws SetupException |
| 214 | 214 | */ |
| 215 | - private function _registerComponent(string $sComponentId): string |
|
| 216 | - { |
|
| 217 | - // Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | - $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | - |
|
| 220 | - $sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | - // Prevent duplication. It's important not to use the class name here. |
|
| 222 | - if($this->has($sComponentObject)) |
|
| 223 | - { |
|
| 224 | - return $sClassName; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Register the helper class |
|
| 228 | - $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | - $xFactory = $this->di->getCallFactory(); |
|
| 230 | - return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | - $xFactory, $this->di->getViewRenderer(), |
|
| 232 | - $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | - $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | - }); |
|
| 235 | - |
|
| 236 | - $this->discoverComponent($sClassName); |
|
| 237 | - |
|
| 238 | - // Register the callable object |
|
| 239 | - $this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | - $aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | - $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | - $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | - return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | - }); |
|
| 245 | - |
|
| 246 | - // Initialize the user class instance |
|
| 247 | - $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | - if($xClassInstance instanceof AbstractComponent) |
|
| 249 | - { |
|
| 250 | - $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | - $xHelper->xTarget = $this->xTarget; |
|
| 252 | - |
|
| 253 | - // Call the protected "initComponent()" method of the Component class. |
|
| 254 | - $cSetter = function($di, $xHelper) { |
|
| 255 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | - }; |
|
| 257 | - $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | - call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Run the callbacks for class initialisation |
|
| 262 | - $this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | - |
|
| 264 | - // Set attributes from the DI container. |
|
| 265 | - // The class level DI options are set on any component. |
|
| 266 | - // The method level DI options are set only on the targetted component. |
|
| 267 | - /** @var CallableObject */ |
|
| 268 | - $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | - $xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | - if($this->xTarget !== null) |
|
| 271 | - { |
|
| 272 | - $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | - $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $xClassInstance; |
|
| 277 | - }); |
|
| 278 | - |
|
| 279 | - return $sClassName; |
|
| 280 | - } |
|
| 215 | +private function _registerComponent(string $sComponentId): string |
|
| 216 | +{ |
|
| 217 | +// Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | +$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | + |
|
| 220 | +$sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | +// Prevent duplication. It's important not to use the class name here. |
|
| 222 | +if($this->has($sComponentObject)) |
|
| 223 | +{ |
|
| 224 | +return $sClassName; |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +// Register the helper class |
|
| 228 | +$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | +$xFactory = $this->di->getCallFactory(); |
|
| 230 | +return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | + $xFactory, $this->di->getViewRenderer(), |
|
| 232 | + $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | + $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | +}); |
|
| 235 | + |
|
| 236 | +$this->discoverComponent($sClassName); |
|
| 237 | + |
|
| 238 | +// Register the callable object |
|
| 239 | +$this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | +$aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | +$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | +$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | +return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | +}); |
|
| 245 | + |
|
| 246 | +// Initialize the user class instance |
|
| 247 | +$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | +if($xClassInstance instanceof AbstractComponent) |
|
| 249 | +{ |
|
| 250 | + $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | + $xHelper->xTarget = $this->xTarget; |
|
| 252 | + |
|
| 253 | + // Call the protected "initComponent()" method of the Component class. |
|
| 254 | + $cSetter = function($di, $xHelper) { |
|
| 255 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | + }; |
|
| 257 | + $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | + call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +// Run the callbacks for class initialisation |
|
| 262 | +$this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | + |
|
| 264 | +// Set attributes from the DI container. |
|
| 265 | +// The class level DI options are set on any component. |
|
| 266 | +// The method level DI options are set only on the targetted component. |
|
| 267 | +/** @var CallableObject */ |
|
| 268 | +$xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | +$xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | +if($this->xTarget !== null) |
|
| 271 | +{ |
|
| 272 | + $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | + $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +return $xClassInstance; |
|
| 277 | +}); |
|
| 281 | 278 | |
| 282 | - /** |
|
| 279 | +return $sClassName; |
|
| 280 | +} |
|
| 281 | + |
|
| 282 | +/** |
|
| 283 | 283 | * Get the callable object for a given class |
| 284 | 284 | * The callable object is registered if it is not already in the DI. |
| 285 | 285 | * |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | * @return CallableObject|null |
| 289 | 289 | * @throws SetupException |
| 290 | 290 | */ |
| 291 | - public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | - { |
|
| 293 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | - return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | - } |
|
| 291 | +public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | +{ |
|
| 293 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | +return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | +} |
|
| 296 | 296 | |
| 297 | - /** |
|
| 297 | +/** |
|
| 298 | 298 | * Get an instance of a component by name |
| 299 | 299 | * |
| 300 | 300 | * @template T |
@@ -303,53 +303,53 @@ discard block |
||
| 303 | 303 | * @return T|null |
| 304 | 304 | * @throws SetupException |
| 305 | 305 | */ |
| 306 | - public function makeComponent(string $sClassName): mixed |
|
| 307 | - { |
|
| 308 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | - return $this->get($sClassName); |
|
| 311 | - } |
|
| 306 | +public function makeComponent(string $sClassName): mixed |
|
| 307 | +{ |
|
| 308 | +$sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | +return $this->get($sClassName); |
|
| 311 | +} |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | +/** |
|
| 314 | 314 | * Get a factory for a call to a registered function. |
| 315 | 315 | * |
| 316 | 316 | * @return JxnCall |
| 317 | 317 | */ |
| 318 | - public function getFunctionRequestFactory(): JxnCall |
|
| 319 | - { |
|
| 320 | - return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | - } |
|
| 318 | +public function getFunctionRequestFactory(): JxnCall |
|
| 319 | +{ |
|
| 320 | +return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | +} |
|
| 322 | 322 | |
| 323 | - /** |
|
| 323 | +/** |
|
| 324 | 324 | * Get a factory for a call to a registered component. |
| 325 | 325 | * |
| 326 | 326 | * @param class-string $sClassName |
| 327 | 327 | * |
| 328 | 328 | * @return JxnCall|null |
| 329 | 329 | */ |
| 330 | - public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 330 | +public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 331 | +{ |
|
| 332 | +$sClassName = trim($sClassName, " \t"); |
|
| 333 | +if($sClassName === '') |
|
| 334 | +{ |
|
| 335 | +return null; |
|
| 336 | +} |
|
| 337 | + |
|
| 338 | +$sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | +if(!$this->has($sFactoryKey)) |
|
| 340 | +{ |
|
| 341 | +$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | + $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | + if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 331 | 344 | { |
| 332 | - $sClassName = trim($sClassName, " \t"); |
|
| 333 | - if($sClassName === '') |
|
| 334 | - { |
|
| 335 | - return null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | - if(!$this->has($sFactoryKey)) |
|
| 340 | - { |
|
| 341 | - $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 344 | - { |
|
| 345 | - return null; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | - $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | - return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | - }); |
|
| 352 | - } |
|
| 353 | - return $this->get($sFactoryKey); |
|
| 345 | + return null; |
|
| 354 | 346 | } |
| 347 | + |
|
| 348 | + $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | + $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | + return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | +}); |
|
| 352 | +} |
|
| 353 | +return $this->get($sFactoryKey); |
|
| 354 | +} |
|
| 355 | 355 | } |