@@ -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 | } |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | */ |
| 142 | 142 | public function val(string $sKey, $xValue): void |
| 143 | 143 | { |
| 144 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 144 | + $this->xContainer->offsetSet($sKey, $xValue); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -40,85 +40,85 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | class ComponentContainer |
| 42 | 42 | { |
| 43 | - use Traits\DiAutoTrait; |
|
| 44 | - use Traits\ComponentTrait; |
|
| 43 | +use Traits\DiAutoTrait; |
|
| 44 | +use Traits\ComponentTrait; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * The Dependency Injection Container for registered classes |
| 48 | 48 | * |
| 49 | 49 | * @var PimpleContainer |
| 50 | 50 | */ |
| 51 | - private $xContainer; |
|
| 51 | +private $xContainer; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | +/** |
|
| 54 | 54 | * This will be set only when getting the object targetted by the ajax request. |
| 55 | 55 | * |
| 56 | 56 | * @var Target|null |
| 57 | 57 | */ |
| 58 | - private $xTarget = null; |
|
| 58 | +private $xTarget = null; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * The class constructor |
| 62 | 62 | * |
| 63 | 63 | * @param Container $di |
| 64 | 64 | */ |
| 65 | - public function __construct(private Container $di) |
|
| 66 | - { |
|
| 67 | - $this->xContainer = new PimpleContainer(); |
|
| 68 | - $this->val(ComponentContainer::class, $this); |
|
| 69 | - |
|
| 70 | - // Register the call factory for registered functions |
|
| 71 | - $this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 72 | - new JxnCall($this->di->g(ConfigManager::class) |
|
| 73 | - ->getOption('core.prefix.function', ''))); |
|
| 74 | - |
|
| 75 | - // Register the pagination component, but do not export to js. |
|
| 76 | - $this->saveComponent(Pagination::class, [ |
|
| 77 | - 'excluded' => true, |
|
| 78 | - 'separator' => '.', |
|
| 79 | - // The namespace has the same name as the Component class. |
|
| 80 | - 'namespace' => Component::class, |
|
| 81 | - ]); |
|
| 82 | - |
|
| 83 | - // Register the logger component, and export to js. |
|
| 84 | - $this->di->callback()->boot(function() { |
|
| 85 | - if($this->di->config()->loggingEnabled()) |
|
| 86 | - { |
|
| 87 | - $this->saveComponent(LoggerComponent::class, [ |
|
| 88 | - 'separator' => '.', |
|
| 89 | - // The namespace has the same name as the Component class. |
|
| 90 | - 'namespace' => Component::class, |
|
| 91 | - ]); |
|
| 92 | - } |
|
| 93 | - }); |
|
| 94 | - |
|
| 95 | - $this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 96 | - $this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 97 | - } |
|
| 65 | +public function __construct(private Container $di) |
|
| 66 | +{ |
|
| 67 | +$this->xContainer = new PimpleContainer(); |
|
| 68 | +$this->val(ComponentContainer::class, $this); |
|
| 69 | + |
|
| 70 | +// Register the call factory for registered functions |
|
| 71 | +$this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 72 | +new JxnCall($this->di->g(ConfigManager::class) |
|
| 73 | + ->getOption('core.prefix.function', ''))); |
|
| 74 | + |
|
| 75 | +// Register the pagination component, but do not export to js. |
|
| 76 | +$this->saveComponent(Pagination::class, [ |
|
| 77 | +'excluded' => true, |
|
| 78 | +'separator' => '.', |
|
| 79 | +// The namespace has the same name as the Component class. |
|
| 80 | +'namespace' => Component::class, |
|
| 81 | +]); |
|
| 82 | + |
|
| 83 | +// Register the logger component, and export to js. |
|
| 84 | +$this->di->callback()->boot(function() { |
|
| 85 | +if($this->di->config()->loggingEnabled()) |
|
| 86 | +{ |
|
| 87 | + $this->saveComponent(LoggerComponent::class, [ |
|
| 88 | + 'separator' => '.', |
|
| 89 | + // The namespace has the same name as the Component class. |
|
| 90 | + 'namespace' => Component::class, |
|
| 91 | + ]); |
|
| 92 | +} |
|
| 93 | +}); |
|
| 94 | + |
|
| 95 | +$this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 96 | +$this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * The container for parameters |
| 101 | 101 | * |
| 102 | 102 | * @return Container |
| 103 | 103 | */ |
| 104 | - protected function cn(): Container |
|
| 105 | - { |
|
| 106 | - return $this->di; |
|
| 107 | - } |
|
| 104 | +protected function cn(): Container |
|
| 105 | +{ |
|
| 106 | +return $this->di; |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Check if a class is defined in the container |
| 111 | 111 | * |
| 112 | 112 | * @param class-string $sClass The full class name |
| 113 | 113 | * |
| 114 | 114 | * @return bool |
| 115 | 115 | */ |
| 116 | - public function has(string $sClass): bool |
|
| 117 | - { |
|
| 118 | - return $this->xContainer->offsetExists($sClass); |
|
| 119 | - } |
|
| 116 | +public function has(string $sClass): bool |
|
| 117 | +{ |
|
| 118 | +return $this->xContainer->offsetExists($sClass); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Save a closure in the container |
| 123 | 123 | * |
| 124 | 124 | * @param class-string $sClass The full class name |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function set(string $sClass, Closure $xClosure): void |
|
| 130 | - { |
|
| 131 | - $this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 132 | - } |
|
| 129 | +public function set(string $sClass, Closure $xClosure): void |
|
| 130 | +{ |
|
| 131 | +$this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * Save a value in the container |
| 136 | 136 | * |
| 137 | 137 | * @param string|class-string $sKey The key |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return void |
| 141 | 141 | */ |
| 142 | - public function val(string $sKey, $xValue): void |
|
| 143 | - { |
|
| 144 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 145 | - } |
|
| 142 | +public function val(string $sKey, $xValue): void |
|
| 143 | +{ |
|
| 144 | +$this->xContainer->offsetSet($sKey, $xValue); |
|
| 145 | +} |
|
| 146 | 146 | |
| 147 | - /** |
|
| 147 | +/** |
|
| 148 | 148 | * Get a class instance |
| 149 | 149 | * |
| 150 | 150 | * @template T |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | * |
| 153 | 153 | * @return T |
| 154 | 154 | */ |
| 155 | - public function get(string $sClass): mixed |
|
| 156 | - { |
|
| 157 | - return $this->xContainer->offsetGet($sClass); |
|
| 158 | - } |
|
| 155 | +public function get(string $sClass): mixed |
|
| 156 | +{ |
|
| 157 | +return $this->xContainer->offsetGet($sClass); |
|
| 158 | +} |
|
| 159 | 159 | |
| 160 | - /** |
|
| 160 | +/** |
|
| 161 | 161 | * Get a component when one of its method needs to be called |
| 162 | 162 | * |
| 163 | 163 | * @template T |
@@ -166,17 +166,17 @@ discard block |
||
| 166 | 166 | * |
| 167 | 167 | * @return T|null |
| 168 | 168 | */ |
| 169 | - public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 170 | - { |
|
| 171 | - // Set the target only when getting the object targetted by the ajax request. |
|
| 172 | - $this->xTarget = $xTarget; |
|
| 173 | - $xComponent = $this->get($sClassName); |
|
| 174 | - $this->xTarget = null; |
|
| 169 | +public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 170 | +{ |
|
| 171 | +// Set the target only when getting the object targetted by the ajax request. |
|
| 172 | +$this->xTarget = $xTarget; |
|
| 173 | +$xComponent = $this->get($sClassName); |
|
| 174 | +$this->xTarget = null; |
|
| 175 | 175 | |
| 176 | - return $xComponent; |
|
| 177 | - } |
|
| 176 | +return $xComponent; |
|
| 177 | +} |
|
| 178 | 178 | |
| 179 | - /** |
|
| 179 | +/** |
|
| 180 | 180 | * Register a component and its options |
| 181 | 181 | * |
| 182 | 182 | * @param class-string $sClassName The class name |
@@ -184,40 +184,40 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return void |
| 186 | 186 | */ |
| 187 | - public function saveComponent(string $sClassName, array $aOptions): void |
|
| 188 | - { |
|
| 189 | - try |
|
| 190 | - { |
|
| 191 | - // Make sure the registered class exists |
|
| 192 | - if(isset($aOptions['include'])) |
|
| 193 | - { |
|
| 194 | - require_once $aOptions['include']; |
|
| 195 | - } |
|
| 196 | - $xReflectionClass = new ReflectionClass($sClassName); |
|
| 197 | - // Check if the class is registrable |
|
| 198 | - if(!$xReflectionClass->isInstantiable()) |
|
| 199 | - { |
|
| 200 | - return; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $this->_saveClassOptions($sClassName, $aOptions); |
|
| 204 | - |
|
| 205 | - $sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 206 | - $this->val($sClassKey, $xReflectionClass); |
|
| 207 | - // Register the user class, but only if the user didn't already. |
|
| 208 | - if(!$this->has($sClassName)) |
|
| 209 | - { |
|
| 210 | - $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - catch(ReflectionException $e) |
|
| 214 | - { |
|
| 215 | - throw new SetupException($this->cn()->g(Translator::class) |
|
| 216 | - ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 217 | - } |
|
| 218 | - } |
|
| 187 | +public function saveComponent(string $sClassName, array $aOptions): void |
|
| 188 | +{ |
|
| 189 | +try |
|
| 190 | +{ |
|
| 191 | +// Make sure the registered class exists |
|
| 192 | +if(isset($aOptions['include'])) |
|
| 193 | +{ |
|
| 194 | + require_once $aOptions['include']; |
|
| 195 | +} |
|
| 196 | +$xReflectionClass = new ReflectionClass($sClassName); |
|
| 197 | +// Check if the class is registrable |
|
| 198 | +if(!$xReflectionClass->isInstantiable()) |
|
| 199 | +{ |
|
| 200 | + return; |
|
| 201 | +} |
|
| 219 | 202 | |
| 220 | - /** |
|
| 203 | +$this->_saveClassOptions($sClassName, $aOptions); |
|
| 204 | + |
|
| 205 | +$sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 206 | +$this->val($sClassKey, $xReflectionClass); |
|
| 207 | +// Register the user class, but only if the user didn't already. |
|
| 208 | +if(!$this->has($sClassName)) |
|
| 209 | +{ |
|
| 210 | + $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 211 | +} |
|
| 212 | +} |
|
| 213 | +catch(ReflectionException $e) |
|
| 214 | +{ |
|
| 215 | +throw new SetupException($this->cn()->g(Translator::class) |
|
| 216 | + ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 217 | +} |
|
| 218 | +} |
|
| 219 | + |
|
| 220 | +/** |
|
| 221 | 221 | * Register a component |
| 222 | 222 | * |
| 223 | 223 | * @param string $sComponentId The component name |
@@ -225,74 +225,74 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | * @throws SetupException |
| 227 | 227 | */ |
| 228 | - private function _registerComponent(string $sComponentId): string |
|
| 229 | - { |
|
| 230 | - // Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 231 | - $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 232 | - |
|
| 233 | - $sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 234 | - // Prevent duplication. It's important not to use the class name here. |
|
| 235 | - if($this->has($sComponentObject)) |
|
| 236 | - { |
|
| 237 | - return $sClassName; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Register the helper class |
|
| 241 | - $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 242 | - $xFactory = $this->di->getCallFactory(); |
|
| 243 | - return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 244 | - $xFactory, $this->di->getViewRenderer(), |
|
| 245 | - $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 246 | - $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 247 | - }); |
|
| 248 | - |
|
| 249 | - $this->discoverComponent($sClassName); |
|
| 250 | - |
|
| 251 | - // Register the callable object |
|
| 252 | - $this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 253 | - $aOptions = $this->_getClassOptions($sComponentId); |
|
| 254 | - $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 255 | - $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 256 | - return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 257 | - }); |
|
| 258 | - |
|
| 259 | - // Initialize the user class instance |
|
| 260 | - $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 261 | - if($xClassInstance instanceof AbstractComponent) |
|
| 262 | - { |
|
| 263 | - $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 264 | - $xHelper->xTarget = $this->xTarget; |
|
| 265 | - |
|
| 266 | - // Call the protected "initComponent()" method of the Component class. |
|
| 267 | - $cSetter = function($di, $xHelper) { |
|
| 268 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 269 | - }; |
|
| 270 | - $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 271 | - call_user_func($cSetter, $this->di, $xHelper); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Run the callbacks for class initialisation |
|
| 275 | - $this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 276 | - |
|
| 277 | - // Set attributes from the DI container. |
|
| 278 | - // The class level DI options are set on any component. |
|
| 279 | - // The method level DI options are set only on the targetted component. |
|
| 280 | - /** @var CallableObject */ |
|
| 281 | - $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 282 | - $xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 283 | - if($this->xTarget !== null) |
|
| 284 | - { |
|
| 285 | - $sMethodName = $this->xTarget->getMethodName(); |
|
| 286 | - $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $xClassInstance; |
|
| 290 | - }); |
|
| 291 | - |
|
| 292 | - return $sClassName; |
|
| 293 | - } |
|
| 228 | +private function _registerComponent(string $sComponentId): string |
|
| 229 | +{ |
|
| 230 | +// Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 231 | +$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 232 | + |
|
| 233 | +$sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 234 | +// Prevent duplication. It's important not to use the class name here. |
|
| 235 | +if($this->has($sComponentObject)) |
|
| 236 | +{ |
|
| 237 | +return $sClassName; |
|
| 238 | +} |
|
| 239 | + |
|
| 240 | +// Register the helper class |
|
| 241 | +$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 242 | +$xFactory = $this->di->getCallFactory(); |
|
| 243 | +return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 244 | + $xFactory, $this->di->getViewRenderer(), |
|
| 245 | + $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 246 | + $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 247 | +}); |
|
| 248 | + |
|
| 249 | +$this->discoverComponent($sClassName); |
|
| 250 | + |
|
| 251 | +// Register the callable object |
|
| 252 | +$this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 253 | +$aOptions = $this->_getClassOptions($sComponentId); |
|
| 254 | +$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 255 | +$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 256 | +return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 257 | +}); |
|
| 258 | + |
|
| 259 | +// Initialize the user class instance |
|
| 260 | +$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 261 | +if($xClassInstance instanceof AbstractComponent) |
|
| 262 | +{ |
|
| 263 | + $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 264 | + $xHelper->xTarget = $this->xTarget; |
|
| 265 | + |
|
| 266 | + // Call the protected "initComponent()" method of the Component class. |
|
| 267 | + $cSetter = function($di, $xHelper) { |
|
| 268 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 269 | + }; |
|
| 270 | + $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 271 | + call_user_func($cSetter, $this->di, $xHelper); |
|
| 272 | +} |
|
| 273 | + |
|
| 274 | +// Run the callbacks for class initialisation |
|
| 275 | +$this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 276 | + |
|
| 277 | +// Set attributes from the DI container. |
|
| 278 | +// The class level DI options are set on any component. |
|
| 279 | +// The method level DI options are set only on the targetted component. |
|
| 280 | +/** @var CallableObject */ |
|
| 281 | +$xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 282 | +$xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 283 | +if($this->xTarget !== null) |
|
| 284 | +{ |
|
| 285 | + $sMethodName = $this->xTarget->getMethodName(); |
|
| 286 | + $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 287 | +} |
|
| 288 | + |
|
| 289 | +return $xClassInstance; |
|
| 290 | +}); |
|
| 291 | + |
|
| 292 | +return $sClassName; |
|
| 293 | +} |
|
| 294 | 294 | |
| 295 | - /** |
|
| 295 | +/** |
|
| 296 | 296 | * Get the callable object for a given class |
| 297 | 297 | * The callable object is registered if it is not already in the DI. |
| 298 | 298 | * |
@@ -301,13 +301,13 @@ discard block |
||
| 301 | 301 | * @return CallableObject|null |
| 302 | 302 | * @throws SetupException |
| 303 | 303 | */ |
| 304 | - public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 305 | - { |
|
| 306 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 307 | - return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 308 | - } |
|
| 304 | +public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 305 | +{ |
|
| 306 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 307 | +return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 308 | +} |
|
| 309 | 309 | |
| 310 | - /** |
|
| 310 | +/** |
|
| 311 | 311 | * Get an instance of a component by name |
| 312 | 312 | * |
| 313 | 313 | * @template T |
@@ -316,53 +316,53 @@ discard block |
||
| 316 | 316 | * @return T|null |
| 317 | 317 | * @throws SetupException |
| 318 | 318 | */ |
| 319 | - public function makeComponent(string $sClassName): mixed |
|
| 320 | - { |
|
| 321 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 322 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 323 | - return $this->get($sClassName); |
|
| 324 | - } |
|
| 319 | +public function makeComponent(string $sClassName): mixed |
|
| 320 | +{ |
|
| 321 | +$sComponentId = str_replace('\\', '.', $sClassName); |
|
| 322 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 323 | +return $this->get($sClassName); |
|
| 324 | +} |
|
| 325 | 325 | |
| 326 | - /** |
|
| 326 | +/** |
|
| 327 | 327 | * Get a factory for a call to a registered function. |
| 328 | 328 | * |
| 329 | 329 | * @return JxnCall |
| 330 | 330 | */ |
| 331 | - public function getFunctionRequestFactory(): JxnCall |
|
| 332 | - { |
|
| 333 | - return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 334 | - } |
|
| 331 | +public function getFunctionRequestFactory(): JxnCall |
|
| 332 | +{ |
|
| 333 | +return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 334 | +} |
|
| 335 | 335 | |
| 336 | - /** |
|
| 336 | +/** |
|
| 337 | 337 | * Get a factory for a call to a registered component. |
| 338 | 338 | * |
| 339 | 339 | * @param class-string $sClassName |
| 340 | 340 | * |
| 341 | 341 | * @return JxnCall|null |
| 342 | 342 | */ |
| 343 | - public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 343 | +public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 344 | +{ |
|
| 345 | +$sClassName = trim($sClassName, " \t"); |
|
| 346 | +if($sClassName === '') |
|
| 347 | +{ |
|
| 348 | +return null; |
|
| 349 | +} |
|
| 350 | + |
|
| 351 | +$sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 352 | +if(!$this->has($sFactoryKey)) |
|
| 353 | +{ |
|
| 354 | +$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 355 | + $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 356 | + if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 344 | 357 | { |
| 345 | - $sClassName = trim($sClassName, " \t"); |
|
| 346 | - if($sClassName === '') |
|
| 347 | - { |
|
| 348 | - return null; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 352 | - if(!$this->has($sFactoryKey)) |
|
| 353 | - { |
|
| 354 | - $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 355 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 356 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 357 | - { |
|
| 358 | - return null; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 362 | - $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 363 | - return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 364 | - }); |
|
| 365 | - } |
|
| 366 | - return $this->get($sFactoryKey); |
|
| 358 | + return null; |
|
| 367 | 359 | } |
| 360 | + |
|
| 361 | + $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 362 | + $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 363 | + return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 364 | +}); |
|
| 365 | +} |
|
| 366 | +return $this->get($sFactoryKey); |
|
| 367 | +} |
|
| 368 | 368 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | // Register the logger component, and export to js. |
| 84 | 84 | $this->di->callback()->boot(function() { |
| 85 | - if($this->di->config()->loggingEnabled()) |
|
| 85 | + if ($this->di->config()->loggingEnabled()) |
|
| 86 | 86 | { |
| 87 | 87 | $this->saveComponent(LoggerComponent::class, [ |
| 88 | 88 | 'separator' => '.', |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | try |
| 190 | 190 | { |
| 191 | 191 | // Make sure the registered class exists |
| 192 | - if(isset($aOptions['include'])) |
|
| 192 | + if (isset($aOptions['include'])) |
|
| 193 | 193 | { |
| 194 | 194 | require_once $aOptions['include']; |
| 195 | 195 | } |
| 196 | 196 | $xReflectionClass = new ReflectionClass($sClassName); |
| 197 | 197 | // Check if the class is registrable |
| 198 | - if(!$xReflectionClass->isInstantiable()) |
|
| 198 | + if (!$xReflectionClass->isInstantiable()) |
|
| 199 | 199 | { |
| 200 | 200 | return; |
| 201 | 201 | } |
@@ -205,12 +205,12 @@ discard block |
||
| 205 | 205 | $sClassKey = $this->getReflectionClassKey($sClassName); |
| 206 | 206 | $this->val($sClassKey, $xReflectionClass); |
| 207 | 207 | // Register the user class, but only if the user didn't already. |
| 208 | - if(!$this->has($sClassName)) |
|
| 208 | + if (!$this->has($sClassName)) |
|
| 209 | 209 | { |
| 210 | 210 | $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | - catch(ReflectionException $e) |
|
| 213 | + catch (ReflectionException $e) |
|
| 214 | 214 | { |
| 215 | 215 | throw new SetupException($this->cn()->g(Translator::class) |
| 216 | 216 | ->trans('errors.class.invalid', ['name' => $sClassName])); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | |
| 233 | 233 | $sComponentObject = $this->getCallableObjectKey($sClassName); |
| 234 | 234 | // Prevent duplication. It's important not to use the class name here. |
| 235 | - if($this->has($sComponentObject)) |
|
| 235 | + if ($this->has($sComponentObject)) |
|
| 236 | 236 | { |
| 237 | 237 | return $sClassName; |
| 238 | 238 | } |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | |
| 259 | 259 | // Initialize the user class instance |
| 260 | 260 | $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
| 261 | - if($xClassInstance instanceof AbstractComponent) |
|
| 261 | + if ($xClassInstance instanceof AbstractComponent) |
|
| 262 | 262 | { |
| 263 | 263 | $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
| 264 | 264 | $xHelper->xTarget = $this->xTarget; |
| 265 | 265 | |
| 266 | 266 | // Call the protected "initComponent()" method of the Component class. |
| 267 | 267 | $cSetter = function($di, $xHelper) { |
| 268 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 268 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 269 | 269 | }; |
| 270 | 270 | $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
| 271 | 271 | call_user_func($cSetter, $this->di, $xHelper); |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | /** @var CallableObject */ |
| 281 | 281 | $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
| 282 | 282 | $xCallableObject->setDiClassAttributes($xClassInstance); |
| 283 | - if($this->xTarget !== null) |
|
| 283 | + if ($this->xTarget !== null) |
|
| 284 | 284 | { |
| 285 | 285 | $sMethodName = $this->xTarget->getMethodName(); |
| 286 | 286 | $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
@@ -343,17 +343,17 @@ discard block |
||
| 343 | 343 | public function getComponentRequestFactory(string $sClassName): ?JxnCall |
| 344 | 344 | { |
| 345 | 345 | $sClassName = trim($sClassName, " \t"); |
| 346 | - if($sClassName === '') |
|
| 346 | + if ($sClassName === '') |
|
| 347 | 347 | { |
| 348 | 348 | return null; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
| 352 | - if(!$this->has($sFactoryKey)) |
|
| 352 | + if (!$this->has($sFactoryKey)) |
|
| 353 | 353 | { |
| 354 | 354 | $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
| 355 | 355 | $sComponentId = str_replace('\\', '.', $sClassName); |
| 356 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 356 | + if (!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 357 | 357 | { |
| 358 | 358 | return null; |
| 359 | 359 | } |
@@ -29,145 +29,145 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class Container |
| 31 | 31 | { |
| 32 | - use Traits\AppTrait; |
|
| 33 | - use Traits\PsrTrait; |
|
| 34 | - use Traits\RequestTrait; |
|
| 35 | - use Traits\ResponseTrait; |
|
| 36 | - use Traits\PluginTrait; |
|
| 37 | - use Traits\CallableTrait; |
|
| 38 | - use Traits\ViewTrait; |
|
| 39 | - use Traits\UtilTrait; |
|
| 40 | - use Traits\MetadataTrait; |
|
| 41 | - use Traits\DiAutoTrait; |
|
| 32 | +use Traits\AppTrait; |
|
| 33 | +use Traits\PsrTrait; |
|
| 34 | +use Traits\RequestTrait; |
|
| 35 | +use Traits\ResponseTrait; |
|
| 36 | +use Traits\PluginTrait; |
|
| 37 | +use Traits\CallableTrait; |
|
| 38 | +use Traits\ViewTrait; |
|
| 39 | +use Traits\UtilTrait; |
|
| 40 | +use Traits\MetadataTrait; |
|
| 41 | +use Traits\DiAutoTrait; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * The library Dependency Injection Container |
| 45 | 45 | * |
| 46 | 46 | * @var PimpleContainer |
| 47 | 47 | */ |
| 48 | - private $xLibContainer; |
|
| 48 | +private $xLibContainer; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * The application or framework Dependency Injection Container |
| 52 | 52 | * |
| 53 | 53 | * @var ContainerInterface |
| 54 | 54 | */ |
| 55 | - private $xAppContainer = null; |
|
| 55 | +private $xAppContainer = null; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * The class constructor |
| 59 | 59 | */ |
| 60 | - public function __construct() |
|
| 61 | - { |
|
| 62 | - $this->xLibContainer = new PimpleContainer(); |
|
| 60 | +public function __construct() |
|
| 61 | +{ |
|
| 62 | +$this->xLibContainer = new PimpleContainer(); |
|
| 63 | 63 | |
| 64 | - $this->val(Container::class, $this); |
|
| 64 | +$this->val(Container::class, $this); |
|
| 65 | 65 | |
| 66 | - // Register the null logger by default |
|
| 67 | - $this->setLogger(new NullLogger()); |
|
| 66 | +// Register the null logger by default |
|
| 67 | +$this->setLogger(new NullLogger()); |
|
| 68 | 68 | |
| 69 | - // Template directory |
|
| 70 | - $sTemplateDir = realpath(__DIR__ . '/../../templates'); |
|
| 71 | - $this->val('jaxon.core.dir.template', $sTemplateDir); |
|
| 69 | +// Template directory |
|
| 70 | +$sTemplateDir = realpath(__DIR__ . '/../../templates'); |
|
| 71 | +$this->val('jaxon.core.dir.template', $sTemplateDir); |
|
| 72 | 72 | |
| 73 | - // Translation directory |
|
| 74 | - $sTranslationDir = realpath(__DIR__ . '/../../translations'); |
|
| 75 | - $this->val('jaxon.core.dir.translation', $sTranslationDir); |
|
| 73 | +// Translation directory |
|
| 74 | +$sTranslationDir = realpath(__DIR__ . '/../../translations'); |
|
| 75 | +$this->val('jaxon.core.dir.translation', $sTranslationDir); |
|
| 76 | 76 | |
| 77 | - $this->registerAll(); |
|
| 78 | - $this->setEventHandlers(); |
|
| 79 | - } |
|
| 77 | +$this->registerAll(); |
|
| 78 | +$this->setEventHandlers(); |
|
| 79 | +} |
|
| 80 | 80 | |
| 81 | - /** |
|
| 81 | +/** |
|
| 82 | 82 | * The container for parameters |
| 83 | 83 | * |
| 84 | 84 | * @return Container |
| 85 | 85 | */ |
| 86 | - protected function cn(): Container |
|
| 87 | - { |
|
| 88 | - return $this; |
|
| 89 | - } |
|
| 86 | +protected function cn(): Container |
|
| 87 | +{ |
|
| 88 | +return $this; |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * Register the values into the container |
| 93 | 93 | * |
| 94 | 94 | * @return void |
| 95 | 95 | */ |
| 96 | - private function registerAll() |
|
| 97 | - { |
|
| 98 | - $this->registerApp(); |
|
| 99 | - $this->registerPsr(); |
|
| 100 | - $this->registerRequests(); |
|
| 101 | - $this->registerResponses(); |
|
| 102 | - $this->registerPlugins(); |
|
| 103 | - $this->registerCallables(); |
|
| 104 | - $this->registerViews(); |
|
| 105 | - $this->registerUtils(); |
|
| 106 | - $this->registerMetadataReader(); |
|
| 107 | - } |
|
| 96 | +private function registerAll() |
|
| 97 | +{ |
|
| 98 | +$this->registerApp(); |
|
| 99 | +$this->registerPsr(); |
|
| 100 | +$this->registerRequests(); |
|
| 101 | +$this->registerResponses(); |
|
| 102 | +$this->registerPlugins(); |
|
| 103 | +$this->registerCallables(); |
|
| 104 | +$this->registerViews(); |
|
| 105 | +$this->registerUtils(); |
|
| 106 | +$this->registerMetadataReader(); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Set the logger |
| 111 | 111 | * |
| 112 | 112 | * @param LoggerInterface|Closure $xLogger |
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function setLogger(LoggerInterface|Closure $xLogger) |
|
| 117 | - { |
|
| 118 | - is_a($xLogger, LoggerInterface::class) ? |
|
| 119 | - $this->val(LoggerInterface::class, $xLogger) : |
|
| 120 | - $this->set(LoggerInterface::class, $xLogger); |
|
| 121 | - } |
|
| 116 | +public function setLogger(LoggerInterface|Closure $xLogger) |
|
| 117 | +{ |
|
| 118 | +is_a($xLogger, LoggerInterface::class) ? |
|
| 119 | +$this->val(LoggerInterface::class, $xLogger) : |
|
| 120 | +$this->set(LoggerInterface::class, $xLogger); |
|
| 121 | +} |
|
| 122 | 122 | |
| 123 | - /** |
|
| 123 | +/** |
|
| 124 | 124 | * Get the logger |
| 125 | 125 | * |
| 126 | 126 | * @return LoggerInterface |
| 127 | 127 | */ |
| 128 | - public function getLogger(): LoggerInterface |
|
| 129 | - { |
|
| 130 | - return $this->get(LoggerInterface::class); |
|
| 131 | - } |
|
| 128 | +public function getLogger(): LoggerInterface |
|
| 129 | +{ |
|
| 130 | +return $this->get(LoggerInterface::class); |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Set the container provided by the integrated framework |
| 135 | 135 | * |
| 136 | 136 | * @param ContainerInterface $xContainer The container implementation |
| 137 | 137 | * |
| 138 | 138 | * @return void |
| 139 | 139 | */ |
| 140 | - public function setContainer(ContainerInterface $xContainer) |
|
| 141 | - { |
|
| 142 | - $this->xAppContainer = $xContainer; |
|
| 143 | - } |
|
| 140 | +public function setContainer(ContainerInterface $xContainer) |
|
| 141 | +{ |
|
| 142 | +$this->xAppContainer = $xContainer; |
|
| 143 | +} |
|
| 144 | 144 | |
| 145 | - /** |
|
| 145 | +/** |
|
| 146 | 146 | * Check if a class is defined in the container |
| 147 | 147 | * |
| 148 | 148 | * @param string $sClass The full class name |
| 149 | 149 | * |
| 150 | 150 | * @return bool |
| 151 | 151 | */ |
| 152 | - public function h(string $sClass): bool |
|
| 153 | - { |
|
| 154 | - return $this->xLibContainer->offsetExists($sClass); |
|
| 155 | - } |
|
| 152 | +public function h(string $sClass): bool |
|
| 153 | +{ |
|
| 154 | +return $this->xLibContainer->offsetExists($sClass); |
|
| 155 | +} |
|
| 156 | 156 | |
| 157 | - /** |
|
| 157 | +/** |
|
| 158 | 158 | * Check if a class is defined in the container |
| 159 | 159 | * |
| 160 | 160 | * @param string $sClass The full class name |
| 161 | 161 | * |
| 162 | 162 | * @return bool |
| 163 | 163 | */ |
| 164 | - public function has(string $sClass): bool |
|
| 165 | - { |
|
| 166 | - return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 167 | - true : $this->xLibContainer->offsetExists($sClass); |
|
| 168 | - } |
|
| 164 | +public function has(string $sClass): bool |
|
| 165 | +{ |
|
| 166 | +return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 167 | +true : $this->xLibContainer->offsetExists($sClass); |
|
| 168 | +} |
|
| 169 | 169 | |
| 170 | - /** |
|
| 170 | +/** |
|
| 171 | 171 | * Get a class instance |
| 172 | 172 | * |
| 173 | 173 | * @template T |
@@ -175,12 +175,12 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return T |
| 177 | 177 | */ |
| 178 | - public function g(string $sClass): mixed |
|
| 179 | - { |
|
| 180 | - return $this->xLibContainer->offsetGet($sClass); |
|
| 181 | - } |
|
| 178 | +public function g(string $sClass): mixed |
|
| 179 | +{ |
|
| 180 | +return $this->xLibContainer->offsetGet($sClass); |
|
| 181 | +} |
|
| 182 | 182 | |
| 183 | - /** |
|
| 183 | +/** |
|
| 184 | 184 | * Get a class instance |
| 185 | 185 | * |
| 186 | 186 | * @template T |
@@ -189,24 +189,24 @@ discard block |
||
| 189 | 189 | * @return T |
| 190 | 190 | * @throws SetupException |
| 191 | 191 | */ |
| 192 | - public function get(string $sClass): mixed |
|
| 193 | - { |
|
| 194 | - try |
|
| 195 | - { |
|
| 196 | - return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 197 | - $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
|
| 198 | - } |
|
| 199 | - catch(Throwable $e) |
|
| 200 | - { |
|
| 201 | - $xLogger = $this->g(LoggerInterface::class); |
|
| 202 | - $xTranslator = $this->g(Translator::class); |
|
| 203 | - $sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
|
| 204 | - $xLogger->error($e->getMessage(), ['message' => $sMessage]); |
|
| 205 | - throw new SetupException($sMessage); |
|
| 206 | - } |
|
| 207 | - } |
|
| 192 | +public function get(string $sClass): mixed |
|
| 193 | +{ |
|
| 194 | +try |
|
| 195 | +{ |
|
| 196 | +return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
|
| 197 | + $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
|
| 198 | +} |
|
| 199 | +catch(Throwable $e) |
|
| 200 | +{ |
|
| 201 | +$xLogger = $this->g(LoggerInterface::class); |
|
| 202 | +$xTranslator = $this->g(Translator::class); |
|
| 203 | +$sMessage = $e->getMessage() . ': ' . $xTranslator->trans('errors.class.container', ['name' => $sClass]); |
|
| 204 | +$xLogger->error($e->getMessage(), ['message' => $sMessage]); |
|
| 205 | +throw new SetupException($sMessage); |
|
| 206 | +} |
|
| 207 | +} |
|
| 208 | 208 | |
| 209 | - /** |
|
| 209 | +/** |
|
| 210 | 210 | * Save a closure in the container |
| 211 | 211 | * |
| 212 | 212 | * @param string|class-string $sClass The full class name |
@@ -215,15 +215,15 @@ discard block |
||
| 215 | 215 | * |
| 216 | 216 | * @return void |
| 217 | 217 | */ |
| 218 | - public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true) |
|
| 219 | - { |
|
| 220 | - // Wrap the user closure into a new closure, so it can take this container as a parameter. |
|
| 221 | - $xClosure = fn() => $xClosure($this); |
|
| 222 | - $this->xLibContainer->offsetSet($sClass, $bIsSingleton ? |
|
| 223 | - $xClosure : $this->xLibContainer->factory($xClosure)); |
|
| 224 | - } |
|
| 218 | +public function set(string $sClass, Closure $xClosure, bool $bIsSingleton = true) |
|
| 219 | +{ |
|
| 220 | +// Wrap the user closure into a new closure, so it can take this container as a parameter. |
|
| 221 | +$xClosure = fn() => $xClosure($this); |
|
| 222 | +$this->xLibContainer->offsetSet($sClass, $bIsSingleton ? |
|
| 223 | +$xClosure : $this->xLibContainer->factory($xClosure)); |
|
| 224 | +} |
|
| 225 | 225 | |
| 226 | - /** |
|
| 226 | +/** |
|
| 227 | 227 | * Save a value in the container |
| 228 | 228 | * |
| 229 | 229 | * @param string|class-string $sKey The key |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return void |
| 233 | 233 | */ |
| 234 | - public function val(string $sKey, $xValue) |
|
| 235 | - { |
|
| 236 | - $this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 237 | - } |
|
| 234 | +public function val(string $sKey, $xValue) |
|
| 235 | +{ |
|
| 236 | +$this->xLibContainer->offsetSet($sKey, $xValue); |
|
| 237 | +} |
|
| 238 | 238 | |
| 239 | - /** |
|
| 239 | +/** |
|
| 240 | 240 | * Set an alias in the container |
| 241 | 241 | * |
| 242 | 242 | * @param string|class-string $sAlias The alias name |
@@ -244,32 +244,32 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @return void |
| 246 | 246 | */ |
| 247 | - public function alias(string $sAlias, string $sClass) |
|
| 248 | - { |
|
| 249 | - $this->set($sAlias, function($di) use ($sClass) { |
|
| 250 | - return $di->get($sClass); |
|
| 251 | - }); |
|
| 252 | - } |
|
| 247 | +public function alias(string $sAlias, string $sClass) |
|
| 248 | +{ |
|
| 249 | +$this->set($sAlias, function($di) use ($sClass) { |
|
| 250 | +return $di->get($sClass); |
|
| 251 | +}); |
|
| 252 | +} |
|
| 253 | 253 | |
| 254 | - /** |
|
| 254 | +/** |
|
| 255 | 255 | * Get the session manager |
| 256 | 256 | * |
| 257 | 257 | * @return SessionInterface|null |
| 258 | 258 | */ |
| 259 | - public function getSessionManager(): ?SessionInterface |
|
| 260 | - { |
|
| 261 | - return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null; |
|
| 262 | - } |
|
| 259 | +public function getSessionManager(): ?SessionInterface |
|
| 260 | +{ |
|
| 261 | +return $this->h(SessionInterface::class) ? $this->g(SessionInterface::class) : null; |
|
| 262 | +} |
|
| 263 | 263 | |
| 264 | - /** |
|
| 264 | +/** |
|
| 265 | 265 | * Set the session manager |
| 266 | 266 | * |
| 267 | 267 | * @param Closure $xClosure A closure to create the session manager instance |
| 268 | 268 | * |
| 269 | 269 | * @return void |
| 270 | 270 | */ |
| 271 | - public function setSessionManager(Closure $xClosure) |
|
| 272 | - { |
|
| 273 | - $this->set(SessionInterface::class, $xClosure); |
|
| 274 | - } |
|
| 271 | +public function setSessionManager(Closure $xClosure) |
|
| 272 | +{ |
|
| 273 | +$this->set(SessionInterface::class, $xClosure); |
|
| 274 | +} |
|
| 275 | 275 | } |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | public function setLogger(LoggerInterface|Closure $xLogger) |
| 117 | 117 | { |
| 118 | 118 | is_a($xLogger, LoggerInterface::class) ? |
| 119 | - $this->val(LoggerInterface::class, $xLogger) : |
|
| 120 | - $this->set(LoggerInterface::class, $xLogger); |
|
| 119 | + $this->val(LoggerInterface::class, $xLogger) : $this->set(LoggerInterface::class, $xLogger); |
|
| 121 | 120 | } |
| 122 | 121 | |
| 123 | 122 | /** |
@@ -196,7 +195,7 @@ discard block |
||
| 196 | 195 | return $this->xAppContainer != null && $this->xAppContainer->has($sClass) ? |
| 197 | 196 | $this->xAppContainer->get($sClass) : $this->xLibContainer->offsetGet($sClass); |
| 198 | 197 | } |
| 199 | - catch(Throwable $e) |
|
| 198 | + catch (Throwable $e) |
|
| 200 | 199 | { |
| 201 | 200 | $xLogger = $this->g(LoggerInterface::class); |
| 202 | 201 | $xTranslator = $this->g(Translator::class); |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | class Logger |
| 9 | 9 | { |
| 10 | - use LoggerTrait; |
|
| 10 | +use LoggerTrait; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * @param LoggerInterface $logger |
| 14 | 14 | */ |
| 15 | - public function __construct(private LoggerInterface $logger) |
|
| 16 | - {} |
|
| 15 | +public function __construct(private LoggerInterface $logger) |
|
| 16 | +{} |
|
| 17 | 17 | |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * Logs with an arbitrary level. |
| 20 | 20 | * |
| 21 | 21 | * @param mixed $level |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @return void |
| 26 | 26 | */ |
| 27 | - public function log($level, string|\Stringable $message, array $context = []) |
|
| 28 | - { |
|
| 29 | - $this->logger->log($level, $message, $context); |
|
| 30 | - } |
|
| 27 | +public function log($level, string|\Stringable $message, array $context = []) |
|
| 28 | +{ |
|
| 29 | +$this->logger->log($level, $message, $context); |
|
| 30 | +} |
|
| 31 | 31 | } |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | class ConfigManager |
| 31 | 31 | { |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @var Config |
| 34 | 34 | */ |
| 35 | - protected $xLibConfig; |
|
| 35 | +protected $xLibConfig; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @var Config |
| 39 | 39 | */ |
| 40 | - protected $xAppConfig; |
|
| 40 | +protected $xAppConfig; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * The constructor |
| 44 | 44 | * |
| 45 | 45 | * @param array $aDefaultOptions |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | * @param ConfigSetter $xConfigSetter |
| 49 | 49 | * @param ConfigEventManager $xEventManager |
| 50 | 50 | */ |
| 51 | - public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | - private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | - private ConfigEventManager $xEventManager) |
|
| 54 | - { |
|
| 55 | - $this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | - $this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | - } |
|
| 51 | +public function __construct(array $aDefaultOptions, private Translator $xTranslator, |
|
| 52 | +private ConfigReader $xConfigReader, private ConfigSetter $xConfigSetter, |
|
| 53 | +private ConfigEventManager $xEventManager) |
|
| 54 | +{ |
|
| 55 | +$this->xLibConfig = $xConfigSetter->newConfig($aDefaultOptions); |
|
| 56 | +$this->xAppConfig = $xConfigSetter->newConfig(); |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * Read a config file |
| 61 | 61 | * |
| 62 | 62 | * @param string $sConfigFile |
@@ -64,35 +64,35 @@ discard block |
||
| 64 | 64 | * @return array |
| 65 | 65 | * @throws SetupException |
| 66 | 66 | */ |
| 67 | - public function read(string $sConfigFile): array |
|
| 68 | - { |
|
| 69 | - try |
|
| 70 | - { |
|
| 71 | - return $this->xConfigReader->read($sConfigFile); |
|
| 72 | - } |
|
| 73 | - catch(YamlExtension $e) |
|
| 74 | - { |
|
| 75 | - $sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | - throw new SetupException($sMessage); |
|
| 77 | - } |
|
| 78 | - catch(FileExtension $e) |
|
| 79 | - { |
|
| 80 | - $sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | - throw new SetupException($sMessage); |
|
| 82 | - } |
|
| 83 | - catch(FileAccess $e) |
|
| 84 | - { |
|
| 85 | - $sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | - throw new SetupException($sMessage); |
|
| 87 | - } |
|
| 88 | - catch(FileContent $e) |
|
| 89 | - { |
|
| 90 | - $sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | - throw new SetupException($sMessage); |
|
| 92 | - } |
|
| 93 | - } |
|
| 67 | +public function read(string $sConfigFile): array |
|
| 68 | +{ |
|
| 69 | +try |
|
| 70 | +{ |
|
| 71 | +return $this->xConfigReader->read($sConfigFile); |
|
| 72 | +} |
|
| 73 | +catch(YamlExtension $e) |
|
| 74 | +{ |
|
| 75 | +$sMessage = $this->xTranslator->trans('errors.yaml.install'); |
|
| 76 | +throw new SetupException($sMessage); |
|
| 77 | +} |
|
| 78 | +catch(FileExtension $e) |
|
| 79 | +{ |
|
| 80 | +$sMessage = $this->xTranslator->trans('errors.file.extension', ['path' => $sConfigFile]); |
|
| 81 | +throw new SetupException($sMessage); |
|
| 82 | +} |
|
| 83 | +catch(FileAccess $e) |
|
| 84 | +{ |
|
| 85 | +$sMessage = $this->xTranslator->trans('errors.file.access', ['path' => $sConfigFile]); |
|
| 86 | +throw new SetupException($sMessage); |
|
| 87 | +} |
|
| 88 | +catch(FileContent $e) |
|
| 89 | +{ |
|
| 90 | +$sMessage = $this->xTranslator->trans('errors.file.content', ['path' => $sConfigFile]); |
|
| 91 | +throw new SetupException($sMessage); |
|
| 92 | +} |
|
| 93 | +} |
|
| 94 | 94 | |
| 95 | - /** |
|
| 95 | +/** |
|
| 96 | 96 | * Read options from a config file and set the library config |
| 97 | 97 | * |
| 98 | 98 | * @param string $sConfigFile The full path to the config file |
@@ -101,27 +101,27 @@ discard block |
||
| 101 | 101 | * @return void |
| 102 | 102 | * @throws SetupException |
| 103 | 103 | */ |
| 104 | - public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | - { |
|
| 106 | - try |
|
| 107 | - { |
|
| 108 | - // Read the options and save in the config. |
|
| 109 | - $this->xLibConfig = $this->xConfigSetter |
|
| 110 | - ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | - // Call the config change listeners. |
|
| 112 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | - } |
|
| 114 | - catch(DataDepth $e) |
|
| 115 | - { |
|
| 116 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | - 'key' => $e->sPrefix, |
|
| 118 | - 'depth' => $e->nDepth, |
|
| 119 | - ]); |
|
| 120 | - throw new SetupException($sMessage); |
|
| 121 | - } |
|
| 122 | - } |
|
| 104 | +public function load(string $sConfigFile, string $sConfigSection = ''): void |
|
| 105 | +{ |
|
| 106 | +try |
|
| 107 | +{ |
|
| 108 | +// Read the options and save in the config. |
|
| 109 | +$this->xLibConfig = $this->xConfigSetter |
|
| 110 | + ->setOptions($this->xLibConfig, $this->read($sConfigFile), $sConfigSection); |
|
| 111 | +// Call the config change listeners. |
|
| 112 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 113 | +} |
|
| 114 | +catch(DataDepth $e) |
|
| 115 | +{ |
|
| 116 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 117 | + 'key' => $e->sPrefix, |
|
| 118 | + 'depth' => $e->nDepth, |
|
| 119 | +]); |
|
| 120 | +throw new SetupException($sMessage); |
|
| 121 | +} |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * Set the config options of the library |
| 126 | 126 | * |
| 127 | 127 | * @param array $aOptions |
@@ -130,27 +130,27 @@ discard block |
||
| 130 | 130 | * @return bool |
| 131 | 131 | * @throws SetupException |
| 132 | 132 | */ |
| 133 | - public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | - { |
|
| 135 | - try |
|
| 136 | - { |
|
| 137 | - $this->xLibConfig = $this->xConfigSetter |
|
| 138 | - ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | - // Call the config change listeners. |
|
| 140 | - $this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | - return $this->xLibConfig->changed(); |
|
| 142 | - } |
|
| 143 | - catch(DataDepth $e) |
|
| 144 | - { |
|
| 145 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | - 'key' => $e->sPrefix, |
|
| 147 | - 'depth' => $e->nDepth, |
|
| 148 | - ]); |
|
| 149 | - throw new SetupException($sMessage); |
|
| 150 | - } |
|
| 151 | - } |
|
| 133 | +public function setOptions(array $aOptions, string $sNamePrefix = ''): bool |
|
| 134 | +{ |
|
| 135 | +try |
|
| 136 | +{ |
|
| 137 | +$this->xLibConfig = $this->xConfigSetter |
|
| 138 | + ->setOptions($this->xLibConfig, $aOptions, $sNamePrefix); |
|
| 139 | +// Call the config change listeners. |
|
| 140 | +$this->xEventManager->libConfigChanged($this->xLibConfig, ''); |
|
| 141 | +return $this->xLibConfig->changed(); |
|
| 142 | +} |
|
| 143 | +catch(DataDepth $e) |
|
| 144 | +{ |
|
| 145 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 146 | + 'key' => $e->sPrefix, |
|
| 147 | + 'depth' => $e->nDepth, |
|
| 148 | +]); |
|
| 149 | +throw new SetupException($sMessage); |
|
| 150 | +} |
|
| 151 | +} |
|
| 152 | 152 | |
| 153 | - /** |
|
| 153 | +/** |
|
| 154 | 154 | * Set the value of a config option |
| 155 | 155 | * |
| 156 | 156 | * @param string $sName The option name |
@@ -158,15 +158,15 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return void |
| 160 | 160 | */ |
| 161 | - public function setOption(string $sName, $xValue): void |
|
| 162 | - { |
|
| 163 | - $this->xLibConfig = $this->xConfigSetter |
|
| 164 | - ->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | - // Call the config change listeners. |
|
| 166 | - $this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | - } |
|
| 161 | +public function setOption(string $sName, $xValue): void |
|
| 162 | +{ |
|
| 163 | +$this->xLibConfig = $this->xConfigSetter |
|
| 164 | +->setOption($this->xLibConfig, $sName, $xValue); |
|
| 165 | +// Call the config change listeners. |
|
| 166 | +$this->xEventManager->libConfigChanged($this->xLibConfig, $sName); |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * Get the value of a config option |
| 171 | 171 | * |
| 172 | 172 | * @param string $sName The option name |
@@ -174,36 +174,36 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * @return mixed |
| 176 | 176 | */ |
| 177 | - public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | - { |
|
| 179 | - return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | - } |
|
| 177 | +public function getOption(string $sName, $xDefault = null): mixed |
|
| 178 | +{ |
|
| 179 | +return $this->xLibConfig->getOption($sName, $xDefault); |
|
| 180 | +} |
|
| 181 | 181 | |
| 182 | - /** |
|
| 182 | +/** |
|
| 183 | 183 | * Check the presence of a config option |
| 184 | 184 | * |
| 185 | 185 | * @param string $sName The option name |
| 186 | 186 | * |
| 187 | 187 | * @return bool |
| 188 | 188 | */ |
| 189 | - public function hasOption(string $sName): bool |
|
| 190 | - { |
|
| 191 | - return $this->xLibConfig->hasOption($sName); |
|
| 192 | - } |
|
| 189 | +public function hasOption(string $sName): bool |
|
| 190 | +{ |
|
| 191 | +return $this->xLibConfig->hasOption($sName); |
|
| 192 | +} |
|
| 193 | 193 | |
| 194 | - /** |
|
| 194 | +/** |
|
| 195 | 195 | * Get the names of the options matching a given prefix |
| 196 | 196 | * |
| 197 | 197 | * @param string $sPrefix The prefix to match |
| 198 | 198 | * |
| 199 | 199 | * @return array |
| 200 | 200 | */ |
| 201 | - public function getOptionNames(string $sPrefix): array |
|
| 202 | - { |
|
| 203 | - return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | - } |
|
| 201 | +public function getOptionNames(string $sPrefix): array |
|
| 202 | +{ |
|
| 203 | +return $this->xLibConfig->getOptionNames($sPrefix); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Set the value of a config option |
| 208 | 208 | * |
| 209 | 209 | * @param string $sName The option name |
@@ -211,25 +211,25 @@ discard block |
||
| 211 | 211 | * |
| 212 | 212 | * @return void |
| 213 | 213 | */ |
| 214 | - public function setAppOption(string $sName, $xValue): void |
|
| 215 | - { |
|
| 216 | - $this->xAppConfig = $this->xConfigSetter |
|
| 217 | - ->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | - // Call the config change listeners. |
|
| 219 | - $this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | - } |
|
| 214 | +public function setAppOption(string $sName, $xValue): void |
|
| 215 | +{ |
|
| 216 | +$this->xAppConfig = $this->xConfigSetter |
|
| 217 | +->setOption($this->xAppConfig, $sName, $xValue); |
|
| 218 | +// Call the config change listeners. |
|
| 219 | +$this->xEventManager->appConfigChanged($this->xAppConfig, $sName); |
|
| 220 | +} |
|
| 221 | 221 | |
| 222 | - /** |
|
| 222 | +/** |
|
| 223 | 223 | * Get the application config |
| 224 | 224 | * |
| 225 | 225 | * @return Config |
| 226 | 226 | */ |
| 227 | - public function getAppConfig(): Config |
|
| 228 | - { |
|
| 229 | - return $this->xAppConfig; |
|
| 230 | - } |
|
| 227 | +public function getAppConfig(): Config |
|
| 228 | +{ |
|
| 229 | +return $this->xAppConfig; |
|
| 230 | +} |
|
| 231 | 231 | |
| 232 | - /** |
|
| 232 | +/** |
|
| 233 | 233 | * Set the application config options |
| 234 | 234 | * |
| 235 | 235 | * @param array $aAppOptions |
@@ -237,27 +237,27 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return bool |
| 239 | 239 | */ |
| 240 | - public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | - { |
|
| 242 | - try |
|
| 243 | - { |
|
| 244 | - $this->xAppConfig = $this->xConfigSetter |
|
| 245 | - ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | - // Call the config change listeners. |
|
| 247 | - $this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | - return $this->xAppConfig->changed(); |
|
| 249 | - } |
|
| 250 | - catch(DataDepth $e) |
|
| 251 | - { |
|
| 252 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | - 'key' => $e->sPrefix, |
|
| 254 | - 'depth' => $e->nDepth, |
|
| 255 | - ]); |
|
| 256 | - throw new SetupException($sMessage); |
|
| 257 | - } |
|
| 258 | - } |
|
| 240 | +public function setAppOptions(array $aAppOptions, string $sNamePrefix = ''): bool |
|
| 241 | +{ |
|
| 242 | +try |
|
| 243 | +{ |
|
| 244 | +$this->xAppConfig = $this->xConfigSetter |
|
| 245 | + ->setOptions($this->xAppConfig, $aAppOptions, $sNamePrefix); |
|
| 246 | +// Call the config change listeners. |
|
| 247 | +$this->xEventManager->appConfigChanged($this->xAppConfig, ''); |
|
| 248 | +return $this->xAppConfig->changed(); |
|
| 249 | +} |
|
| 250 | +catch(DataDepth $e) |
|
| 251 | +{ |
|
| 252 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 253 | + 'key' => $e->sPrefix, |
|
| 254 | + 'depth' => $e->nDepth, |
|
| 255 | +]); |
|
| 256 | +throw new SetupException($sMessage); |
|
| 257 | +} |
|
| 258 | +} |
|
| 259 | 259 | |
| 260 | - /** |
|
| 260 | +/** |
|
| 261 | 261 | * Get the value of an application config option |
| 262 | 262 | * |
| 263 | 263 | * @param string $sName The option name |
@@ -265,24 +265,24 @@ discard block |
||
| 265 | 265 | * |
| 266 | 266 | * @return mixed |
| 267 | 267 | */ |
| 268 | - public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | - { |
|
| 270 | - return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | - } |
|
| 268 | +public function getAppOption(string $sName, $xDefault = null): mixed |
|
| 269 | +{ |
|
| 270 | +return $this->xAppConfig->getOption($sName, $xDefault); |
|
| 271 | +} |
|
| 272 | 272 | |
| 273 | - /** |
|
| 273 | +/** |
|
| 274 | 274 | * Check the presence of an application config option |
| 275 | 275 | * |
| 276 | 276 | * @param string $sName The option name |
| 277 | 277 | * |
| 278 | 278 | * @return bool |
| 279 | 279 | */ |
| 280 | - public function hasAppOption(string $sName): bool |
|
| 281 | - { |
|
| 282 | - return $this->xAppConfig->hasOption($sName); |
|
| 283 | - } |
|
| 280 | +public function hasAppOption(string $sName): bool |
|
| 281 | +{ |
|
| 282 | +return $this->xAppConfig->hasOption($sName); |
|
| 283 | +} |
|
| 284 | 284 | |
| 285 | - /** |
|
| 285 | +/** |
|
| 286 | 286 | * Create a new the config object |
| 287 | 287 | * |
| 288 | 288 | * @param array $aOptions The options array |
@@ -291,64 +291,64 @@ discard block |
||
| 291 | 291 | * @return Config |
| 292 | 292 | * @throws SetupException |
| 293 | 293 | */ |
| 294 | - public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | - { |
|
| 296 | - try |
|
| 297 | - { |
|
| 298 | - return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | - } |
|
| 300 | - catch(DataDepth $e) |
|
| 301 | - { |
|
| 302 | - $sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | - 'key' => $e->sPrefix, |
|
| 304 | - 'depth' => $e->nDepth, |
|
| 305 | - ]); |
|
| 306 | - throw new SetupException($sMessage); |
|
| 307 | - } |
|
| 308 | - } |
|
| 294 | +public function newConfig(array $aOptions = [], string $sNamePrefix = ''): Config |
|
| 295 | +{ |
|
| 296 | +try |
|
| 297 | +{ |
|
| 298 | +return $this->xConfigSetter->newConfig($aOptions, $sNamePrefix); |
|
| 299 | +} |
|
| 300 | +catch(DataDepth $e) |
|
| 301 | +{ |
|
| 302 | +$sMessage = $this->xTranslator->trans('errors.data.depth', [ |
|
| 303 | + 'key' => $e->sPrefix, |
|
| 304 | + 'depth' => $e->nDepth, |
|
| 305 | +]); |
|
| 306 | +throw new SetupException($sMessage); |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | |
| 310 | - /** |
|
| 310 | +/** |
|
| 311 | 311 | * Check if the remote logging is enabled |
| 312 | 312 | * |
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | - public function loggingEnabled(): bool |
|
| 316 | - { |
|
| 317 | - return $this->getAppOption('options.logging.enabled', false); |
|
| 318 | - } |
|
| 315 | +public function loggingEnabled(): bool |
|
| 316 | +{ |
|
| 317 | +return $this->getAppOption('options.logging.enabled', false); |
|
| 318 | +} |
|
| 319 | 319 | |
| 320 | - /** |
|
| 320 | +/** |
|
| 321 | 321 | * @param string $sClassName |
| 322 | 322 | * |
| 323 | 323 | * @return void |
| 324 | 324 | */ |
| 325 | - public function addLibEventListener(string $sClassName): void |
|
| 326 | - { |
|
| 327 | - $this->xEventManager->addLibConfigListener($sClassName); |
|
| 328 | - } |
|
| 325 | +public function addLibEventListener(string $sClassName): void |
|
| 326 | +{ |
|
| 327 | +$this->xEventManager->addLibConfigListener($sClassName); |
|
| 328 | +} |
|
| 329 | 329 | |
| 330 | - /** |
|
| 330 | +/** |
|
| 331 | 331 | * @param string $sClassName |
| 332 | 332 | * |
| 333 | 333 | * @return void |
| 334 | 334 | */ |
| 335 | - public function addAppEventListener(string $sClassName): void |
|
| 336 | - { |
|
| 337 | - $this->xEventManager->addAppConfigListener($sClassName); |
|
| 338 | - } |
|
| 335 | +public function addAppEventListener(string $sClassName): void |
|
| 336 | +{ |
|
| 337 | +$this->xEventManager->addAppConfigListener($sClassName); |
|
| 338 | +} |
|
| 339 | 339 | |
| 340 | - /** |
|
| 340 | +/** |
|
| 341 | 341 | * Make the helpers functions available in the global namespace. |
| 342 | 342 | * |
| 343 | 343 | * @param bool $bForce |
| 344 | 344 | * |
| 345 | 345 | * @return void |
| 346 | 346 | */ |
| 347 | - public function globals(bool $bForce = false): void |
|
| 348 | - { |
|
| 349 | - if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 350 | - { |
|
| 351 | - require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 352 | - } |
|
| 353 | - } |
|
| 347 | +public function globals(bool $bForce = false): void |
|
| 348 | +{ |
|
| 349 | +if($bForce || $this->getAppOption('helpers.global', true)) |
|
| 350 | +{ |
|
| 351 | +require_once dirname(__DIR__, 2) . '/globals.php'; |
|
| 352 | +} |
|
| 353 | +} |
|
| 354 | 354 | } |
@@ -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 | } |
@@ -23,58 +23,58 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | class Bootstrap |
| 25 | 25 | { |
| 26 | - /** |
|
| 26 | +/** |
|
| 27 | 27 | * The library options |
| 28 | 28 | * |
| 29 | 29 | * @var array |
| 30 | 30 | */ |
| 31 | - private $aLibOptions = []; |
|
| 31 | +private $aLibOptions = []; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * The application options |
| 35 | 35 | * |
| 36 | 36 | * @var array |
| 37 | 37 | */ |
| 38 | - private $aAppOptions = []; |
|
| 38 | +private $aAppOptions = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * The class constructor |
| 42 | 42 | * |
| 43 | 43 | * @param ConfigManager $xConfigManager |
| 44 | 44 | * @param PackageManager $xPackageManager |
| 45 | 45 | * @param CallbackManager $xCallbackManager |
| 46 | 46 | */ |
| 47 | - public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | - private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | - {} |
|
| 47 | +public function __construct(private ConfigManager $xConfigManager, |
|
| 48 | +private PackageManager $xPackageManager, private CallbackManager $xCallbackManager) |
|
| 49 | +{} |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * Set the library options |
| 53 | 53 | * |
| 54 | 54 | * @param array $aLibOptions The library options |
| 55 | 55 | * |
| 56 | 56 | * @return Bootstrap |
| 57 | 57 | */ |
| 58 | - public function lib(array $aLibOptions): Bootstrap |
|
| 59 | - { |
|
| 60 | - $this->aLibOptions = $aLibOptions; |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 58 | +public function lib(array $aLibOptions): Bootstrap |
|
| 59 | +{ |
|
| 60 | +$this->aLibOptions = $aLibOptions; |
|
| 61 | +return $this; |
|
| 62 | +} |
|
| 63 | 63 | |
| 64 | - /** |
|
| 64 | +/** |
|
| 65 | 65 | * Set the applications options |
| 66 | 66 | * |
| 67 | 67 | * @param array $aAppOptions The application options |
| 68 | 68 | * |
| 69 | 69 | * @return Bootstrap |
| 70 | 70 | */ |
| 71 | - public function app(array $aAppOptions): Bootstrap |
|
| 72 | - { |
|
| 73 | - $this->aAppOptions = $aAppOptions; |
|
| 74 | - return $this; |
|
| 75 | - } |
|
| 71 | +public function app(array $aAppOptions): Bootstrap |
|
| 72 | +{ |
|
| 73 | +$this->aAppOptions = $aAppOptions; |
|
| 74 | +return $this; |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * Set the javascript asset |
| 79 | 79 | * |
| 80 | 80 | * @param bool $bExport Whether to export the js code in a file |
@@ -84,75 +84,75 @@ discard block |
||
| 84 | 84 | * |
| 85 | 85 | * @return Bootstrap |
| 86 | 86 | */ |
| 87 | - public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | - { |
|
| 89 | - // Jaxon library settings |
|
| 90 | - $aJsOptions = [ |
|
| 91 | - 'export' => $bExport, |
|
| 92 | - 'minify' => $bMinify, |
|
| 93 | - ]; |
|
| 94 | - if($sUri !== '') |
|
| 95 | - { |
|
| 96 | - $aJsOptions['uri'] = $sUri; |
|
| 97 | - } |
|
| 98 | - if($sDir !== '') |
|
| 99 | - { |
|
| 100 | - $aJsOptions['dir'] = $sDir; |
|
| 101 | - } |
|
| 102 | - $this->xConfigManager->setOptions($aJsOptions, 'js.app'); |
|
| 103 | - return $this; |
|
| 104 | - } |
|
| 87 | +public function asset(bool $bExport, bool $bMinify, string $sUri = '', string $sDir = ''): Bootstrap |
|
| 88 | +{ |
|
| 89 | +// Jaxon library settings |
|
| 90 | +$aJsOptions = [ |
|
| 91 | +'export' => $bExport, |
|
| 92 | +'minify' => $bMinify, |
|
| 93 | +]; |
|
| 94 | +if($sUri !== '') |
|
| 95 | +{ |
|
| 96 | +$aJsOptions['uri'] = $sUri; |
|
| 97 | +} |
|
| 98 | +if($sDir !== '') |
|
| 99 | +{ |
|
| 100 | +$aJsOptions['dir'] = $sDir; |
|
| 101 | +} |
|
| 102 | +$this->xConfigManager->setOptions($aJsOptions, 'js.app'); |
|
| 103 | +return $this; |
|
| 104 | +} |
|
| 105 | 105 | |
| 106 | - /** |
|
| 106 | +/** |
|
| 107 | 107 | * Set the Jaxon application options. |
| 108 | 108 | * |
| 109 | 109 | * @return void |
| 110 | 110 | * @throws SetupException |
| 111 | 111 | */ |
| 112 | - private function setupApp(): void |
|
| 113 | - { |
|
| 114 | - // Save the app config. |
|
| 115 | - $this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 116 | - // Register user functions and classes |
|
| 117 | - $this->xPackageManager->registerFromConfig(); |
|
| 118 | - } |
|
| 112 | +private function setupApp(): void |
|
| 113 | +{ |
|
| 114 | +// Save the app config. |
|
| 115 | +$this->xConfigManager->setAppOptions($this->aAppOptions); |
|
| 116 | +// Register user functions and classes |
|
| 117 | +$this->xPackageManager->registerFromConfig(); |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - /** |
|
| 120 | +/** |
|
| 121 | 121 | * Wraps the module/package/bundle setup method. |
| 122 | 122 | * |
| 123 | 123 | * @return void |
| 124 | 124 | * @throws SetupException |
| 125 | 125 | */ |
| 126 | - public function setup(): void |
|
| 127 | - { |
|
| 128 | - // Prevent the Jaxon library from sending the response or exiting |
|
| 129 | - $this->xConfigManager->setOptions([ |
|
| 130 | - 'response' => [ |
|
| 131 | - 'send' => false, |
|
| 132 | - ], |
|
| 133 | - 'process' => [ |
|
| 134 | - 'exit' => false, |
|
| 135 | - ], |
|
| 136 | - ], 'core'); |
|
| 137 | - // Setup the lib config options. |
|
| 138 | - $this->xConfigManager->setOptions($this->aLibOptions); |
|
| 126 | +public function setup(): void |
|
| 127 | +{ |
|
| 128 | +// Prevent the Jaxon library from sending the response or exiting |
|
| 129 | +$this->xConfigManager->setOptions([ |
|
| 130 | +'response' => [ |
|
| 131 | + 'send' => false, |
|
| 132 | +], |
|
| 133 | +'process' => [ |
|
| 134 | + 'exit' => false, |
|
| 135 | +], |
|
| 136 | +], 'core'); |
|
| 137 | +// Setup the lib config options. |
|
| 138 | +$this->xConfigManager->setOptions($this->aLibOptions); |
|
| 139 | 139 | |
| 140 | - // Setup the app. |
|
| 141 | - $this->setupApp(); |
|
| 142 | - } |
|
| 140 | +// Setup the app. |
|
| 141 | +$this->setupApp(); |
|
| 142 | +} |
|
| 143 | 143 | |
| 144 | - /** |
|
| 144 | +/** |
|
| 145 | 145 | * These callbacks are called once, after the library is initialized. |
| 146 | 146 | * |
| 147 | 147 | * @return void |
| 148 | 148 | */ |
| 149 | - public function onBoot(): void |
|
| 150 | - { |
|
| 151 | - // Popping the callbacks makes each of them to be called once. |
|
| 152 | - $aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 153 | - foreach($aBootCallbacks as $aBootCallback) |
|
| 154 | - { |
|
| 155 | - call_user_func($aBootCallback); |
|
| 156 | - } |
|
| 157 | - } |
|
| 149 | +public function onBoot(): void |
|
| 150 | +{ |
|
| 151 | +// Popping the callbacks makes each of them to be called once. |
|
| 152 | +$aBootCallbacks = $this->xCallbackManager->popBootCallbacks(); |
|
| 153 | +foreach($aBootCallbacks as $aBootCallback) |
|
| 154 | +{ |
|
| 155 | +call_user_func($aBootCallback); |
|
| 156 | +} |
|
| 157 | +} |
|
| 158 | 158 | } |