@@ -50,8 +50,7 @@ |
||
| 50 | 50 | public function rq(string $sClassName = ''): ?JxnCall |
| 51 | 51 | { |
| 52 | 52 | $sClassName = trim($sClassName); |
| 53 | - return $sClassName === '' ? $this->cdi->getFunctionRequestFactory() : |
|
| 54 | - $this->cdi->getComponentRequestFactory($sClassName); |
|
| 53 | + return $sClassName === '' ? $this->cdi->getFunctionRequestFactory() : $this->cdi->getComponentRequestFactory($sClassName); |
|
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | /** |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | */ |
| 139 | 139 | public function val(string $sKey, $xValue) |
| 140 | 140 | { |
| 141 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 141 | + $this->xContainer->offsetSet($sKey, $xValue); |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -169,13 +169,13 @@ discard block |
||
| 169 | 169 | try |
| 170 | 170 | { |
| 171 | 171 | // Make sure the registered class exists |
| 172 | - if(isset($aOptions['include'])) |
|
| 172 | + if (isset($aOptions['include'])) |
|
| 173 | 173 | { |
| 174 | 174 | require_once $aOptions['include']; |
| 175 | 175 | } |
| 176 | 176 | $xReflectionClass = new ReflectionClass($sClassName); |
| 177 | 177 | // Check if the class is registrable |
| 178 | - if(!$xReflectionClass->isInstantiable()) |
|
| 178 | + if (!$xReflectionClass->isInstantiable()) |
|
| 179 | 179 | { |
| 180 | 180 | return; |
| 181 | 181 | } |
@@ -185,12 +185,12 @@ discard block |
||
| 185 | 185 | $sClassKey = $this->getReflectionClassKey($sClassName); |
| 186 | 186 | $this->val($sClassKey, $xReflectionClass); |
| 187 | 187 | // Register the user class, but only if the user didn't already. |
| 188 | - if(!$this->has($sClassName)) |
|
| 188 | + if (!$this->has($sClassName)) |
|
| 189 | 189 | { |
| 190 | 190 | $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - catch(ReflectionException $e) |
|
| 193 | + catch (ReflectionException $e) |
|
| 194 | 194 | { |
| 195 | 195 | throw new SetupException($this->cn()->g(Translator::class) |
| 196 | 196 | ->trans('errors.class.invalid', ['name' => $sClassName])); |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $sComponentObject = $this->getCallableObjectKey($sClassName); |
| 214 | 214 | // Prevent duplication. It's important not to use the class name here. |
| 215 | - if($this->has($sComponentObject)) |
|
| 215 | + if ($this->has($sComponentObject)) |
|
| 216 | 216 | { |
| 217 | 217 | return $sClassName; |
| 218 | 218 | } |
@@ -238,14 +238,14 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | // Initialize the user class instance |
| 240 | 240 | $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
| 241 | - if($xClassInstance instanceof AbstractComponent) |
|
| 241 | + if ($xClassInstance instanceof AbstractComponent) |
|
| 242 | 242 | { |
| 243 | 243 | $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
| 244 | 244 | $xHelper->xTarget = $this->xTarget; |
| 245 | 245 | |
| 246 | 246 | // Call the protected "initComponent()" method of the Component class. |
| 247 | 247 | $cSetter = function($di, $xHelper) { |
| 248 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 248 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 249 | 249 | }; |
| 250 | 250 | $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
| 251 | 251 | call_user_func($cSetter, $this->di, $xHelper); |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | /** @var CallableObject */ |
| 261 | 261 | $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
| 262 | 262 | $xCallableObject->setDiClassAttributes($xClassInstance); |
| 263 | - if($this->xTarget !== null) |
|
| 263 | + if ($this->xTarget !== null) |
|
| 264 | 264 | { |
| 265 | 265 | $sMethodName = $this->xTarget->getMethodName(); |
| 266 | 266 | $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
@@ -323,17 +323,17 @@ discard block |
||
| 323 | 323 | public function getComponentRequestFactory(string $sClassName): ?JxnCall |
| 324 | 324 | { |
| 325 | 325 | $sClassName = trim($sClassName, " \t"); |
| 326 | - if($sClassName === '') |
|
| 326 | + if ($sClassName === '') |
|
| 327 | 327 | { |
| 328 | 328 | return null; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
| 332 | - if(!$this->has($sFactoryKey)) |
|
| 332 | + if (!$this->has($sFactoryKey)) |
|
| 333 | 333 | { |
| 334 | 334 | $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
| 335 | 335 | $sComponentId = str_replace('\\', '.', $sClassName); |
| 336 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 336 | + if (!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 337 | 337 | { |
| 338 | 338 | return null; |
| 339 | 339 | } |
@@ -189,8 +189,7 @@ |
||
| 189 | 189 | { |
| 190 | 190 | $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
| 191 | 191 | } |
| 192 | - } |
|
| 193 | - catch(ReflectionException $e) |
|
| 192 | + } catch(ReflectionException $e) |
|
| 194 | 193 | { |
| 195 | 194 | throw new SetupException($this->cn()->g(Translator::class) |
| 196 | 195 | ->trans('errors.class.invalid', ['name' => $sClassName])); |
@@ -39,73 +39,73 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | class ComponentContainer |
| 41 | 41 | { |
| 42 | - use Traits\DiAutoTrait; |
|
| 43 | - use Traits\ComponentTrait; |
|
| 42 | +use Traits\DiAutoTrait; |
|
| 43 | +use Traits\ComponentTrait; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * The Dependency Injection Container for registered classes |
| 47 | 47 | * |
| 48 | 48 | * @var PimpleContainer |
| 49 | 49 | */ |
| 50 | - private $xContainer; |
|
| 50 | +private $xContainer; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * This will be set only when getting the object targetted by the ajax request. |
| 54 | 54 | * |
| 55 | 55 | * @var Target|null |
| 56 | 56 | */ |
| 57 | - private $xTarget = null; |
|
| 57 | +private $xTarget = null; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * The class constructor |
| 61 | 61 | * |
| 62 | 62 | * @param Container $di |
| 63 | 63 | */ |
| 64 | - public function __construct(private Container $di) |
|
| 65 | - { |
|
| 66 | - $this->xContainer = new PimpleContainer(); |
|
| 67 | - $this->val(ComponentContainer::class, $this); |
|
| 68 | - |
|
| 69 | - // Register the call factory for registered functions |
|
| 70 | - $this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | - new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | - ->getOption('core.prefix.function', ''))); |
|
| 73 | - |
|
| 74 | - // Register the pagination component, but do not export to js. |
|
| 75 | - $this->saveComponent(Pagination::class, [ |
|
| 76 | - 'excluded' => true, |
|
| 77 | - 'separator' => '.', |
|
| 78 | - // The namespace has the same name as the Component class. |
|
| 79 | - 'namespace' => Component::class, |
|
| 80 | - ]); |
|
| 81 | - |
|
| 82 | - $this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 83 | - $this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 84 | - } |
|
| 64 | +public function __construct(private Container $di) |
|
| 65 | +{ |
|
| 66 | +$this->xContainer = new PimpleContainer(); |
|
| 67 | +$this->val(ComponentContainer::class, $this); |
|
| 68 | + |
|
| 69 | +// Register the call factory for registered functions |
|
| 70 | +$this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | +new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | + ->getOption('core.prefix.function', ''))); |
|
| 73 | + |
|
| 74 | +// Register the pagination component, but do not export to js. |
|
| 75 | +$this->saveComponent(Pagination::class, [ |
|
| 76 | +'excluded' => true, |
|
| 77 | +'separator' => '.', |
|
| 78 | +// The namespace has the same name as the Component class. |
|
| 79 | +'namespace' => Component::class, |
|
| 80 | +]); |
|
| 81 | + |
|
| 82 | +$this->setComponentPublicMethods('node', NodeComponent::class, ['item', 'html']); |
|
| 83 | +$this->setComponentPublicMethods('func', FuncComponent::class, ['paginator']); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * The container for parameters |
| 88 | 88 | * |
| 89 | 89 | * @return Container |
| 90 | 90 | */ |
| 91 | - protected function cn(): Container |
|
| 92 | - { |
|
| 93 | - return $this->di; |
|
| 94 | - } |
|
| 91 | +protected function cn(): Container |
|
| 92 | +{ |
|
| 93 | +return $this->di; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Check if a class is defined in the container |
| 98 | 98 | * |
| 99 | 99 | * @param class-string $sClass The full class name |
| 100 | 100 | * |
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | - public function has(string $sClass): bool |
|
| 104 | - { |
|
| 105 | - return $this->xContainer->offsetExists($sClass); |
|
| 106 | - } |
|
| 103 | +public function has(string $sClass): bool |
|
| 104 | +{ |
|
| 105 | +return $this->xContainer->offsetExists($sClass); |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Save a closure in the container |
| 110 | 110 | * |
| 111 | 111 | * @param class-string $sClass The full class name |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function set(string $sClass, Closure $xClosure) |
|
| 117 | - { |
|
| 118 | - $this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | - } |
|
| 116 | +public function set(string $sClass, Closure $xClosure) |
|
| 117 | +{ |
|
| 118 | +$this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Save a value in the container |
| 123 | 123 | * |
| 124 | 124 | * @param string|class-string $sKey The key |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function val(string $sKey, $xValue) |
|
| 130 | - { |
|
| 131 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | - } |
|
| 129 | +public function val(string $sKey, $xValue) |
|
| 130 | +{ |
|
| 131 | +$this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * Get a class instance |
| 136 | 136 | * |
| 137 | 137 | * @template T |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return T |
| 141 | 141 | */ |
| 142 | - public function get(string $sClass) |
|
| 143 | - { |
|
| 144 | - return $this->xContainer->offsetGet($sClass); |
|
| 145 | - } |
|
| 142 | +public function get(string $sClass) |
|
| 143 | +{ |
|
| 144 | +return $this->xContainer->offsetGet($sClass); |
|
| 145 | +} |
|
| 146 | 146 | |
| 147 | - /** |
|
| 147 | +/** |
|
| 148 | 148 | * Get a component when one of its method needs to be called |
| 149 | 149 | * |
| 150 | 150 | * @template T |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return T|null |
| 155 | 155 | */ |
| 156 | - public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | - { |
|
| 158 | - // Set the target only when getting the object targetted by the ajax request. |
|
| 159 | - $this->xTarget = $xTarget; |
|
| 160 | - $xComponent = $this->get($sClassName); |
|
| 161 | - $this->xTarget = null; |
|
| 156 | +public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | +{ |
|
| 158 | +// Set the target only when getting the object targetted by the ajax request. |
|
| 159 | +$this->xTarget = $xTarget; |
|
| 160 | +$xComponent = $this->get($sClassName); |
|
| 161 | +$this->xTarget = null; |
|
| 162 | 162 | |
| 163 | - return $xComponent; |
|
| 164 | - } |
|
| 163 | +return $xComponent; |
|
| 164 | +} |
|
| 165 | 165 | |
| 166 | - /** |
|
| 166 | +/** |
|
| 167 | 167 | * Register a component and its options |
| 168 | 168 | * |
| 169 | 169 | * @param class-string $sClassName The class name |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | - { |
|
| 176 | - try |
|
| 177 | - { |
|
| 178 | - // Make sure the registered class exists |
|
| 179 | - if(isset($aOptions['include'])) |
|
| 180 | - { |
|
| 181 | - require_once $aOptions['include']; |
|
| 182 | - } |
|
| 183 | - $xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | - // Check if the class is registrable |
|
| 185 | - if(!$xReflectionClass->isInstantiable()) |
|
| 186 | - { |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $this->_saveClassOptions($sClassName, $aOptions); |
|
| 191 | - |
|
| 192 | - $sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | - $this->val($sClassKey, $xReflectionClass); |
|
| 194 | - // Register the user class, but only if the user didn't already. |
|
| 195 | - if(!$this->has($sClassName)) |
|
| 196 | - { |
|
| 197 | - $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - catch(ReflectionException $e) |
|
| 201 | - { |
|
| 202 | - throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | - ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | - } |
|
| 205 | - } |
|
| 174 | +public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | +{ |
|
| 176 | +try |
|
| 177 | +{ |
|
| 178 | +// Make sure the registered class exists |
|
| 179 | +if(isset($aOptions['include'])) |
|
| 180 | +{ |
|
| 181 | + require_once $aOptions['include']; |
|
| 182 | +} |
|
| 183 | +$xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | +// Check if the class is registrable |
|
| 185 | +if(!$xReflectionClass->isInstantiable()) |
|
| 186 | +{ |
|
| 187 | + return; |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +$this->_saveClassOptions($sClassName, $aOptions); |
|
| 206 | 191 | |
| 207 | - /** |
|
| 192 | +$sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | +$this->val($sClassKey, $xReflectionClass); |
|
| 194 | +// Register the user class, but only if the user didn't already. |
|
| 195 | +if(!$this->has($sClassName)) |
|
| 196 | +{ |
|
| 197 | + $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | +} |
|
| 199 | +} |
|
| 200 | +catch(ReflectionException $e) |
|
| 201 | +{ |
|
| 202 | +throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | + ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | +} |
|
| 205 | +} |
|
| 206 | + |
|
| 207 | +/** |
|
| 208 | 208 | * Register a component |
| 209 | 209 | * |
| 210 | 210 | * @param string $sComponentId The component name |
@@ -212,74 +212,74 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | * @throws SetupException |
| 214 | 214 | */ |
| 215 | - private function _registerComponent(string $sComponentId): string |
|
| 216 | - { |
|
| 217 | - // Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | - $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | - |
|
| 220 | - $sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | - // Prevent duplication. It's important not to use the class name here. |
|
| 222 | - if($this->has($sComponentObject)) |
|
| 223 | - { |
|
| 224 | - return $sClassName; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Register the helper class |
|
| 228 | - $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | - $xFactory = $this->di->getCallFactory(); |
|
| 230 | - return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | - $xFactory, $this->di->getViewRenderer(), |
|
| 232 | - $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | - $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | - }); |
|
| 235 | - |
|
| 236 | - $this->discoverComponent($sClassName); |
|
| 237 | - |
|
| 238 | - // Register the callable object |
|
| 239 | - $this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | - $aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | - $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | - $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | - return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | - }); |
|
| 245 | - |
|
| 246 | - // Initialize the user class instance |
|
| 247 | - $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | - if($xClassInstance instanceof AbstractComponent) |
|
| 249 | - { |
|
| 250 | - $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | - $xHelper->xTarget = $this->xTarget; |
|
| 252 | - |
|
| 253 | - // Call the protected "initComponent()" method of the Component class. |
|
| 254 | - $cSetter = function($di, $xHelper) { |
|
| 255 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | - }; |
|
| 257 | - $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | - call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Run the callbacks for class initialisation |
|
| 262 | - $this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | - |
|
| 264 | - // Set attributes from the DI container. |
|
| 265 | - // The class level DI options are set on any component. |
|
| 266 | - // The method level DI options are set only on the targetted component. |
|
| 267 | - /** @var CallableObject */ |
|
| 268 | - $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | - $xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | - if($this->xTarget !== null) |
|
| 271 | - { |
|
| 272 | - $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | - $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $xClassInstance; |
|
| 277 | - }); |
|
| 278 | - |
|
| 279 | - return $sClassName; |
|
| 280 | - } |
|
| 215 | +private function _registerComponent(string $sComponentId): string |
|
| 216 | +{ |
|
| 217 | +// Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | +$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | + |
|
| 220 | +$sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | +// Prevent duplication. It's important not to use the class name here. |
|
| 222 | +if($this->has($sComponentObject)) |
|
| 223 | +{ |
|
| 224 | +return $sClassName; |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +// Register the helper class |
|
| 228 | +$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | +$xFactory = $this->di->getCallFactory(); |
|
| 230 | +return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | + $xFactory, $this->di->getViewRenderer(), |
|
| 232 | + $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | + $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | +}); |
|
| 235 | + |
|
| 236 | +$this->discoverComponent($sClassName); |
|
| 237 | + |
|
| 238 | +// Register the callable object |
|
| 239 | +$this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | +$aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | +$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | +$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | +return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | +}); |
|
| 245 | + |
|
| 246 | +// Initialize the user class instance |
|
| 247 | +$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | +if($xClassInstance instanceof AbstractComponent) |
|
| 249 | +{ |
|
| 250 | + $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | + $xHelper->xTarget = $this->xTarget; |
|
| 252 | + |
|
| 253 | + // Call the protected "initComponent()" method of the Component class. |
|
| 254 | + $cSetter = function($di, $xHelper) { |
|
| 255 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | + }; |
|
| 257 | + $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | + call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +// Run the callbacks for class initialisation |
|
| 262 | +$this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | + |
|
| 264 | +// Set attributes from the DI container. |
|
| 265 | +// The class level DI options are set on any component. |
|
| 266 | +// The method level DI options are set only on the targetted component. |
|
| 267 | +/** @var CallableObject */ |
|
| 268 | +$xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | +$xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | +if($this->xTarget !== null) |
|
| 271 | +{ |
|
| 272 | + $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | + $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +return $xClassInstance; |
|
| 277 | +}); |
|
| 281 | 278 | |
| 282 | - /** |
|
| 279 | +return $sClassName; |
|
| 280 | +} |
|
| 281 | + |
|
| 282 | +/** |
|
| 283 | 283 | * Get the callable object for a given class |
| 284 | 284 | * The callable object is registered if it is not already in the DI. |
| 285 | 285 | * |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | * @return CallableObject|null |
| 289 | 289 | * @throws SetupException |
| 290 | 290 | */ |
| 291 | - public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | - { |
|
| 293 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | - return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | - } |
|
| 291 | +public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | +{ |
|
| 293 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | +return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | +} |
|
| 296 | 296 | |
| 297 | - /** |
|
| 297 | +/** |
|
| 298 | 298 | * Get an instance of a component by name |
| 299 | 299 | * |
| 300 | 300 | * @template T |
@@ -303,53 +303,53 @@ discard block |
||
| 303 | 303 | * @return T|null |
| 304 | 304 | * @throws SetupException |
| 305 | 305 | */ |
| 306 | - public function makeComponent(string $sClassName): mixed |
|
| 307 | - { |
|
| 308 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | - return $this->get($sClassName); |
|
| 311 | - } |
|
| 306 | +public function makeComponent(string $sClassName): mixed |
|
| 307 | +{ |
|
| 308 | +$sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | +return $this->get($sClassName); |
|
| 311 | +} |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | +/** |
|
| 314 | 314 | * Get a factory for a call to a registered function. |
| 315 | 315 | * |
| 316 | 316 | * @return JxnCall |
| 317 | 317 | */ |
| 318 | - public function getFunctionRequestFactory(): JxnCall |
|
| 319 | - { |
|
| 320 | - return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | - } |
|
| 318 | +public function getFunctionRequestFactory(): JxnCall |
|
| 319 | +{ |
|
| 320 | +return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | +} |
|
| 322 | 322 | |
| 323 | - /** |
|
| 323 | +/** |
|
| 324 | 324 | * Get a factory for a call to a registered component. |
| 325 | 325 | * |
| 326 | 326 | * @param class-string $sClassName |
| 327 | 327 | * |
| 328 | 328 | * @return JxnCall|null |
| 329 | 329 | */ |
| 330 | - public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 330 | +public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 331 | +{ |
|
| 332 | +$sClassName = trim($sClassName, " \t"); |
|
| 333 | +if($sClassName === '') |
|
| 334 | +{ |
|
| 335 | +return null; |
|
| 336 | +} |
|
| 337 | + |
|
| 338 | +$sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | +if(!$this->has($sFactoryKey)) |
|
| 340 | +{ |
|
| 341 | +$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | + $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | + if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 331 | 344 | { |
| 332 | - $sClassName = trim($sClassName, " \t"); |
|
| 333 | - if($sClassName === '') |
|
| 334 | - { |
|
| 335 | - return null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | - if(!$this->has($sFactoryKey)) |
|
| 340 | - { |
|
| 341 | - $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 344 | - { |
|
| 345 | - return null; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | - $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | - return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | - }); |
|
| 352 | - } |
|
| 353 | - return $this->get($sFactoryKey); |
|
| 345 | + return null; |
|
| 354 | 346 | } |
| 347 | + |
|
| 348 | + $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | + $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | + return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | +}); |
|
| 352 | +} |
|
| 353 | +return $this->get($sFactoryKey); |
|
| 354 | +} |
|
| 355 | 355 | } |
@@ -51,12 +51,12 @@ |
||
| 51 | 51 | $sMetadataVar = '$xMetadata'; |
| 52 | 52 | $sDataVar = '$xData'; |
| 53 | 53 | $aCalls = ["$sMetadataVar = new " . Metadata::class . '();']; |
| 54 | - foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 54 | + foreach ($xMetadata->getAttributes() as $sType => $aValues) |
|
| 55 | 55 | { |
| 56 | - foreach($aValues as $sMethod => $xData) |
|
| 56 | + foreach ($aValues as $sMethod => $xData) |
|
| 57 | 57 | { |
| 58 | 58 | $aCalls[] = "$sDataVar = {$sMetadataVar}->{$sType}('{$sMethod}');"; |
| 59 | - foreach($xData->encode($sDataVar) as $sCall) |
|
| 59 | + foreach ($xData->encode($sDataVar) as $sCall) |
|
| 60 | 60 | { |
| 61 | 61 | $aCalls[] = $sCall; |
| 62 | 62 | } |
@@ -28,60 +28,60 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | class MetadataCache |
| 30 | 30 | { |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @param string $sCacheDir |
| 33 | 33 | */ |
| 34 | - public function __construct(private string $sCacheDir) |
|
| 35 | - {} |
|
| 34 | +public function __construct(private string $sCacheDir) |
|
| 35 | +{} |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * @param string $sClass |
| 39 | 39 | * |
| 40 | 40 | * @return string |
| 41 | 41 | */ |
| 42 | - private function filepath(string $sClass): string |
|
| 43 | - { |
|
| 44 | - $sFilename = trim(str_replace(['\\', '.'], DIRECTORY_SEPARATOR, |
|
| 45 | - strtolower($sClass)), DIRECTORY_SEPARATOR); |
|
| 46 | - return rtrim($this->sCacheDir, "/\\") . DIRECTORY_SEPARATOR . |
|
| 47 | - "metadata" . DIRECTORY_SEPARATOR . "{$sFilename}.php"; |
|
| 48 | - } |
|
| 42 | +private function filepath(string $sClass): string |
|
| 43 | +{ |
|
| 44 | +$sFilename = trim(str_replace(['\\', '.'], DIRECTORY_SEPARATOR, |
|
| 45 | +strtolower($sClass)), DIRECTORY_SEPARATOR); |
|
| 46 | +return rtrim($this->sCacheDir, "/\\") . DIRECTORY_SEPARATOR . |
|
| 47 | +"metadata" . DIRECTORY_SEPARATOR . "{$sFilename}.php"; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * Generate the PHP code to create a metadata object. |
| 52 | 52 | * |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - private function encode(Metadata $xMetadata): array |
|
| 55 | +private function encode(Metadata $xMetadata): array |
|
| 56 | +{ |
|
| 57 | +$sMetadataVar = '$xMetadata'; |
|
| 58 | +$sDataVar = '$xData'; |
|
| 59 | +$aCalls = ["$sMetadataVar = new " . Metadata::class . '();']; |
|
| 60 | +foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 61 | +{ |
|
| 62 | +foreach($aValues as $sMethod => $xData) |
|
| 63 | +{ |
|
| 64 | + $aCalls[] = "$sDataVar = {$sMetadataVar}->{$sType}('{$sMethod}');"; |
|
| 65 | + foreach($xData->encode($sDataVar) as $sCall) |
|
| 56 | 66 | { |
| 57 | - $sMetadataVar = '$xMetadata'; |
|
| 58 | - $sDataVar = '$xData'; |
|
| 59 | - $aCalls = ["$sMetadataVar = new " . Metadata::class . '();']; |
|
| 60 | - foreach($xMetadata->getAttributes() as $sType => $aValues) |
|
| 61 | - { |
|
| 62 | - foreach($aValues as $sMethod => $xData) |
|
| 63 | - { |
|
| 64 | - $aCalls[] = "$sDataVar = {$sMetadataVar}->{$sType}('{$sMethod}');"; |
|
| 65 | - foreach($xData->encode($sDataVar) as $sCall) |
|
| 66 | - { |
|
| 67 | - $aCalls[] = $sCall; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - $aCalls[] = "return $sMetadataVar;"; |
|
| 72 | - return $aCalls; |
|
| 67 | + $aCalls[] = $sCall; |
|
| 73 | 68 | } |
| 69 | +} |
|
| 70 | +} |
|
| 71 | +$aCalls[] = "return $sMetadataVar;"; |
|
| 72 | +return $aCalls; |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @param string $sClass |
| 77 | 77 | * @param Metadata $xMetadata |
| 78 | 78 | * |
| 79 | 79 | * @return void |
| 80 | 80 | */ |
| 81 | - public function save(string $sClass, Metadata $xMetadata): void |
|
| 82 | - { |
|
| 83 | - $sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 84 | - $sPhpCode = <<<CODE |
|
| 81 | +public function save(string $sClass, Metadata $xMetadata): void |
|
| 82 | +{ |
|
| 83 | +$sDataCode = implode("\n ", $this->encode($xMetadata)); |
|
| 84 | +$sPhpCode = <<<CODE |
|
| 85 | 85 | <?php |
| 86 | 86 | |
| 87 | 87 | return function() { |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | 91 | CODE; |
| 92 | - // Recursively create the directories. |
|
| 93 | - $sPath = $this->filepath($sClass); |
|
| 94 | - @mkdir(dirname($sPath), 0755, true); |
|
| 95 | - file_put_contents($sPath, $sPhpCode); |
|
| 96 | - } |
|
| 92 | +// Recursively create the directories. |
|
| 93 | +$sPath = $this->filepath($sClass); |
|
| 94 | +@mkdir(dirname($sPath), 0755, true); |
|
| 95 | +file_put_contents($sPath, $sPhpCode); |
|
| 96 | +} |
|
| 97 | 97 | |
| 98 | - /** |
|
| 98 | +/** |
|
| 99 | 99 | * @param string $sClass |
| 100 | 100 | * |
| 101 | 101 | * @return Metadata|null |
| 102 | 102 | */ |
| 103 | - public function read(string $sClass): ?Metadata |
|
| 104 | - { |
|
| 105 | - $sPath = $this->filepath($sClass); |
|
| 106 | - $fCreator = file_exists($sPath) ? require $sPath : null; |
|
| 107 | - return $fCreator instanceof Closure ? $fCreator() : null; |
|
| 108 | - } |
|
| 103 | +public function read(string $sClass): ?Metadata |
|
| 104 | +{ |
|
| 105 | +$sPath = $this->filepath($sClass); |
|
| 106 | +$fCreator = file_exists($sPath) ? require $sPath : null; |
|
| 107 | +return $fCreator instanceof Closure ? $fCreator() : null; |
|
| 108 | +} |
|
| 109 | 109 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | protected function validateAttr(string $sAttr): void |
| 53 | 53 | { |
| 54 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 54 | + if (preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 55 | 55 | { |
| 56 | 56 | return; |
| 57 | 57 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | protected function validateClass(string $sClass): void |
| 67 | 67 | { |
| 68 | - if(preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 68 | + if (preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 69 | 69 | { |
| 70 | 70 | return; |
| 71 | 71 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | public function encode(string $sVarName): array |
| 93 | 93 | { |
| 94 | 94 | $aCalls = []; |
| 95 | - foreach($this->aProperties as $sAttr => $sClass) |
|
| 95 | + foreach ($this->aProperties as $sAttr => $sClass) |
|
| 96 | 96 | { |
| 97 | 97 | $aCalls[] = "{$sVarName}->addValue('$sAttr', '" . addslashes($sClass) . "');"; |
| 98 | 98 | } |
@@ -21,81 +21,81 @@ |
||
| 21 | 21 | |
| 22 | 22 | class ContainerData extends AbstractData |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * The properties to get from the container |
| 26 | 26 | * |
| 27 | 27 | * @var array |
| 28 | 28 | */ |
| 29 | - protected $aProperties = []; |
|
| 29 | +protected $aProperties = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | - public function getName(): string |
|
| 35 | - { |
|
| 36 | - return '__di'; |
|
| 37 | - } |
|
| 34 | +public function getName(): string |
|
| 35 | +{ |
|
| 36 | +return '__di'; |
|
| 37 | +} |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @return mixed |
| 41 | 41 | */ |
| 42 | - public function getValue(): mixed |
|
| 43 | - { |
|
| 44 | - return $this->aProperties; |
|
| 45 | - } |
|
| 42 | +public function getValue(): mixed |
|
| 43 | +{ |
|
| 44 | +return $this->aProperties; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @param string $sAttr |
| 49 | 49 | * |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - protected function validateAttr(string $sAttr): void |
|
| 53 | - { |
|
| 54 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 55 | - { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - throw new SetupException("$sAttr is not a valid \"attr\" value for di"); |
|
| 59 | - } |
|
| 52 | +protected function validateAttr(string $sAttr): void |
|
| 53 | +{ |
|
| 54 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sAttr) > 0) |
|
| 55 | +{ |
|
| 56 | +return; |
|
| 57 | +} |
|
| 58 | +throw new SetupException("$sAttr is not a valid \"attr\" value for di"); |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @param string $sClass |
| 63 | 63 | * |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - protected function validateClass(string $sClass): void |
|
| 67 | - { |
|
| 68 | - if(preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 69 | - { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - throw new SetupException("$sClass is not a valid \"class\" value for di"); |
|
| 73 | - } |
|
| 66 | +protected function validateClass(string $sClass): void |
|
| 67 | +{ |
|
| 68 | +if(preg_match('/^(\\\)?([a-zA-Z][a-zA-Z0-9_]*)(\\\[a-zA-Z][a-zA-Z0-9_]*)*$/', $sClass) > 0) |
|
| 69 | +{ |
|
| 70 | +return; |
|
| 71 | +} |
|
| 72 | +throw new SetupException("$sClass is not a valid \"class\" value for di"); |
|
| 73 | +} |
|
| 74 | 74 | |
| 75 | - /** |
|
| 75 | +/** |
|
| 76 | 76 | * @param string $sAttr |
| 77 | 77 | * @param string $sClass |
| 78 | 78 | * |
| 79 | 79 | * @return void |
| 80 | 80 | */ |
| 81 | - public function addValue(string $sAttr, string $sClass): void |
|
| 82 | - { |
|
| 83 | - $this->validateAttr($sAttr); |
|
| 84 | - $this->validateClass($sClass); |
|
| 81 | +public function addValue(string $sAttr, string $sClass): void |
|
| 82 | +{ |
|
| 83 | +$this->validateAttr($sAttr); |
|
| 84 | +$this->validateClass($sClass); |
|
| 85 | 85 | |
| 86 | - $this->aProperties[$sAttr] = $sClass; |
|
| 87 | - } |
|
| 86 | +$this->aProperties[$sAttr] = $sClass; |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * @inheritDoc |
| 91 | 91 | */ |
| 92 | - public function encode(string $sVarName): array |
|
| 93 | - { |
|
| 94 | - $aCalls = []; |
|
| 95 | - foreach($this->aProperties as $sAttr => $sClass) |
|
| 96 | - { |
|
| 97 | - $aCalls[] = "{$sVarName}->addValue('$sAttr', '" . addslashes($sClass) . "');"; |
|
| 98 | - } |
|
| 99 | - return $aCalls; |
|
| 100 | - } |
|
| 92 | +public function encode(string $sVarName): array |
|
| 93 | +{ |
|
| 94 | +$aCalls = []; |
|
| 95 | +foreach($this->aProperties as $sAttr => $sClass) |
|
| 96 | +{ |
|
| 97 | +$aCalls[] = "{$sVarName}->addValue('$sAttr', '" . addslashes($sClass) . "');"; |
|
| 98 | +} |
|
| 99 | +return $aCalls; |
|
| 100 | +} |
|
| 101 | 101 | } |
@@ -85,8 +85,7 @@ discard block |
||
| 85 | 85 | if(is_string($xOptions)) |
| 86 | 86 | { |
| 87 | 87 | $xOptions = ['include' => $xOptions]; |
| 88 | - } |
|
| 89 | - elseif(!is_array($xOptions)) |
|
| 88 | + } elseif(!is_array($xOptions)) |
|
| 90 | 89 | { |
| 91 | 90 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 92 | 91 | } |
@@ -261,8 +260,7 @@ discard block |
||
| 261 | 260 | |
| 262 | 261 | $sError = 'errors.objects.call'; |
| 263 | 262 | $xCallableObject->call($this->xTarget); |
| 264 | - } |
|
| 265 | - catch(ReflectionException|SetupException $e) |
|
| 263 | + } catch(ReflectionException|SetupException $e) |
|
| 266 | 264 | { |
| 267 | 265 | // Unable to execute the requested class or method |
| 268 | 266 | $this->throwException($e->getMessage(), $sError, $aErrorParams); |
@@ -81,15 +81,15 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function checkOptions(string $sCallable, $xOptions): array |
| 83 | 83 | { |
| 84 | - if(!$this->xValidator->validateClass(trim($sCallable))) |
|
| 84 | + if (!$this->xValidator->validateClass(trim($sCallable))) |
|
| 85 | 85 | { |
| 86 | 86 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 87 | 87 | } |
| 88 | - if(is_string($xOptions)) |
|
| 88 | + if (is_string($xOptions)) |
|
| 89 | 89 | { |
| 90 | 90 | $xOptions = ['include' => $xOptions]; |
| 91 | 91 | } |
| 92 | - elseif(!is_array($xOptions)) |
|
| 92 | + elseif (!is_array($xOptions)) |
|
| 93 | 93 | { |
| 94 | 94 | throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration')); |
| 95 | 95 | } |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | private function addCallable(CallableObject $xCallableObject): void |
| 135 | 135 | { |
| 136 | - if($xCallableObject->excluded()) |
|
| 136 | + if ($xCallableObject->excluded()) |
|
| 137 | 137 | { |
| 138 | 138 | return; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $aCallableObject = &$this->aCallableObjects; |
| 142 | - foreach(explode('.', $xCallableObject->getJsName()) as $sName) |
|
| 142 | + foreach (explode('.', $xCallableObject->getJsName()) as $sName) |
|
| 143 | 143 | { |
| 144 | - if(!isset($aCallableObject['children'][$sName])) |
|
| 144 | + if (!isset($aCallableObject['children'][$sName])) |
|
| 145 | 145 | { |
| 146 | 146 | $aCallableObject['children'][$sName] = []; |
| 147 | 147 | } |
@@ -176,11 +176,10 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $fMethodCallback = fn($aMethod) => $this->renderMethod($sIndent, |
| 178 | 178 | ['sJsClass' => $sJsClass, 'aMethod' => $aMethod]); |
| 179 | - $aMethods = !isset($aCallable['methods']) ? [] : |
|
| 180 | - array_map($fMethodCallback, $aCallable['methods']); |
|
| 179 | + $aMethods = !isset($aCallable['methods']) ? [] : array_map($fMethodCallback, $aCallable['methods']); |
|
| 181 | 180 | |
| 182 | 181 | $aChildren = []; |
| 183 | - foreach($aCallable['children'] ?? [] as $sName => $aChild) |
|
| 182 | + foreach ($aCallable['children'] ?? [] as $sName => $aChild) |
|
| 184 | 183 | { |
| 185 | 184 | $aChildren[] = $this->renderChild("$sName:", "$sJsClass.$sName", |
| 186 | 185 | $aChild, $nRepeat) . ','; |
@@ -221,13 +220,13 @@ discard block |
||
| 221 | 220 | $this->xRegistry->registerAllComponents(); |
| 222 | 221 | |
| 223 | 222 | $this->aCallableObjects = ['children' => []]; |
| 224 | - foreach($this->cdi->getCallableObjects() as $xCallableObject) |
|
| 223 | + foreach ($this->cdi->getCallableObjects() as $xCallableObject) |
|
| 225 | 224 | { |
| 226 | 225 | $this->addCallable($xCallableObject); |
| 227 | 226 | } |
| 228 | 227 | |
| 229 | 228 | $aScripts = []; |
| 230 | - foreach($this->aCallableObjects['children'] as $sJsClass => $aCallable) |
|
| 229 | + foreach ($this->aCallableObjects['children'] as $sJsClass => $aCallable) |
|
| 231 | 230 | { |
| 232 | 231 | $aScripts[] = $this->renderChild("{$this->sPrefix}$sJsClass =", |
| 233 | 232 | $sJsClass, $aCallable) . ';'; |
@@ -283,7 +282,7 @@ discard block |
||
| 283 | 282 | // Will be used to print a translated error message. |
| 284 | 283 | $aErrorParams = ['class' => $sClassName, 'method' => $sMethodName]; |
| 285 | 284 | |
| 286 | - if(!$this->xValidator->validateJsObject($sClassName) || |
|
| 285 | + if (!$this->xValidator->validateJsObject($sClassName) || |
|
| 287 | 286 | !$this->xValidator->validateMethod($sMethodName)) |
| 288 | 287 | { |
| 289 | 288 | // Unable to find the requested object or method |
@@ -297,7 +296,7 @@ discard block |
||
| 297 | 296 | /** @var CallableObject */ |
| 298 | 297 | $xCallableObject = $this->getCallable($sClassName); |
| 299 | 298 | |
| 300 | - if($xCallableObject->excluded($sMethodName)) |
|
| 299 | + if ($xCallableObject->excluded($sMethodName)) |
|
| 301 | 300 | { |
| 302 | 301 | // Unable to find the requested class or method |
| 303 | 302 | $this->throwException('', 'errors.objects.excluded', $aErrorParams); |
@@ -306,7 +305,7 @@ discard block |
||
| 306 | 305 | $sError = 'errors.objects.call'; |
| 307 | 306 | $xCallableObject->call($this->xTarget); |
| 308 | 307 | } |
| 309 | - catch(ReflectionException|SetupException $e) |
|
| 308 | + catch (ReflectionException|SetupException $e) |
|
| 310 | 309 | { |
| 311 | 310 | // Unable to execute the requested class or method |
| 312 | 311 | $this->throwException($e->getMessage(), $sError, $aErrorParams); |
@@ -20,50 +20,50 @@ |
||
| 20 | 20 | |
| 21 | 21 | class InputData |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * @var ReflectionClass |
| 25 | 25 | */ |
| 26 | - private $xReflectionClass; |
|
| 26 | +private $xReflectionClass; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * @param ReflectionClass|string $xClass |
| 30 | 30 | * @param array $aMethods |
| 31 | 31 | * @param array $aProperties |
| 32 | 32 | */ |
| 33 | - public function __construct(ReflectionClass|string $xClass, |
|
| 34 | - private array $aMethods = [], private array $aProperties = []) |
|
| 35 | - { |
|
| 36 | - $this->xReflectionClass = is_string($xClass) ? |
|
| 37 | - new ReflectionClass($xClass) : $xClass; |
|
| 38 | - } |
|
| 33 | +public function __construct(ReflectionClass|string $xClass, |
|
| 34 | +private array $aMethods = [], private array $aProperties = []) |
|
| 35 | +{ |
|
| 36 | +$this->xReflectionClass = is_string($xClass) ? |
|
| 37 | +new ReflectionClass($xClass) : $xClass; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * Get the reflection class |
| 42 | 42 | * |
| 43 | 43 | * @return ReflectionClass |
| 44 | 44 | */ |
| 45 | - public function getReflectionClass(): ReflectionClass |
|
| 46 | - { |
|
| 47 | - return $this->xReflectionClass; |
|
| 48 | - } |
|
| 45 | +public function getReflectionClass(): ReflectionClass |
|
| 46 | +{ |
|
| 47 | +return $this->xReflectionClass; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * The methods to check for metadata |
| 52 | 52 | * |
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | - public function getMethods(): array |
|
| 56 | - { |
|
| 57 | - return $this->aMethods; |
|
| 58 | - } |
|
| 55 | +public function getMethods(): array |
|
| 56 | +{ |
|
| 57 | +return $this->aMethods; |
|
| 58 | +} |
|
| 59 | 59 | |
| 60 | - /** |
|
| 60 | +/** |
|
| 61 | 61 | * The properties to check for metadata |
| 62 | 62 | * |
| 63 | 63 | * @return array |
| 64 | 64 | */ |
| 65 | - public function getProperties(): array |
|
| 66 | - { |
|
| 67 | - return $this->aProperties; |
|
| 68 | - } |
|
| 65 | +public function getProperties(): array |
|
| 66 | +{ |
|
| 67 | +return $this->aProperties; |
|
| 68 | +} |
|
| 69 | 69 | } |
@@ -16,42 +16,42 @@ |
||
| 16 | 16 | |
| 17 | 17 | class ExcludeData extends AbstractData |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var bool |
| 21 | 21 | */ |
| 22 | - private bool $bValue = true; |
|
| 22 | +private bool $bValue = true; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @return string |
| 26 | 26 | */ |
| 27 | - public function getName(): string |
|
| 28 | - { |
|
| 29 | - return 'protected'; |
|
| 30 | - } |
|
| 27 | +public function getName(): string |
|
| 28 | +{ |
|
| 29 | +return 'protected'; |
|
| 30 | +} |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return mixed |
| 34 | 34 | */ |
| 35 | - public function getValue(): mixed |
|
| 36 | - { |
|
| 37 | - return $this->bValue; |
|
| 38 | - } |
|
| 35 | +public function getValue(): mixed |
|
| 36 | +{ |
|
| 37 | +return $this->bValue; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @param bool $bValue |
| 42 | 42 | * |
| 43 | 43 | * @return void |
| 44 | 44 | */ |
| 45 | - public function setValue(bool $bValue): void |
|
| 46 | - { |
|
| 47 | - $this->bValue = $bValue; |
|
| 48 | - } |
|
| 45 | +public function setValue(bool $bValue): void |
|
| 46 | +{ |
|
| 47 | +$this->bValue = $bValue; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * @inheritDoc |
| 52 | 52 | */ |
| 53 | - public function encode(string $sVarName): array |
|
| 54 | - { |
|
| 55 | - return ["{$sVarName}->setValue(" . ($this->bValue ? 'true' : 'false') . ");"]; |
|
| 56 | - } |
|
| 53 | +public function encode(string $sVarName): array |
|
| 54 | +{ |
|
| 55 | +return ["{$sVarName}->setValue(" . ($this->bValue ? 'true' : 'false') . ");"]; |
|
| 56 | +} |
|
| 57 | 57 | } |
@@ -81,8 +81,7 @@ discard block |
||
| 81 | 81 | { |
| 82 | 82 | // Local file system adapter |
| 83 | 83 | $this->registerAdapter('local', function(string $sRootDir, $xOptions) { |
| 84 | - return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) : |
|
| 85 | - new LocalFilesystemAdapter($sRootDir, $xOptions); |
|
| 84 | + return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) : new LocalFilesystemAdapter($sRootDir, $xOptions); |
|
| 86 | 85 | }); |
| 87 | 86 | |
| 88 | 87 | // AWS S3 file system adapter |
@@ -140,7 +139,7 @@ discard block |
||
| 140 | 139 | public function filesystem(string $sField = ''): Filesystem |
| 141 | 140 | { |
| 142 | 141 | $sField = trim($sField); |
| 143 | - if(isset($this->aFilesystems[$sField])) |
|
| 142 | + if (isset($this->aFilesystems[$sField])) |
|
| 144 | 143 | { |
| 145 | 144 | return $this->aFilesystems[$sField]; |
| 146 | 145 | } |
@@ -150,18 +149,18 @@ discard block |
||
| 150 | 149 | $sRootDir = $this->xConfigManager->getOption('upload.default.dir', ''); |
| 151 | 150 | $aOptions = $this->xConfigManager->getOption('upload.default.options'); |
| 152 | 151 | $sConfigKey = "upload.files.$sField"; |
| 153 | - if($sField !== '' && $this->xConfigManager->hasOption($sConfigKey)) |
|
| 152 | + if ($sField !== '' && $this->xConfigManager->hasOption($sConfigKey)) |
|
| 154 | 153 | { |
| 155 | 154 | $sStorage = $this->xConfigManager->getOption("$sConfigKey.storage", $sStorage); |
| 156 | 155 | $sRootDir = $this->xConfigManager->getOption("$sConfigKey.dir", $sRootDir); |
| 157 | 156 | $aOptions = $this->xConfigManager->getOption("$sConfigKey.options", $aOptions); |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | - if(!is_string($sRootDir)) |
|
| 159 | + if (!is_string($sRootDir)) |
|
| 161 | 160 | { |
| 162 | 161 | throw new RequestException($this->xTranslator->trans('errors.upload.dir')); |
| 163 | 162 | } |
| 164 | - if(!isset($this->aAdapters[$sStorage])) |
|
| 163 | + if (!isset($this->aAdapters[$sStorage])) |
|
| 165 | 164 | { |
| 166 | 165 | throw new RequestException($this->xTranslator->trans('errors.upload.adapter')); |
| 167 | 166 | } |
@@ -16,23 +16,23 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Jaxon |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @const string |
| 21 | 21 | */ |
| 22 | - public const VERSION = 'Jaxon 5.x'; |
|
| 22 | +public const VERSION = 'Jaxon 5.x'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @const string |
| 26 | 26 | */ |
| 27 | - public const CALLABLE_CLASS = 'CallableClass'; |
|
| 27 | +public const CALLABLE_CLASS = 'CallableClass'; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @const string |
| 31 | 31 | */ |
| 32 | - public const CALLABLE_DIR = 'CallableDir'; |
|
| 32 | +public const CALLABLE_DIR = 'CallableDir'; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @const string |
| 36 | 36 | */ |
| 37 | - public const CALLABLE_FUNCTION = 'CallableFunction'; |
|
| 37 | +public const CALLABLE_FUNCTION = 'CallableFunction'; |
|
| 38 | 38 | } |