@@ -9,35 +9,35 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class Store implements JsonSerializable, Stringable |
| 11 | 11 | { |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * The view renderer |
| 14 | 14 | * |
| 15 | 15 | * @var ViewInterface|null |
| 16 | 16 | */ |
| 17 | - protected $xRenderer = null; |
|
| 17 | +protected $xRenderer = null; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * The view namespace |
| 21 | 21 | * |
| 22 | 22 | * @var string |
| 23 | 23 | */ |
| 24 | - protected $sNamespace; |
|
| 24 | +protected $sNamespace; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The view name |
| 28 | 28 | * |
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - protected $sViewName; |
|
| 31 | +protected $sViewName; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The view data |
| 35 | 35 | * |
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - protected $aViewData = []; |
|
| 38 | +protected $aViewData = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * Make a piece of data available for the rendered view |
| 42 | 42 | * |
| 43 | 43 | * @param string $sName The data name |
@@ -45,26 +45,26 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return Store |
| 47 | 47 | */ |
| 48 | - public function with(string $sName, $xValue): Store |
|
| 49 | - { |
|
| 50 | - $this->aViewData[$sName] = $xValue; |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 48 | +public function with(string $sName, $xValue): Store |
|
| 49 | +{ |
|
| 50 | +$this->aViewData[$sName] = $xValue; |
|
| 51 | +return $this; |
|
| 52 | +} |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * Set the data to be rendered |
| 56 | 56 | * |
| 57 | 57 | * @param array $aViewData The view data |
| 58 | 58 | * |
| 59 | 59 | * @return Store |
| 60 | 60 | */ |
| 61 | - public function setData(array $aViewData): Store |
|
| 62 | - { |
|
| 63 | - $this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 64 | - return $this; |
|
| 65 | - } |
|
| 61 | +public function setData(array $aViewData): Store |
|
| 62 | +{ |
|
| 63 | +$this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 64 | +return $this; |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * Set the view to be rendered, with optional data |
| 69 | 69 | * |
| 70 | 70 | * @param ViewInterface $xRenderer The view renderer |
@@ -74,65 +74,65 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return Store |
| 76 | 76 | */ |
| 77 | - public function setView(ViewInterface $xRenderer, |
|
| 78 | - string $sNamespace, string $sViewName, array $aViewData = []): Store |
|
| 79 | - { |
|
| 80 | - $this->xRenderer = $xRenderer; |
|
| 81 | - $this->sNamespace = trim($sNamespace); |
|
| 82 | - $this->sViewName = trim($sViewName); |
|
| 83 | - $this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 84 | - return $this; |
|
| 85 | - } |
|
| 77 | +public function setView(ViewInterface $xRenderer, |
|
| 78 | +string $sNamespace, string $sViewName, array $aViewData = []): Store |
|
| 79 | +{ |
|
| 80 | +$this->xRenderer = $xRenderer; |
|
| 81 | +$this->sNamespace = trim($sNamespace); |
|
| 82 | +$this->sViewName = trim($sViewName); |
|
| 83 | +$this->aViewData = array_merge($this->aViewData, $aViewData); |
|
| 84 | +return $this; |
|
| 85 | +} |
|
| 86 | 86 | |
| 87 | - /** |
|
| 87 | +/** |
|
| 88 | 88 | * Get the view namespace |
| 89 | 89 | * |
| 90 | 90 | * @return string The view namespace |
| 91 | 91 | */ |
| 92 | - public function getNamespace(): string |
|
| 93 | - { |
|
| 94 | - return $this->sNamespace; |
|
| 95 | - } |
|
| 92 | +public function getNamespace(): string |
|
| 93 | +{ |
|
| 94 | +return $this->sNamespace; |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * Get the view name |
| 99 | 99 | * |
| 100 | 100 | * @return string The view name |
| 101 | 101 | */ |
| 102 | - public function getViewName(): string |
|
| 103 | - { |
|
| 104 | - return $this->sViewName; |
|
| 105 | - } |
|
| 102 | +public function getViewName(): string |
|
| 103 | +{ |
|
| 104 | +return $this->sViewName; |
|
| 105 | +} |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * Get the view data |
| 109 | 109 | * |
| 110 | 110 | * @return array The view data |
| 111 | 111 | */ |
| 112 | - public function getViewData(): array |
|
| 113 | - { |
|
| 114 | - return $this->aViewData; |
|
| 115 | - } |
|
| 112 | +public function getViewData(): array |
|
| 113 | +{ |
|
| 114 | +return $this->aViewData; |
|
| 115 | +} |
|
| 116 | 116 | |
| 117 | - /** |
|
| 117 | +/** |
|
| 118 | 118 | * Render a view using third party view system |
| 119 | 119 | * |
| 120 | 120 | * @return string The string representation of the view |
| 121 | 121 | */ |
| 122 | - public function __toString(): string |
|
| 123 | - { |
|
| 124 | - return !$this->xRenderer ? '' : $this->xRenderer->render($this); |
|
| 125 | - } |
|
| 122 | +public function __toString(): string |
|
| 123 | +{ |
|
| 124 | +return !$this->xRenderer ? '' : $this->xRenderer->render($this); |
|
| 125 | +} |
|
| 126 | 126 | |
| 127 | - /** |
|
| 127 | +/** |
|
| 128 | 128 | * Convert this object to string for json. |
| 129 | 129 | * |
| 130 | 130 | * This is a method of the JsonSerializable interface. |
| 131 | 131 | * |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function jsonSerialize(): string |
|
| 135 | - { |
|
| 136 | - return $this->__toString(); |
|
| 137 | - } |
|
| 134 | +public function jsonSerialize(): string |
|
| 135 | +{ |
|
| 136 | +return $this->__toString(); |
|
| 137 | +} |
|
| 138 | 138 | } |
@@ -18,32 +18,32 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class AbstractData |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Generate the PHP code to populate a Metadata object |
| 23 | 23 | * |
| 24 | 24 | * @param string $sVarName |
| 25 | 25 | * |
| 26 | 26 | * @return array |
| 27 | 27 | */ |
| 28 | - abstract public function encode(string $sVarName): array; |
|
| 28 | +abstract public function encode(string $sVarName): array; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - abstract public function getName(): string; |
|
| 33 | +abstract public function getName(): string; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * @return mixed |
| 37 | 37 | */ |
| 38 | - abstract public function getValue(): mixed; |
|
| 38 | +abstract public function getValue(): mixed; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @param string $sMethod |
| 42 | 42 | * |
| 43 | 43 | * @return bool |
| 44 | 44 | */ |
| 45 | - protected function validateMethod(string $sMethod): bool |
|
| 46 | - { |
|
| 47 | - return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 48 | - } |
|
| 45 | +protected function validateMethod(string $sMethod): bool |
|
| 46 | +{ |
|
| 47 | +return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 48 | +} |
|
| 49 | 49 | } |
@@ -19,46 +19,46 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | abstract class AbstractPackage extends AbstractCodeGenerator |
| 21 | 21 | { |
| 22 | - /** |
|
| 22 | +/** |
|
| 23 | 23 | * The configuration options of the package |
| 24 | 24 | * |
| 25 | 25 | * @var Config |
| 26 | 26 | */ |
| 27 | - protected $xPkgConfig; |
|
| 27 | +protected $xPkgConfig; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The view renderer |
| 31 | 31 | * |
| 32 | 32 | * @var ViewRenderer |
| 33 | 33 | */ |
| 34 | - protected $xRenderer; |
|
| 34 | +protected $xRenderer; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the path to the config file, or the config options in an array. |
| 38 | 38 | * |
| 39 | 39 | * @return string|array |
| 40 | 40 | */ |
| 41 | - abstract public static function config(): string|array; |
|
| 41 | +abstract public static function config(): string|array; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * Get the package config object |
| 45 | 45 | * |
| 46 | 46 | * @return Config |
| 47 | 47 | */ |
| 48 | - final public function getConfig(): Config |
|
| 49 | - { |
|
| 50 | - return $this->xPkgConfig; |
|
| 51 | - } |
|
| 48 | +final public function getConfig(): Config |
|
| 49 | +{ |
|
| 50 | +return $this->xPkgConfig; |
|
| 51 | +} |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * This method is automatically called after the package instance is created and configured. |
| 55 | 55 | * |
| 56 | 56 | * @return void |
| 57 | 57 | */ |
| 58 | - protected function init(): void |
|
| 59 | - {} |
|
| 58 | +protected function init(): void |
|
| 59 | +{} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * Get the value of a given package option |
| 63 | 63 | * |
| 64 | 64 | * @param string $sOption The option name |
@@ -66,59 +66,59 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return mixed |
| 68 | 68 | */ |
| 69 | - final public function getOption(string $sOption, $xDefault = null): mixed |
|
| 70 | - { |
|
| 71 | - return $this->xPkgConfig->getOption($sOption, $xDefault); |
|
| 72 | - } |
|
| 69 | +final public function getOption(string $sOption, $xDefault = null): mixed |
|
| 70 | +{ |
|
| 71 | +return $this->xPkgConfig->getOption($sOption, $xDefault); |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * Get the view renderer |
| 76 | 76 | * |
| 77 | 77 | * @return ViewRenderer |
| 78 | 78 | */ |
| 79 | - final public function view(): ViewRenderer |
|
| 80 | - { |
|
| 81 | - return $this->xRenderer; |
|
| 82 | - } |
|
| 79 | +final public function view(): ViewRenderer |
|
| 80 | +{ |
|
| 81 | +return $this->xRenderer; |
|
| 82 | +} |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * @inheritDoc |
| 86 | 86 | */ |
| 87 | - final public function getHash(): string |
|
| 88 | - { |
|
| 89 | - // Packages do not generate hash on their own. So we make this method final. |
|
| 90 | - return ''; |
|
| 91 | - } |
|
| 87 | +final public function getHash(): string |
|
| 88 | +{ |
|
| 89 | +// Packages do not generate hash on their own. So we make this method final. |
|
| 90 | +return ''; |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Get the HTML code of the package home page |
| 95 | 95 | * |
| 96 | 96 | * @return string|Stringable |
| 97 | 97 | */ |
| 98 | - public function getHtml(): string|Stringable |
|
| 99 | - { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 98 | +public function getHtml(): string|Stringable |
|
| 99 | +{ |
|
| 100 | +return ''; |
|
| 101 | +} |
|
| 102 | 102 | |
| 103 | - /** |
|
| 103 | +/** |
|
| 104 | 104 | * Get the HTML code of the package home page |
| 105 | 105 | * |
| 106 | 106 | * This method is an alias for getHtml(). |
| 107 | 107 | * |
| 108 | 108 | * @return string|Stringable |
| 109 | 109 | */ |
| 110 | - public function html(): string|Stringable |
|
| 111 | - { |
|
| 112 | - return $this->getHtml(); |
|
| 113 | - } |
|
| 110 | +public function html(): string|Stringable |
|
| 111 | +{ |
|
| 112 | +return $this->getHtml(); |
|
| 113 | +} |
|
| 114 | 114 | |
| 115 | - /** |
|
| 115 | +/** |
|
| 116 | 116 | * Get the Js code of the ready() callback |
| 117 | 117 | * |
| 118 | 118 | * @return string|Stringable |
| 119 | 119 | */ |
| 120 | - public function getReadyScript(): string|Stringable |
|
| 121 | - { |
|
| 122 | - return ''; |
|
| 123 | - } |
|
| 120 | +public function getReadyScript(): string|Stringable |
|
| 121 | +{ |
|
| 122 | +return ''; |
|
| 123 | +} |
|
| 124 | 124 | } |
@@ -20,99 +20,99 @@ |
||
| 20 | 20 | |
| 21 | 21 | trait RequestTrait |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * Register the values into the container |
| 25 | 25 | * |
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | - private function registerRequests(): void |
|
| 29 | - { |
|
| 30 | - // The parameter reader |
|
| 31 | - $this->set(ParameterReader::class, function($di) { |
|
| 32 | - return new ParameterReader($di->g(Container::class), $di->g(Translator::class), |
|
| 33 | - $di->g(ConfigManager::class), $di->g(UriDetector::class)); |
|
| 34 | - }); |
|
| 35 | - // Callback Manager |
|
| 36 | - $this->set(CallbackManager::class, function($di) { |
|
| 37 | - return new CallbackManager($di->g(ResponseManager::class)); |
|
| 38 | - }); |
|
| 39 | - // By default, register a null upload handler |
|
| 40 | - $this->set(UploadHandlerInterface::class, function() { |
|
| 41 | - return null; |
|
| 42 | - }); |
|
| 43 | - // Request Handler |
|
| 44 | - $this->set(RequestHandler::class, function($di) { |
|
| 45 | - return new RequestHandler($di->g(Container::class), $di->g(PluginManager::class), |
|
| 46 | - $di->g(ResponseManager::class), $di->g(CallbackManager::class), |
|
| 47 | - $di->g(DatabagPlugin::class)); |
|
| 48 | - }); |
|
| 49 | - // Requests and calls Factory |
|
| 50 | - $this->set(CallFactory::class, function($di) { |
|
| 51 | - return new CallFactory($di->g(ComponentContainer::class), $di->g(DialogCommand::class)); |
|
| 52 | - }); |
|
| 53 | - // Factory for function parameters |
|
| 54 | - $this->set(ParameterFactory::class, function() { |
|
| 55 | - return new ParameterFactory(); |
|
| 56 | - }); |
|
| 57 | - } |
|
| 28 | +private function registerRequests(): void |
|
| 29 | +{ |
|
| 30 | +// The parameter reader |
|
| 31 | +$this->set(ParameterReader::class, function($di) { |
|
| 32 | +return new ParameterReader($di->g(Container::class), $di->g(Translator::class), |
|
| 33 | + $di->g(ConfigManager::class), $di->g(UriDetector::class)); |
|
| 34 | +}); |
|
| 35 | +// Callback Manager |
|
| 36 | +$this->set(CallbackManager::class, function($di) { |
|
| 37 | +return new CallbackManager($di->g(ResponseManager::class)); |
|
| 38 | +}); |
|
| 39 | +// By default, register a null upload handler |
|
| 40 | +$this->set(UploadHandlerInterface::class, function() { |
|
| 41 | +return null; |
|
| 42 | +}); |
|
| 43 | +// Request Handler |
|
| 44 | +$this->set(RequestHandler::class, function($di) { |
|
| 45 | +return new RequestHandler($di->g(Container::class), $di->g(PluginManager::class), |
|
| 46 | + $di->g(ResponseManager::class), $di->g(CallbackManager::class), |
|
| 47 | + $di->g(DatabagPlugin::class)); |
|
| 48 | +}); |
|
| 49 | +// Requests and calls Factory |
|
| 50 | +$this->set(CallFactory::class, function($di) { |
|
| 51 | +return new CallFactory($di->g(ComponentContainer::class), $di->g(DialogCommand::class)); |
|
| 52 | +}); |
|
| 53 | +// Factory for function parameters |
|
| 54 | +$this->set(ParameterFactory::class, function() { |
|
| 55 | +return new ParameterFactory(); |
|
| 56 | +}); |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * Get the callback manager |
| 61 | 61 | * |
| 62 | 62 | * @return CallbackManager |
| 63 | 63 | */ |
| 64 | - public function callback(): CallbackManager |
|
| 65 | - { |
|
| 66 | - return $this->g(CallbackManager::class); |
|
| 67 | - } |
|
| 64 | +public function callback(): CallbackManager |
|
| 65 | +{ |
|
| 66 | +return $this->g(CallbackManager::class); |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * Get the js call factory |
| 71 | 71 | * |
| 72 | 72 | * @return CallFactory |
| 73 | 73 | */ |
| 74 | - public function getCallFactory(): CallFactory |
|
| 75 | - { |
|
| 76 | - return $this->g(CallFactory::class); |
|
| 77 | - } |
|
| 74 | +public function getCallFactory(): CallFactory |
|
| 75 | +{ |
|
| 76 | +return $this->g(CallFactory::class); |
|
| 77 | +} |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * Get the js call parameter factory |
| 81 | 81 | * |
| 82 | 82 | * @return ParameterFactory |
| 83 | 83 | */ |
| 84 | - public function getParameterFactory(): ParameterFactory |
|
| 85 | - { |
|
| 86 | - return $this->g(ParameterFactory::class); |
|
| 87 | - } |
|
| 84 | +public function getParameterFactory(): ParameterFactory |
|
| 85 | +{ |
|
| 86 | +return $this->g(ParameterFactory::class); |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * Get the request handler |
| 91 | 91 | * |
| 92 | 92 | * @return RequestHandler |
| 93 | 93 | */ |
| 94 | - public function getRequestHandler(): RequestHandler |
|
| 95 | - { |
|
| 96 | - return $this->g(RequestHandler::class); |
|
| 97 | - } |
|
| 94 | +public function getRequestHandler(): RequestHandler |
|
| 95 | +{ |
|
| 96 | +return $this->g(RequestHandler::class); |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * Get the upload handler |
| 101 | 101 | * |
| 102 | 102 | * @return UploadHandlerInterface|null |
| 103 | 103 | */ |
| 104 | - public function getUploadHandler(): ?UploadHandlerInterface |
|
| 105 | - { |
|
| 106 | - return $this->g(UploadHandlerInterface::class); |
|
| 107 | - } |
|
| 104 | +public function getUploadHandler(): ?UploadHandlerInterface |
|
| 105 | +{ |
|
| 106 | +return $this->g(UploadHandlerInterface::class); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Get the parameter reader |
| 111 | 111 | * |
| 112 | 112 | * @return ParameterReader |
| 113 | 113 | */ |
| 114 | - public function getParameterReader(): ParameterReader |
|
| 115 | - { |
|
| 116 | - return $this->g(ParameterReader::class); |
|
| 117 | - } |
|
| 114 | +public function getParameterReader(): ParameterReader |
|
| 115 | +{ |
|
| 116 | +return $this->g(ParameterReader::class); |
|
| 117 | +} |
|
| 118 | 118 | } |
@@ -26,44 +26,44 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | trait DiAutoTrait |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * The container for parameters |
| 31 | 31 | * |
| 32 | 32 | * @return Container |
| 33 | 33 | */ |
| 34 | - abstract protected function cn(): Container; |
|
| 34 | +abstract protected function cn(): Container; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * @param ReflectionClass $xClass |
| 38 | 38 | * @param ReflectionParameter $xParameter |
| 39 | 39 | * |
| 40 | 40 | * @return mixed |
| 41 | 41 | * @throws SetupException |
| 42 | 42 | */ |
| 43 | - private function getParameter(ReflectionClass $xClass, ReflectionParameter $xParameter) |
|
| 44 | - { |
|
| 45 | - $xType = $xParameter->getType(); |
|
| 46 | - $sParameterName = '$' . $xParameter->getName(); |
|
| 47 | - // Check the parameter class first. |
|
| 48 | - if($xType instanceof ReflectionNamedType) |
|
| 49 | - { |
|
| 50 | - $sParameterType = $xType->getName(); |
|
| 51 | - // The class + the name |
|
| 52 | - if($this->cn()->has("$sParameterType $sParameterName")) |
|
| 53 | - { |
|
| 54 | - return $this->cn()->get("$sParameterType $sParameterName"); |
|
| 55 | - } |
|
| 56 | - // The class only |
|
| 57 | - if($this->cn()->has($sParameterType)) |
|
| 58 | - { |
|
| 59 | - return $this->cn()->get($sParameterType); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - // Check the name only |
|
| 63 | - return $this->cn()->get($sParameterName); |
|
| 64 | - } |
|
| 43 | +private function getParameter(ReflectionClass $xClass, ReflectionParameter $xParameter) |
|
| 44 | +{ |
|
| 45 | +$xType = $xParameter->getType(); |
|
| 46 | +$sParameterName = '$' . $xParameter->getName(); |
|
| 47 | +// Check the parameter class first. |
|
| 48 | +if($xType instanceof ReflectionNamedType) |
|
| 49 | +{ |
|
| 50 | +$sParameterType = $xType->getName(); |
|
| 51 | +// The class + the name |
|
| 52 | +if($this->cn()->has("$sParameterType $sParameterName")) |
|
| 53 | +{ |
|
| 54 | + return $this->cn()->get("$sParameterType $sParameterName"); |
|
| 55 | +} |
|
| 56 | +// The class only |
|
| 57 | +if($this->cn()->has($sParameterType)) |
|
| 58 | +{ |
|
| 59 | + return $this->cn()->get($sParameterType); |
|
| 60 | +} |
|
| 61 | +} |
|
| 62 | +// Check the name only |
|
| 63 | +return $this->cn()->get($sParameterName); |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * Create an instance of a class, getting the constructor parameters from the DI container |
| 68 | 68 | * |
| 69 | 69 | * @param class-string|ReflectionClass $xClass The class name or the reflection class |
@@ -72,33 +72,33 @@ discard block |
||
| 72 | 72 | * @throws ReflectionException |
| 73 | 73 | * @throws SetupException |
| 74 | 74 | */ |
| 75 | - public function make(string|ReflectionClass $xClass): mixed |
|
| 76 | - { |
|
| 77 | - if(is_string($xClass)) |
|
| 78 | - { |
|
| 79 | - // Create the reflection class instance |
|
| 80 | - $xClass = new ReflectionClass($xClass); |
|
| 81 | - } |
|
| 82 | - // Use the Reflection class to get the parameters of the constructor |
|
| 83 | - if(($constructor = $xClass->getConstructor()) === null) |
|
| 84 | - { |
|
| 85 | - return $xClass->newInstance(); |
|
| 86 | - } |
|
| 75 | +public function make(string|ReflectionClass $xClass): mixed |
|
| 76 | +{ |
|
| 77 | +if(is_string($xClass)) |
|
| 78 | +{ |
|
| 79 | +// Create the reflection class instance |
|
| 80 | +$xClass = new ReflectionClass($xClass); |
|
| 81 | +} |
|
| 82 | +// Use the Reflection class to get the parameters of the constructor |
|
| 83 | +if(($constructor = $xClass->getConstructor()) === null) |
|
| 84 | +{ |
|
| 85 | +return $xClass->newInstance(); |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - $aParameters = array_map(fn($xParameter) => |
|
| 89 | - $this->getParameter($xClass, $xParameter), $constructor->getParameters()); |
|
| 90 | - return $xClass->newInstanceArgs($aParameters); |
|
| 91 | - } |
|
| 88 | +$aParameters = array_map(fn($xParameter) => |
|
| 89 | +$this->getParameter($xClass, $xParameter), $constructor->getParameters()); |
|
| 90 | +return $xClass->newInstanceArgs($aParameters); |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Create an instance of a class by automatically fetching the dependencies in the constructor. |
| 95 | 95 | * |
| 96 | 96 | * @param class-string $sClass The class name |
| 97 | 97 | * |
| 98 | 98 | * @return void |
| 99 | 99 | */ |
| 100 | - public function auto(string $sClass): void |
|
| 101 | - { |
|
| 102 | - $this->set($sClass, fn() => $this->make($sClass)); |
|
| 103 | - } |
|
| 100 | +public function auto(string $sClass): void |
|
| 101 | +{ |
|
| 102 | +$this->set($sClass, fn() => $this->make($sClass)); |
|
| 103 | +} |
|
| 104 | 104 | } |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | $xType = $xParameter->getType(); |
| 46 | 46 | $sParameterName = '$' . $xParameter->getName(); |
| 47 | 47 | // Check the parameter class first. |
| 48 | - if($xType instanceof ReflectionNamedType) |
|
| 48 | + if ($xType instanceof ReflectionNamedType) |
|
| 49 | 49 | { |
| 50 | 50 | $sParameterType = $xType->getName(); |
| 51 | 51 | // The class + the name |
| 52 | - if($this->cn()->has("$sParameterType $sParameterName")) |
|
| 52 | + if ($this->cn()->has("$sParameterType $sParameterName")) |
|
| 53 | 53 | { |
| 54 | 54 | return $this->cn()->get("$sParameterType $sParameterName"); |
| 55 | 55 | } |
| 56 | 56 | // The class only |
| 57 | - if($this->cn()->has($sParameterType)) |
|
| 57 | + if ($this->cn()->has($sParameterType)) |
|
| 58 | 58 | { |
| 59 | 59 | return $this->cn()->get($sParameterType); |
| 60 | 60 | } |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function make(string|ReflectionClass $xClass): mixed |
| 76 | 76 | { |
| 77 | - if(is_string($xClass)) |
|
| 77 | + if (is_string($xClass)) |
|
| 78 | 78 | { |
| 79 | 79 | // Create the reflection class instance |
| 80 | 80 | $xClass = new ReflectionClass($xClass); |
| 81 | 81 | } |
| 82 | 82 | // Use the Reflection class to get the parameters of the constructor |
| 83 | - if(($constructor = $xClass->getConstructor()) === null) |
|
| 83 | + if (($constructor = $xClass->getConstructor()) === null) |
|
| 84 | 84 | { |
| 85 | 85 | return $xClass->newInstance(); |
| 86 | 86 | } |
@@ -31,73 +31,73 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | trait ServicesTrait |
| 33 | 33 | { |
| 34 | - use DiTrait; |
|
| 34 | +use DiTrait; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * @return Translator |
| 38 | 38 | */ |
| 39 | - public function translator(): Translator |
|
| 40 | - { |
|
| 41 | - return $this->di()->g(Translator::class); |
|
| 42 | - } |
|
| 39 | +public function translator(): Translator |
|
| 40 | +{ |
|
| 41 | +return $this->di()->g(Translator::class); |
|
| 42 | +} |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * @return LoggerInterface |
| 46 | 46 | */ |
| 47 | - public function logger(): LoggerInterface |
|
| 48 | - { |
|
| 49 | - return $this->di()->getLogger(); |
|
| 50 | - } |
|
| 47 | +public function logger(): LoggerInterface |
|
| 48 | +{ |
|
| 49 | +return $this->di()->getLogger(); |
|
| 50 | +} |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * @return Bootstrap |
| 54 | 54 | */ |
| 55 | - protected function getBootstrap(): Bootstrap |
|
| 56 | - { |
|
| 57 | - return $this->di()->getBootstrap(); |
|
| 58 | - } |
|
| 55 | +protected function getBootstrap(): Bootstrap |
|
| 56 | +{ |
|
| 57 | +return $this->di()->getBootstrap(); |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * @return PluginManager |
| 62 | 62 | */ |
| 63 | - protected function getPluginManager(): PluginManager |
|
| 64 | - { |
|
| 65 | - return $this->di()->getPluginManager(); |
|
| 66 | - } |
|
| 63 | +protected function getPluginManager(): PluginManager |
|
| 64 | +{ |
|
| 65 | +return $this->di()->getPluginManager(); |
|
| 66 | +} |
|
| 67 | 67 | |
| 68 | - /** |
|
| 68 | +/** |
|
| 69 | 69 | * @return RequestHandler |
| 70 | 70 | */ |
| 71 | - protected function getRequestHandler(): RequestHandler |
|
| 72 | - { |
|
| 73 | - return $this->di()->getRequestHandler(); |
|
| 74 | - } |
|
| 71 | +protected function getRequestHandler(): RequestHandler |
|
| 72 | +{ |
|
| 73 | +return $this->di()->getRequestHandler(); |
|
| 74 | +} |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * @return ResponseManager |
| 78 | 78 | */ |
| 79 | - protected function getResponseManager(): ResponseManager |
|
| 80 | - { |
|
| 81 | - return $this->di()->getResponseManager(); |
|
| 82 | - } |
|
| 79 | +protected function getResponseManager(): ResponseManager |
|
| 80 | +{ |
|
| 81 | +return $this->di()->getResponseManager(); |
|
| 82 | +} |
|
| 83 | 83 | |
| 84 | - /** |
|
| 84 | +/** |
|
| 85 | 85 | * @return PackageManager |
| 86 | 86 | */ |
| 87 | - protected function getPackageManager(): PackageManager |
|
| 88 | - { |
|
| 89 | - return $this->di()->getPackageManager(); |
|
| 90 | - } |
|
| 87 | +protected function getPackageManager(): PackageManager |
|
| 88 | +{ |
|
| 89 | +return $this->di()->getPackageManager(); |
|
| 90 | +} |
|
| 91 | 91 | |
| 92 | - /** |
|
| 92 | +/** |
|
| 93 | 93 | * @return CodeGenerator |
| 94 | 94 | */ |
| 95 | - protected function getCodeGenerator(): CodeGenerator |
|
| 96 | - { |
|
| 97 | - return $this->di()->getCodeGenerator(); |
|
| 98 | - } |
|
| 95 | +protected function getCodeGenerator(): CodeGenerator |
|
| 96 | +{ |
|
| 97 | +return $this->di()->getCodeGenerator(); |
|
| 98 | +} |
|
| 99 | 99 | |
| 100 | - /** |
|
| 100 | +/** |
|
| 101 | 101 | * Add a view renderer with an id |
| 102 | 102 | * |
| 103 | 103 | * @param string $sRenderer The renderer name |
@@ -106,70 +106,70 @@ discard block |
||
| 106 | 106 | * |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure): void |
|
| 110 | - { |
|
| 111 | - $this->view()->setDefaultRenderer($sRenderer, $sExtension, $xClosure); |
|
| 112 | - } |
|
| 109 | +public function addViewRenderer(string $sRenderer, string $sExtension, Closure $xClosure): void |
|
| 110 | +{ |
|
| 111 | +$this->view()->setDefaultRenderer($sRenderer, $sExtension, $xClosure); |
|
| 112 | +} |
|
| 113 | 113 | |
| 114 | - /** |
|
| 114 | +/** |
|
| 115 | 115 | * @param LoggerInterface|Closure $xLogger |
| 116 | 116 | * |
| 117 | 117 | * @return void |
| 118 | 118 | */ |
| 119 | - public function setLogger(LoggerInterface|Closure $xLogger): void |
|
| 120 | - { |
|
| 121 | - $this->di()->setLogger($xLogger); |
|
| 122 | - } |
|
| 119 | +public function setLogger(LoggerInterface|Closure $xLogger): void |
|
| 120 | +{ |
|
| 121 | +$this->di()->setLogger($xLogger); |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Set the session manager |
| 126 | 126 | * |
| 127 | 127 | * @param Closure $xClosure A closure to create the session manager instance |
| 128 | 128 | * |
| 129 | 129 | * @return void |
| 130 | 130 | */ |
| 131 | - public function setSessionManager(Closure $xClosure): void |
|
| 132 | - { |
|
| 133 | - $this->di()->setSessionManager($xClosure); |
|
| 134 | - } |
|
| 131 | +public function setSessionManager(Closure $xClosure): void |
|
| 132 | +{ |
|
| 133 | +$this->di()->setSessionManager($xClosure); |
|
| 134 | +} |
|
| 135 | 135 | |
| 136 | - /** |
|
| 136 | +/** |
|
| 137 | 137 | * @return UploadHandlerInterface|null |
| 138 | 138 | */ |
| 139 | - public function upload(): ?UploadHandlerInterface |
|
| 140 | - { |
|
| 141 | - return $this->di()->getUploadHandler(); |
|
| 142 | - } |
|
| 139 | +public function upload(): ?UploadHandlerInterface |
|
| 140 | +{ |
|
| 141 | +return $this->di()->getUploadHandler(); |
|
| 142 | +} |
|
| 143 | 143 | |
| 144 | - /** |
|
| 144 | +/** |
|
| 145 | 145 | * @return PsrFactory |
| 146 | 146 | */ |
| 147 | - public function psr(): PsrFactory |
|
| 148 | - { |
|
| 149 | - return $this->di()->getPsrFactory(); |
|
| 150 | - } |
|
| 147 | +public function psr(): PsrFactory |
|
| 148 | +{ |
|
| 149 | +return $this->di()->getPsrFactory(); |
|
| 150 | +} |
|
| 151 | 151 | |
| 152 | - /** |
|
| 152 | +/** |
|
| 153 | 153 | * @return TemplateEngine |
| 154 | 154 | */ |
| 155 | - public function template(): TemplateEngine |
|
| 156 | - { |
|
| 157 | - return $this->di()->getTemplateEngine(); |
|
| 158 | - } |
|
| 155 | +public function template(): TemplateEngine |
|
| 156 | +{ |
|
| 157 | +return $this->di()->getTemplateEngine(); |
|
| 158 | +} |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * @return ViewRenderer |
| 162 | 162 | */ |
| 163 | - public function view(): ViewRenderer |
|
| 164 | - { |
|
| 165 | - return $this->di()->getViewRenderer(); |
|
| 166 | - } |
|
| 163 | +public function view(): ViewRenderer |
|
| 164 | +{ |
|
| 165 | +return $this->di()->getViewRenderer(); |
|
| 166 | +} |
|
| 167 | 167 | |
| 168 | - /** |
|
| 168 | +/** |
|
| 169 | 169 | * @return SessionInterface|null |
| 170 | 170 | */ |
| 171 | - public function session(): ?SessionInterface |
|
| 172 | - { |
|
| 173 | - return $this->di()->getSessionManager(); |
|
| 174 | - } |
|
| 171 | +public function session(): ?SessionInterface |
|
| 172 | +{ |
|
| 173 | +return $this->di()->getSessionManager(); |
|
| 174 | +} |
|
| 175 | 175 | } |
@@ -28,27 +28,27 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | trait PluginTrait |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @return PluginManager |
| 33 | 33 | */ |
| 34 | - abstract public function getPluginManager(): PluginManager; |
|
| 34 | +abstract public function getPluginManager(): PluginManager; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * @return PackageManager |
| 38 | 38 | */ |
| 39 | - abstract public function getPackageManager(): PackageManager; |
|
| 39 | +abstract public function getPackageManager(): PackageManager; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | +/** |
|
| 42 | 42 | * @return CodeGenerator |
| 43 | 43 | */ |
| 44 | - abstract public function getCodeGenerator(): CodeGenerator; |
|
| 44 | +abstract public function getCodeGenerator(): CodeGenerator; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @return Bootstrap |
| 48 | 48 | */ |
| 49 | - abstract protected function getBootstrap(): Bootstrap; |
|
| 49 | +abstract protected function getBootstrap(): Bootstrap; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Register request handlers, including functions, callable classes and directories. |
| 53 | 53 | * |
| 54 | 54 | * @param string $sType The type of request handler being registered |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | * @return void |
| 66 | 66 | * @throws SetupException |
| 67 | 67 | */ |
| 68 | - public function register(string $sType, string $sName, $xOptions = []): void |
|
| 69 | - { |
|
| 70 | - $this->getPluginManager()->registerCallable($sType, $sName, $xOptions); |
|
| 71 | - } |
|
| 68 | +public function register(string $sType, string $sName, $xOptions = []): void |
|
| 69 | +{ |
|
| 70 | +$this->getPluginManager()->registerCallable($sType, $sName, $xOptions); |
|
| 71 | +} |
|
| 72 | 72 | |
| 73 | - /** |
|
| 73 | +/** |
|
| 74 | 74 | * Register a plugin |
| 75 | 75 | * |
| 76 | 76 | * Below is a table for priorities and their description: |
@@ -85,12 +85,12 @@ discard block |
||
| 85 | 85 | * @return void |
| 86 | 86 | * @throws SetupException |
| 87 | 87 | */ |
| 88 | - public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000) |
|
| 89 | - { |
|
| 90 | - $this->getPluginManager()->registerPlugin($sClassName, $sPluginName, $nPriority); |
|
| 91 | - } |
|
| 88 | +public function registerPlugin(string $sClassName, string $sPluginName, int $nPriority = 1000) |
|
| 89 | +{ |
|
| 90 | +$this->getPluginManager()->registerPlugin($sClassName, $sPluginName, $nPriority); |
|
| 91 | +} |
|
| 92 | 92 | |
| 93 | - /** |
|
| 93 | +/** |
|
| 94 | 94 | * Register a package |
| 95 | 95 | * |
| 96 | 96 | * @param string $sClassName The package class |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | * @return void |
| 100 | 100 | * @throws SetupException |
| 101 | 101 | */ |
| 102 | - public function registerPackage(string $sClassName, array $xPkgOptions = []) |
|
| 103 | - { |
|
| 104 | - $this->getPackageManager()->registerPackage($sClassName, $xPkgOptions); |
|
| 105 | - } |
|
| 102 | +public function registerPackage(string $sClassName, array $xPkgOptions = []) |
|
| 103 | +{ |
|
| 104 | +$this->getPackageManager()->registerPackage($sClassName, $xPkgOptions); |
|
| 105 | +} |
|
| 106 | 106 | |
| 107 | - /** |
|
| 107 | +/** |
|
| 108 | 108 | * Find a response plugin by name or class name |
| 109 | 109 | * |
| 110 | 110 | * @template R of ResponsePluginInterface |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | * |
| 113 | 113 | * @return ($sName is class-string ? R : ResponsePluginInterface)|null |
| 114 | 114 | */ |
| 115 | - public function plugin(string $sName): ResponsePluginInterface|null |
|
| 116 | - { |
|
| 117 | - return $this->getPluginManager()->getResponsePlugin($sName); |
|
| 118 | - } |
|
| 115 | +public function plugin(string $sName): ResponsePluginInterface|null |
|
| 116 | +{ |
|
| 117 | +return $this->getPluginManager()->getResponsePlugin($sName); |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - /** |
|
| 120 | +/** |
|
| 121 | 121 | * Get a package instance |
| 122 | 122 | * |
| 123 | 123 | * @template P of AbstractPackage |
@@ -125,52 +125,52 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | * @return P|null |
| 127 | 127 | */ |
| 128 | - public function package(string $sClassName): ?AbstractPackage |
|
| 129 | - { |
|
| 130 | - return $this->getPackageManager()->getPackage($sClassName); |
|
| 131 | - } |
|
| 128 | +public function package(string $sClassName): ?AbstractPackage |
|
| 129 | +{ |
|
| 130 | +return $this->getPackageManager()->getPackage($sClassName); |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get the HTML tags to include Jaxon javascript files into the page. |
| 135 | 135 | * |
| 136 | 136 | * @return string |
| 137 | 137 | */ |
| 138 | - public function getJs(): string |
|
| 139 | - { |
|
| 140 | - return $this->getCodeGenerator()->getJs(); |
|
| 141 | - } |
|
| 138 | +public function getJs(): string |
|
| 139 | +{ |
|
| 140 | +return $this->getCodeGenerator()->getJs(); |
|
| 141 | +} |
|
| 142 | 142 | |
| 143 | - /** |
|
| 143 | +/** |
|
| 144 | 144 | * Get the HTML tags to include Jaxon javascript files into the page. |
| 145 | 145 | * |
| 146 | 146 | * @return string the javascript code |
| 147 | 147 | */ |
| 148 | - public function js(): string |
|
| 149 | - { |
|
| 150 | - return $this->getCodeGenerator()->getJs(); |
|
| 151 | - } |
|
| 148 | +public function js(): string |
|
| 149 | +{ |
|
| 150 | +return $this->getCodeGenerator()->getJs(); |
|
| 151 | +} |
|
| 152 | 152 | |
| 153 | - /** |
|
| 153 | +/** |
|
| 154 | 154 | * Get the HTML tags to include Jaxon CSS code and files into the page. |
| 155 | 155 | * |
| 156 | 156 | * @return string |
| 157 | 157 | */ |
| 158 | - public function getCss(): string |
|
| 159 | - { |
|
| 160 | - return $this->getCodeGenerator()->getCss(); |
|
| 161 | - } |
|
| 158 | +public function getCss(): string |
|
| 159 | +{ |
|
| 160 | +return $this->getCodeGenerator()->getCss(); |
|
| 161 | +} |
|
| 162 | 162 | |
| 163 | - /** |
|
| 163 | +/** |
|
| 164 | 164 | * Get the HTML tags to include Jaxon CSS code and files into the page. |
| 165 | 165 | * |
| 166 | 166 | * @return string |
| 167 | 167 | */ |
| 168 | - public function css(): string |
|
| 169 | - { |
|
| 170 | - return $this->getCodeGenerator()->getCss(); |
|
| 171 | - } |
|
| 168 | +public function css(): string |
|
| 169 | +{ |
|
| 170 | +return $this->getCodeGenerator()->getCss(); |
|
| 171 | +} |
|
| 172 | 172 | |
| 173 | - /** |
|
| 173 | +/** |
|
| 174 | 174 | * Returns the js header and wrapper code to be printed into the page |
| 175 | 175 | * |
| 176 | 176 | * The javascript code returned by this function depends on the plugins |
@@ -182,12 +182,12 @@ discard block |
||
| 182 | 182 | * @return string |
| 183 | 183 | * @throws UriException |
| 184 | 184 | */ |
| 185 | - public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string |
|
| 186 | - { |
|
| 187 | - return $this->getCodeGenerator()->getScript($bIncludeJs, $bIncludeCss); |
|
| 188 | - } |
|
| 185 | +public function getScript(bool $bIncludeJs = false, bool $bIncludeCss = false): string |
|
| 186 | +{ |
|
| 187 | +return $this->getCodeGenerator()->getScript($bIncludeJs, $bIncludeCss); |
|
| 188 | +} |
|
| 189 | 189 | |
| 190 | - /** |
|
| 190 | +/** |
|
| 191 | 191 | * Returns the js header and wrapper code to be printed into the page |
| 192 | 192 | * |
| 193 | 193 | * @param bool $bIncludeJs Also get the js code |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | * @return string the javascript code |
| 197 | 197 | * @throws UriException |
| 198 | 198 | */ |
| 199 | - public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string |
|
| 200 | - { |
|
| 201 | - return $this->getCodeGenerator()->getScript($bIncludeJs, $bIncludeCss); |
|
| 202 | - } |
|
| 199 | +public function script(bool $bIncludeJs = false, bool $bIncludeCss = false): string |
|
| 200 | +{ |
|
| 201 | +return $this->getCodeGenerator()->getScript($bIncludeJs, $bIncludeCss); |
|
| 202 | +} |
|
| 203 | 203 | } |
@@ -32,110 +32,110 @@ |
||
| 32 | 32 | |
| 33 | 33 | final class Jaxon |
| 34 | 34 | { |
| 35 | - use Traits\ConfigTrait; |
|
| 36 | - use Traits\ServicesTrait; |
|
| 37 | - use Traits\PluginTrait; |
|
| 38 | - use Traits\RequestTrait; |
|
| 39 | - use Traits\ResponseTrait; |
|
| 40 | - use Traits\SendResponseTrait; |
|
| 41 | - |
|
| 42 | - /** |
|
| 35 | +use Traits\ConfigTrait; |
|
| 36 | +use Traits\ServicesTrait; |
|
| 37 | +use Traits\PluginTrait; |
|
| 38 | +use Traits\RequestTrait; |
|
| 39 | +use Traits\ResponseTrait; |
|
| 40 | +use Traits\SendResponseTrait; |
|
| 41 | + |
|
| 42 | +/** |
|
| 43 | 43 | * @var Jaxon|null |
| 44 | 44 | */ |
| 45 | - private static $xInstance = null; |
|
| 45 | +private static $xInstance = null; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * The constructor |
| 49 | 49 | * |
| 50 | 50 | * @param Container $xContainer |
| 51 | 51 | * @param ComponentContainer $xComponentContainer |
| 52 | 52 | */ |
| 53 | - private function __construct(Container $xContainer, ComponentContainer $xComponentContainer) |
|
| 54 | - { |
|
| 55 | - $this->xContainer = $xContainer; |
|
| 56 | - $this->xComponentContainer = $xComponentContainer; |
|
| 57 | - } |
|
| 53 | +private function __construct(Container $xContainer, ComponentContainer $xComponentContainer) |
|
| 54 | +{ |
|
| 55 | +$this->xContainer = $xContainer; |
|
| 56 | +$this->xComponentContainer = $xComponentContainer; |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @return Jaxon |
| 61 | 61 | */ |
| 62 | - private static function createInstance(): Jaxon |
|
| 63 | - { |
|
| 64 | - $xContainer = new Container(); |
|
| 65 | - $xComponentContainer = new ComponentContainer($xContainer); |
|
| 66 | - self::$xInstance = new Jaxon($xContainer, $xComponentContainer); |
|
| 62 | +private static function createInstance(): Jaxon |
|
| 63 | +{ |
|
| 64 | +$xContainer = new Container(); |
|
| 65 | +$xComponentContainer = new ComponentContainer($xContainer); |
|
| 66 | +self::$xInstance = new Jaxon($xContainer, $xComponentContainer); |
|
| 67 | 67 | |
| 68 | - // Save the Jaxon and container instances |
|
| 69 | - $xContainer->val(Jaxon::class, self::$xInstance); |
|
| 70 | - $xContainer->val(ComponentContainer::class, $xComponentContainer); |
|
| 68 | +// Save the Jaxon and container instances |
|
| 69 | +$xContainer->val(Jaxon::class, self::$xInstance); |
|
| 70 | +$xContainer->val(ComponentContainer::class, $xComponentContainer); |
|
| 71 | 71 | |
| 72 | - // Make the helpers functions available in the global namespace. |
|
| 73 | - self::$xInstance->callback()->boot(function() { |
|
| 74 | - self::$xInstance->config()->globals(); |
|
| 75 | - }); |
|
| 72 | +// Make the helpers functions available in the global namespace. |
|
| 73 | +self::$xInstance->callback()->boot(function() { |
|
| 74 | +self::$xInstance->config()->globals(); |
|
| 75 | +}); |
|
| 76 | 76 | |
| 77 | - return self::$xInstance; |
|
| 78 | - } |
|
| 77 | +return self::$xInstance; |
|
| 78 | +} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * @return Jaxon |
| 82 | 82 | */ |
| 83 | - public static function getInstance(): Jaxon |
|
| 84 | - { |
|
| 85 | - return self::$xInstance ?: self::$xInstance = self::createInstance(); |
|
| 86 | - } |
|
| 83 | +public static function getInstance(): Jaxon |
|
| 84 | +{ |
|
| 85 | +return self::$xInstance ?: self::$xInstance = self::createInstance(); |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * @return string |
| 90 | 90 | */ |
| 91 | - public function getVersion(): string |
|
| 92 | - { |
|
| 93 | - return \Jaxon\Jaxon::VERSION; |
|
| 94 | - } |
|
| 91 | +public function getVersion(): string |
|
| 92 | +{ |
|
| 93 | +return \Jaxon\Jaxon::VERSION; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * @return ConfigManager |
| 98 | 98 | */ |
| 99 | - public function config(): ConfigManager |
|
| 100 | - { |
|
| 101 | - return $this->xContainer->config(); |
|
| 102 | - } |
|
| 99 | +public function config(): ConfigManager |
|
| 100 | +{ |
|
| 101 | +return $this->xContainer->config(); |
|
| 102 | +} |
|
| 103 | 103 | |
| 104 | - /** |
|
| 104 | +/** |
|
| 105 | 105 | * Set the ajax endpoint URI |
| 106 | 106 | * |
| 107 | 107 | * @param string $sUri The ajax endpoint URI |
| 108 | 108 | * |
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | - public function setUri(string $sUri): void |
|
| 112 | - { |
|
| 113 | - $this->config()->setOption('core.request.uri', $sUri); |
|
| 114 | - } |
|
| 111 | +public function setUri(string $sUri): void |
|
| 112 | +{ |
|
| 113 | +$this->config()->setOption('core.request.uri', $sUri); |
|
| 114 | +} |
|
| 115 | 115 | |
| 116 | - /** |
|
| 116 | +/** |
|
| 117 | 117 | * @return AppInterface |
| 118 | 118 | */ |
| 119 | - public function app(): AppInterface |
|
| 120 | - { |
|
| 121 | - return $this->xContainer->getApp(); |
|
| 122 | - } |
|
| 119 | +public function app(): AppInterface |
|
| 120 | +{ |
|
| 121 | +return $this->xContainer->getApp(); |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Get the callback manager |
| 126 | 126 | * |
| 127 | 127 | * @return CallbackManager |
| 128 | 128 | */ |
| 129 | - public function callback(): CallbackManager |
|
| 130 | - { |
|
| 131 | - return $this->xContainer->callback(); |
|
| 132 | - } |
|
| 129 | +public function callback(): CallbackManager |
|
| 130 | +{ |
|
| 131 | +return $this->xContainer->callback(); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * @return void |
| 136 | 136 | */ |
| 137 | - public function reset(): void |
|
| 138 | - { |
|
| 139 | - self::$xInstance = null; |
|
| 140 | - } |
|
| 137 | +public function reset(): void |
|
| 138 | +{ |
|
| 139 | +self::$xInstance = null; |
|
| 140 | +} |
|
| 141 | 141 | } |
@@ -22,53 +22,53 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ConfigScriptGenerator extends AbstractCodeGenerator |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The constructor |
| 27 | 27 | * |
| 28 | 28 | * @param ParameterReader $xParameterReader |
| 29 | 29 | * @param TemplateEngine $xTemplateEngine |
| 30 | 30 | * @param ConfigManager $xConfigManager |
| 31 | 31 | */ |
| 32 | - public function __construct(private ParameterReader $xParameterReader, |
|
| 33 | - private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager) |
|
| 34 | - {} |
|
| 32 | +public function __construct(private ParameterReader $xParameterReader, |
|
| 33 | +private TemplateEngine $xTemplateEngine, private ConfigManager $xConfigManager) |
|
| 34 | +{} |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the value of a config option |
| 38 | 38 | * |
| 39 | 39 | * @param string $sName The option name |
| 40 | 40 | * |
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - private function option(string $sName): mixed |
|
| 44 | - { |
|
| 45 | - return $this->xConfigManager->getOption($sName); |
|
| 46 | - } |
|
| 43 | +private function option(string $sName): mixed |
|
| 44 | +{ |
|
| 45 | +return $this->xConfigManager->getOption($sName); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @inheritDoc |
| 50 | 50 | * @throws UriException |
| 51 | 51 | */ |
| 52 | - public function getScript(): string |
|
| 53 | - { |
|
| 54 | - // It is important to call $this->xParameterReader->uri() only if necessary. |
|
| 55 | - $sUri = $this->option('core.request.uri') ?: $this->xParameterReader->uri(); |
|
| 56 | - $aOptions = [ |
|
| 57 | - 'sResponseType' => 'JSON', |
|
| 58 | - 'sVersion' => $this->option('core.version'), |
|
| 59 | - 'sLanguage' => $this->option('core.language'), |
|
| 60 | - 'sRequestURI' => $sUri, |
|
| 61 | - 'sDefaultMode' => $this->option('core.request.mode'), |
|
| 62 | - 'sDefaultMethod' => $this->option('core.request.method'), |
|
| 63 | - 'sCsrfMetaName' => $this->option('core.request.csrf_meta'), |
|
| 64 | - 'bLoggingEnabled' => $this->xConfigManager->loggingEnabled(), |
|
| 65 | - 'bDebug' => $this->option('core.debug.on'), |
|
| 66 | - 'bVerboseDebug' => $this->option('core.debug.verbose'), |
|
| 67 | - 'sDebugOutputID' => $this->option('core.debug.output_id'), |
|
| 68 | - 'nResponseQueueSize' => $this->option('js.lib.queue_size'), |
|
| 69 | - 'sStatusMessages' => $this->option('js.lib.show_status') ? 'true' : 'false', |
|
| 70 | - 'sWaitCursor' => $this->option('js.lib.show_cursor') ? 'true' : 'false', |
|
| 71 | - ]; |
|
| 72 | - return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions); |
|
| 73 | - } |
|
| 52 | +public function getScript(): string |
|
| 53 | +{ |
|
| 54 | +// It is important to call $this->xParameterReader->uri() only if necessary. |
|
| 55 | +$sUri = $this->option('core.request.uri') ?: $this->xParameterReader->uri(); |
|
| 56 | +$aOptions = [ |
|
| 57 | +'sResponseType' => 'JSON', |
|
| 58 | +'sVersion' => $this->option('core.version'), |
|
| 59 | +'sLanguage' => $this->option('core.language'), |
|
| 60 | +'sRequestURI' => $sUri, |
|
| 61 | +'sDefaultMode' => $this->option('core.request.mode'), |
|
| 62 | +'sDefaultMethod' => $this->option('core.request.method'), |
|
| 63 | +'sCsrfMetaName' => $this->option('core.request.csrf_meta'), |
|
| 64 | +'bLoggingEnabled' => $this->xConfigManager->loggingEnabled(), |
|
| 65 | +'bDebug' => $this->option('core.debug.on'), |
|
| 66 | +'bVerboseDebug' => $this->option('core.debug.verbose'), |
|
| 67 | +'sDebugOutputID' => $this->option('core.debug.output_id'), |
|
| 68 | +'nResponseQueueSize' => $this->option('js.lib.queue_size'), |
|
| 69 | +'sStatusMessages' => $this->option('js.lib.show_status') ? 'true' : 'false', |
|
| 70 | +'sWaitCursor' => $this->option('js.lib.show_cursor') ? 'true' : 'false', |
|
| 71 | +]; |
|
| 72 | +return $this->xTemplateEngine->render('jaxon::plugins/config.js', $aOptions); |
|
| 73 | +} |
|
| 74 | 74 | } |