@@ -22,61 +22,61 @@ |
||
| 22 | 22 | |
| 23 | 23 | class CallbackData extends AbstractData |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * The callback js objects |
| 27 | 27 | * |
| 28 | 28 | * @var string |
| 29 | 29 | */ |
| 30 | - protected $aNames = []; |
|
| 30 | +protected $aNames = []; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 32 | +/** |
|
| 33 | 33 | * @return string |
| 34 | 34 | */ |
| 35 | - public function getName(): string |
|
| 36 | - { |
|
| 37 | - return 'callback'; |
|
| 38 | - } |
|
| 35 | +public function getName(): string |
|
| 36 | +{ |
|
| 37 | +return 'callback'; |
|
| 38 | +} |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | +/** |
|
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function getValue(): mixed |
|
| 44 | - { |
|
| 45 | - return array_values($this->aNames); |
|
| 46 | - } |
|
| 43 | +public function getValue(): mixed |
|
| 44 | +{ |
|
| 45 | +return array_values($this->aNames); |
|
| 46 | +} |
|
| 47 | 47 | |
| 48 | - /** |
|
| 48 | +/** |
|
| 49 | 49 | * @param string $sName |
| 50 | 50 | * |
| 51 | 51 | * @return void |
| 52 | 52 | */ |
| 53 | - protected function validateObjectName(string $sName): void |
|
| 54 | - { |
|
| 55 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | - { |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - throw new SetupException("$sName is not a valid \"name\" value for callback"); |
|
| 60 | - } |
|
| 53 | +protected function validateObjectName(string $sName): void |
|
| 54 | +{ |
|
| 55 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sName) > 0) |
|
| 56 | +{ |
|
| 57 | +return; |
|
| 58 | +} |
|
| 59 | +throw new SetupException("$sName is not a valid \"name\" value for callback"); |
|
| 60 | +} |
|
| 61 | 61 | |
| 62 | - /** |
|
| 62 | +/** |
|
| 63 | 63 | * @param string $sName |
| 64 | 64 | * |
| 65 | 65 | * @return void |
| 66 | 66 | */ |
| 67 | - public function addValue(string $sName): void |
|
| 68 | - { |
|
| 69 | - $this->validateObjectName($sName); |
|
| 67 | +public function addValue(string $sName): void |
|
| 68 | +{ |
|
| 69 | +$this->validateObjectName($sName); |
|
| 70 | 70 | |
| 71 | - $this->aNames[$sName] = $sName; |
|
| 72 | - } |
|
| 71 | +$this->aNames[$sName] = $sName; |
|
| 72 | +} |
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | +/** |
|
| 75 | 75 | * @inheritDoc |
| 76 | 76 | */ |
| 77 | - public function encode(string $sVarName): array |
|
| 78 | - { |
|
| 79 | - return array_map(fn($sName) => |
|
| 80 | - "{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | - } |
|
| 77 | +public function encode(string $sVarName): array |
|
| 78 | +{ |
|
| 79 | +return array_map(fn($sName) => |
|
| 80 | +"{$sVarName}->addValue('$sName');", $this->aNames); |
|
| 81 | +} |
|
| 82 | 82 | } |
@@ -236,82 +236,82 @@ |
||
| 236 | 236 | $this->aComponentPublicMethods['node'], |
| 237 | 237 | $xReflectionClass->isSubclassOf(FuncComponent::class) => |
| 238 | 238 | $this->aComponentPublicMethods['func'], |
| 239 | - default => [], |
|
| 240 | - }; |
|
| 241 | - return [$aMethods, $aBaseMethods]; |
|
| 242 | - } |
|
| 239 | +default => [], |
|
| 240 | +}; |
|
| 241 | +return [$aMethods, $aBaseMethods]; |
|
| 242 | +} |
|
| 243 | 243 | |
| 244 | - /** |
|
| 244 | +/** |
|
| 245 | 245 | * @param ReflectionClass $xReflectionClass |
| 246 | 246 | * @param array $aMethods |
| 247 | 247 | * @param array $aOptions |
| 248 | 248 | * |
| 249 | 249 | * @return Metadata|null |
| 250 | 250 | */ |
| 251 | - private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 252 | - array $aMethods, array $aOptions): Metadata|null |
|
| 253 | - { |
|
| 254 | - /** @var Config|null */ |
|
| 255 | - $xPackageConfig = $aOptions['config'] ?? null; |
|
| 256 | - if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 257 | - { |
|
| 258 | - return null; |
|
| 259 | - } |
|
| 260 | - $sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 261 | - if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 262 | - { |
|
| 263 | - return null; |
|
| 264 | - } |
|
| 251 | +private function getComponentMetadata(ReflectionClass $xReflectionClass, |
|
| 252 | +array $aMethods, array $aOptions): Metadata|null |
|
| 253 | +{ |
|
| 254 | +/** @var Config|null */ |
|
| 255 | +$xPackageConfig = $aOptions['config'] ?? null; |
|
| 256 | +if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false)) |
|
| 257 | +{ |
|
| 258 | +return null; |
|
| 259 | +} |
|
| 260 | +$sMetadataFormat = $xPackageConfig->getOption('metadata.format'); |
|
| 261 | +if(!in_array($sMetadataFormat, ['attributes', 'annotations'])) |
|
| 262 | +{ |
|
| 263 | +return null; |
|
| 264 | +} |
|
| 265 | 265 | |
| 266 | - // Try to get the class metadata from the cache. |
|
| 267 | - $di = $this->cn(); |
|
| 268 | - $xMetadata = null; |
|
| 269 | - $xMetadataCache = null; |
|
| 270 | - $xConfig = $di->config(); |
|
| 271 | - if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 272 | - { |
|
| 273 | - if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 274 | - { |
|
| 275 | - $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 276 | - $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 277 | - } |
|
| 278 | - $xMetadataCache = $di->getMetadataCache(); |
|
| 279 | - $xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 280 | - if($xMetadata !== null) |
|
| 281 | - { |
|
| 282 | - return $xMetadata; |
|
| 283 | - } |
|
| 284 | - } |
|
| 266 | +// Try to get the class metadata from the cache. |
|
| 267 | +$di = $this->cn(); |
|
| 268 | +$xMetadata = null; |
|
| 269 | +$xMetadataCache = null; |
|
| 270 | +$xConfig = $di->config(); |
|
| 271 | +if($xConfig->getAppOption('metadata.cache.enabled', false)) |
|
| 272 | +{ |
|
| 273 | +if(!$di->h('jaxon_metadata_cache_dir')) |
|
| 274 | +{ |
|
| 275 | + $sCacheDir = $xConfig->getAppOption('metadata.cache.dir'); |
|
| 276 | + $di->val('jaxon_metadata_cache_dir', $sCacheDir); |
|
| 277 | +} |
|
| 278 | +$xMetadataCache = $di->getMetadataCache(); |
|
| 279 | +$xMetadata = $xMetadataCache->read($xReflectionClass->getName()); |
|
| 280 | +if($xMetadata !== null) |
|
| 281 | +{ |
|
| 282 | + return $xMetadata; |
|
| 283 | +} |
|
| 284 | +} |
|
| 285 | 285 | |
| 286 | - $aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 287 | - $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 288 | - ReflectionProperty::IS_PROTECTED)); |
|
| 286 | +$aProperties = array_map(fn($xProperty) => $xProperty->getName(), |
|
| 287 | +$xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC | |
|
| 288 | + ReflectionProperty::IS_PROTECTED)); |
|
| 289 | 289 | |
| 290 | - $xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 291 | - $xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 292 | - $xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 290 | +$xMetadataReader = $di->getMetadataReader($sMetadataFormat); |
|
| 291 | +$xInput = new InputData($xReflectionClass, $aMethods, $aProperties); |
|
| 292 | +$xMetadata = $xMetadataReader->getAttributes($xInput); |
|
| 293 | 293 | |
| 294 | - // Try to save the metadata in the cache |
|
| 295 | - if($xMetadataCache !== null && $xMetadata !== null) |
|
| 296 | - { |
|
| 297 | - $xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 298 | - } |
|
| 294 | +// Try to save the metadata in the cache |
|
| 295 | +if($xMetadataCache !== null && $xMetadata !== null) |
|
| 296 | +{ |
|
| 297 | +$xMetadataCache->save($xReflectionClass->getName(), $xMetadata); |
|
| 298 | +} |
|
| 299 | 299 | |
| 300 | - return $xMetadata; |
|
| 301 | - } |
|
| 300 | +return $xMetadata; |
|
| 301 | +} |
|
| 302 | 302 | |
| 303 | - /** |
|
| 303 | +/** |
|
| 304 | 304 | * @param ReflectionClass $xReflectionClass |
| 305 | 305 | * @param array $aOptions |
| 306 | 306 | * |
| 307 | 307 | * @return ComponentOptions |
| 308 | 308 | */ |
| 309 | - private function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 310 | - array $aOptions): ComponentOptions |
|
| 311 | - { |
|
| 312 | - $aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 313 | - $xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 309 | +private function getComponentOptions(ReflectionClass $xReflectionClass, |
|
| 310 | +array $aOptions): ComponentOptions |
|
| 311 | +{ |
|
| 312 | +$aMethods = $this->getPublicMethods($xReflectionClass); |
|
| 313 | +$xMetadata = $this->getComponentMetadata($xReflectionClass, $aMethods[0], $aOptions); |
|
| 314 | 314 | |
| 315 | - return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 316 | - } |
|
| 315 | +return new ComponentOptions($aMethods, $aOptions, $xMetadata); |
|
| 316 | +} |
|
| 317 | 317 | } |
@@ -15,81 +15,81 @@ |
||
| 15 | 15 | |
| 16 | 16 | trait CallableTrait |
| 17 | 17 | { |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * Register the values into the container |
| 20 | 20 | * |
| 21 | 21 | * @return void |
| 22 | 22 | */ |
| 23 | - private function registerCallables(): void |
|
| 24 | - { |
|
| 25 | - // Validator |
|
| 26 | - $this->set(Validator::class, function($di) { |
|
| 27 | - return new Validator($di->g(ConfigManager::class), $di->g(Translator::class)); |
|
| 28 | - }); |
|
| 29 | - // Callable objects registry |
|
| 30 | - $this->set(ComponentRegistry::class, function($di) { |
|
| 31 | - return new ComponentRegistry($di->g(ComponentContainer::class)); |
|
| 32 | - }); |
|
| 33 | - // Callable class plugin |
|
| 34 | - $this->set(CallableClassPlugin::class, function($di) { |
|
| 35 | - $sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.class'); |
|
| 36 | - return new CallableClassPlugin($sPrefix, $di->getLogger(), |
|
| 37 | - $di->g(ComponentContainer::class), $di->g(ComponentRegistry::class), |
|
| 38 | - $di->g(Translator::class), $di->g(TemplateEngine::class), |
|
| 39 | - $di->g(Validator::class)); |
|
| 40 | - }); |
|
| 41 | - // Callable dir plugin |
|
| 42 | - $this->set(CallableDirPlugin::class, function($di) { |
|
| 43 | - return new CallableDirPlugin($di->g(ComponentContainer::class), |
|
| 44 | - $di->g(ComponentRegistry::class), $di->g(Translator::class)); |
|
| 45 | - }); |
|
| 46 | - // Callable function plugin |
|
| 47 | - $this->set(CallableFunctionPlugin::class, function($di) { |
|
| 48 | - $sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.function'); |
|
| 49 | - $bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false); |
|
| 50 | - return new CallableFunctionPlugin($sPrefix, $bDebug, |
|
| 51 | - $di->g(Container::class), $di->g(TemplateEngine::class), |
|
| 52 | - $di->g(Translator::class), $di->g(Validator::class)); |
|
| 53 | - }); |
|
| 54 | - } |
|
| 23 | +private function registerCallables(): void |
|
| 24 | +{ |
|
| 25 | +// Validator |
|
| 26 | +$this->set(Validator::class, function($di) { |
|
| 27 | +return new Validator($di->g(ConfigManager::class), $di->g(Translator::class)); |
|
| 28 | +}); |
|
| 29 | +// Callable objects registry |
|
| 30 | +$this->set(ComponentRegistry::class, function($di) { |
|
| 31 | +return new ComponentRegistry($di->g(ComponentContainer::class)); |
|
| 32 | +}); |
|
| 33 | +// Callable class plugin |
|
| 34 | +$this->set(CallableClassPlugin::class, function($di) { |
|
| 35 | +$sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.class'); |
|
| 36 | +return new CallableClassPlugin($sPrefix, $di->getLogger(), |
|
| 37 | + $di->g(ComponentContainer::class), $di->g(ComponentRegistry::class), |
|
| 38 | + $di->g(Translator::class), $di->g(TemplateEngine::class), |
|
| 39 | + $di->g(Validator::class)); |
|
| 40 | +}); |
|
| 41 | +// Callable dir plugin |
|
| 42 | +$this->set(CallableDirPlugin::class, function($di) { |
|
| 43 | +return new CallableDirPlugin($di->g(ComponentContainer::class), |
|
| 44 | + $di->g(ComponentRegistry::class), $di->g(Translator::class)); |
|
| 45 | +}); |
|
| 46 | +// Callable function plugin |
|
| 47 | +$this->set(CallableFunctionPlugin::class, function($di) { |
|
| 48 | +$sPrefix = $di->g(ConfigManager::class)->getOption('core.prefix.function'); |
|
| 49 | +$bDebug = $di->g(ConfigManager::class)->getOption('core.debug.on', false); |
|
| 50 | +return new CallableFunctionPlugin($sPrefix, $bDebug, |
|
| 51 | + $di->g(Container::class), $di->g(TemplateEngine::class), |
|
| 52 | + $di->g(Translator::class), $di->g(Validator::class)); |
|
| 53 | +}); |
|
| 54 | +} |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * Get the callable registry |
| 58 | 58 | * |
| 59 | 59 | * @return ComponentRegistry |
| 60 | 60 | */ |
| 61 | - public function getComponentRegistry(): ComponentRegistry |
|
| 62 | - { |
|
| 63 | - return $this->g(ComponentRegistry::class); |
|
| 64 | - } |
|
| 61 | +public function getComponentRegistry(): ComponentRegistry |
|
| 62 | +{ |
|
| 63 | +return $this->g(ComponentRegistry::class); |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * Get the callable function plugin |
| 68 | 68 | * |
| 69 | 69 | * @return CallableFunctionPlugin |
| 70 | 70 | */ |
| 71 | - public function getCallableFunctionPlugin(): CallableFunctionPlugin |
|
| 72 | - { |
|
| 73 | - return $this->g(CallableFunctionPlugin::class); |
|
| 74 | - } |
|
| 71 | +public function getCallableFunctionPlugin(): CallableFunctionPlugin |
|
| 72 | +{ |
|
| 73 | +return $this->g(CallableFunctionPlugin::class); |
|
| 74 | +} |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * Get the callable class plugin |
| 78 | 78 | * |
| 79 | 79 | * @return CallableClassPlugin |
| 80 | 80 | */ |
| 81 | - public function getCallableClassPlugin(): CallableClassPlugin |
|
| 82 | - { |
|
| 83 | - return $this->g(CallableClassPlugin::class); |
|
| 84 | - } |
|
| 81 | +public function getCallableClassPlugin(): CallableClassPlugin |
|
| 82 | +{ |
|
| 83 | +return $this->g(CallableClassPlugin::class); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * Get the callable dir plugin |
| 88 | 88 | * |
| 89 | 89 | * @return CallableDirPlugin |
| 90 | 90 | */ |
| 91 | - public function getCallableDirPlugin(): CallableDirPlugin |
|
| 92 | - { |
|
| 93 | - return $this->g(CallableDirPlugin::class); |
|
| 94 | - } |
|
| 91 | +public function getCallableDirPlugin(): CallableDirPlugin |
|
| 92 | +{ |
|
| 93 | +return $this->g(CallableDirPlugin::class); |
|
| 94 | +} |
|
| 95 | 95 | } |
@@ -9,50 +9,50 @@ |
||
| 9 | 9 | |
| 10 | 10 | trait MetadataTrait |
| 11 | 11 | { |
| 12 | - /** |
|
| 12 | +/** |
|
| 13 | 13 | * Register the values into the container |
| 14 | 14 | * |
| 15 | 15 | * @return void |
| 16 | 16 | */ |
| 17 | - private function registerMetadataReader(): void |
|
| 18 | - { |
|
| 19 | - // Metadata cache |
|
| 20 | - $this->set(MetadataCache::class, fn($di) => |
|
| 21 | - new MetadataCache($di->g('jaxon_metadata_cache_dir'))); |
|
| 17 | +private function registerMetadataReader(): void |
|
| 18 | +{ |
|
| 19 | +// Metadata cache |
|
| 20 | +$this->set(MetadataCache::class, fn($di) => |
|
| 21 | +new MetadataCache($di->g('jaxon_metadata_cache_dir'))); |
|
| 22 | 22 | |
| 23 | - // By default, register a fake metadata reader. |
|
| 24 | - $this->set('metadata_reader_null', function() { |
|
| 25 | - return new class implements MetadataReaderInterface |
|
| 26 | - { |
|
| 27 | - public function getAttributes(InputData $xInputData): Metadata |
|
| 28 | - { |
|
| 29 | - return new Metadata(); |
|
| 30 | - } |
|
| 31 | - }; |
|
| 32 | - }); |
|
| 23 | +// By default, register a fake metadata reader. |
|
| 24 | +$this->set('metadata_reader_null', function() { |
|
| 25 | +return new class implements MetadataReaderInterface |
|
| 26 | +{ |
|
| 27 | + public function getAttributes(InputData $xInputData): Metadata |
|
| 28 | + { |
|
| 29 | + return new Metadata(); |
|
| 33 | 30 | } |
| 31 | +}; |
|
| 32 | +}); |
|
| 33 | +} |
|
| 34 | 34 | |
| 35 | - /** |
|
| 35 | +/** |
|
| 36 | 36 | * Get the metadata cache |
| 37 | 37 | * |
| 38 | 38 | * @return MetadataCache |
| 39 | 39 | */ |
| 40 | - public function getMetadataCache(): MetadataCache |
|
| 41 | - { |
|
| 42 | - return $this->g(MetadataCache::class); |
|
| 43 | - } |
|
| 40 | +public function getMetadataCache(): MetadataCache |
|
| 41 | +{ |
|
| 42 | +return $this->g(MetadataCache::class); |
|
| 43 | +} |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * Get the metadata reader with the given id |
| 47 | 47 | * |
| 48 | 48 | * @param string $sReaderId |
| 49 | 49 | * |
| 50 | 50 | * @return MetadataReaderInterface |
| 51 | 51 | */ |
| 52 | - public function getMetadataReader(string $sReaderId): MetadataReaderInterface |
|
| 53 | - { |
|
| 54 | - return $this->h("metadata_reader_$sReaderId") ? |
|
| 55 | - $this->g("metadata_reader_$sReaderId") : |
|
| 56 | - $this->g('metadata_reader_null'); |
|
| 57 | - } |
|
| 52 | +public function getMetadataReader(string $sReaderId): MetadataReaderInterface |
|
| 53 | +{ |
|
| 54 | +return $this->h("metadata_reader_$sReaderId") ? |
|
| 55 | +$this->g("metadata_reader_$sReaderId") : |
|
| 56 | +$this->g('metadata_reader_null'); |
|
| 57 | +} |
|
| 58 | 58 | } |
@@ -20,152 +20,152 @@ |
||
| 20 | 20 | |
| 21 | 21 | trait PsrTrait |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * @var string |
| 25 | 25 | */ |
| 26 | - private $sPsrConfig = 'jaxon.psr.config.file'; |
|
| 26 | +private $sPsrConfig = 'jaxon.psr.config.file'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 28 | +/** |
|
| 29 | 29 | * @var string |
| 30 | 30 | */ |
| 31 | - private $sPsrServerRequest = 'jaxon.psr.server.request'; |
|
| 31 | +private $sPsrServerRequest = 'jaxon.psr.server.request'; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 33 | +/** |
|
| 34 | 34 | * Register the values into the container |
| 35 | 35 | * |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | - private function registerPsr(): void |
|
| 39 | - { |
|
| 40 | - // The server request |
|
| 41 | - $this->set(Psr17Factory::class, function() { |
|
| 42 | - return new Psr17Factory(); |
|
| 43 | - }); |
|
| 44 | - $this->set(ServerRequestCreator::class, function($di) { |
|
| 45 | - $xPsr17Factory = $di->g(Psr17Factory::class); |
|
| 46 | - return new ServerRequestCreator( |
|
| 47 | - $xPsr17Factory, // ServerRequestFactory |
|
| 48 | - $xPsr17Factory, // UriFactory |
|
| 49 | - $xPsr17Factory, // UploadedFileFactory |
|
| 50 | - $xPsr17Factory, // StreamFactory |
|
| 51 | - ); |
|
| 52 | - }); |
|
| 53 | - $this->set(ServerRequestInterface::class, function($di) { |
|
| 54 | - return $di->g(ServerRequestCreator::class)->fromGlobals(); |
|
| 55 | - }); |
|
| 56 | - // Server request with the Jaxon request parameter as attribute |
|
| 57 | - $this->set($this->sPsrServerRequest, function($di) { |
|
| 58 | - $xParameterReader = $di->g(ParameterReader::class); |
|
| 59 | - $xRequest = $di->g(ServerRequestInterface::class); |
|
| 60 | - $aRequestParameter = $xParameterReader->getRequestParameter($xRequest); |
|
| 61 | - return !is_array($aRequestParameter) ? $xRequest : |
|
| 62 | - $xRequest->withAttribute('jxncall', $aRequestParameter); |
|
| 63 | - }); |
|
| 64 | - // PSR factory |
|
| 65 | - $this->set(PsrFactory::class, function($di) { |
|
| 66 | - return new PsrFactory($di->g(Container::class)); |
|
| 67 | - }); |
|
| 68 | - // PSR request handler |
|
| 69 | - $this->set(PsrRequestHandler::class, function($di) { |
|
| 70 | - return new PsrRequestHandler($di->g(Container::class), $di->g(RequestHandler::class), |
|
| 71 | - $di->g(ResponseManager::class), $di->g(Translator::class)); |
|
| 72 | - }); |
|
| 73 | - // PSR config middleware |
|
| 74 | - $this->set(PsrConfigMiddleware::class, function($di) { |
|
| 75 | - return new PsrConfigMiddleware($di->g(Container::class), $di->g($this->sPsrConfig)); |
|
| 76 | - }); |
|
| 77 | - // PSR ajax middleware |
|
| 78 | - $this->set(PsrAjaxMiddleware::class, function($di) { |
|
| 79 | - return new PsrAjaxMiddleware($di->g(Container::class), $di->g(RequestHandler::class), |
|
| 80 | - $di->g(ResponseManager::class)); |
|
| 81 | - }); |
|
| 82 | - // The PSR response plugin |
|
| 83 | - $this->set(PsrPlugin::class, function($di) { |
|
| 84 | - return new PsrPlugin($di->g(Psr17Factory::class), $di->g(ServerRequestInterface::class)); |
|
| 85 | - }); |
|
| 86 | - } |
|
| 38 | +private function registerPsr(): void |
|
| 39 | +{ |
|
| 40 | +// The server request |
|
| 41 | +$this->set(Psr17Factory::class, function() { |
|
| 42 | +return new Psr17Factory(); |
|
| 43 | +}); |
|
| 44 | +$this->set(ServerRequestCreator::class, function($di) { |
|
| 45 | +$xPsr17Factory = $di->g(Psr17Factory::class); |
|
| 46 | +return new ServerRequestCreator( |
|
| 47 | + $xPsr17Factory, // ServerRequestFactory |
|
| 48 | + $xPsr17Factory, // UriFactory |
|
| 49 | + $xPsr17Factory, // UploadedFileFactory |
|
| 50 | + $xPsr17Factory, // StreamFactory |
|
| 51 | +); |
|
| 52 | +}); |
|
| 53 | +$this->set(ServerRequestInterface::class, function($di) { |
|
| 54 | +return $di->g(ServerRequestCreator::class)->fromGlobals(); |
|
| 55 | +}); |
|
| 56 | +// Server request with the Jaxon request parameter as attribute |
|
| 57 | +$this->set($this->sPsrServerRequest, function($di) { |
|
| 58 | +$xParameterReader = $di->g(ParameterReader::class); |
|
| 59 | +$xRequest = $di->g(ServerRequestInterface::class); |
|
| 60 | +$aRequestParameter = $xParameterReader->getRequestParameter($xRequest); |
|
| 61 | +return !is_array($aRequestParameter) ? $xRequest : |
|
| 62 | + $xRequest->withAttribute('jxncall', $aRequestParameter); |
|
| 63 | +}); |
|
| 64 | +// PSR factory |
|
| 65 | +$this->set(PsrFactory::class, function($di) { |
|
| 66 | +return new PsrFactory($di->g(Container::class)); |
|
| 67 | +}); |
|
| 68 | +// PSR request handler |
|
| 69 | +$this->set(PsrRequestHandler::class, function($di) { |
|
| 70 | +return new PsrRequestHandler($di->g(Container::class), $di->g(RequestHandler::class), |
|
| 71 | + $di->g(ResponseManager::class), $di->g(Translator::class)); |
|
| 72 | +}); |
|
| 73 | +// PSR config middleware |
|
| 74 | +$this->set(PsrConfigMiddleware::class, function($di) { |
|
| 75 | +return new PsrConfigMiddleware($di->g(Container::class), $di->g($this->sPsrConfig)); |
|
| 76 | +}); |
|
| 77 | +// PSR ajax middleware |
|
| 78 | +$this->set(PsrAjaxMiddleware::class, function($di) { |
|
| 79 | +return new PsrAjaxMiddleware($di->g(Container::class), $di->g(RequestHandler::class), |
|
| 80 | + $di->g(ResponseManager::class)); |
|
| 81 | +}); |
|
| 82 | +// The PSR response plugin |
|
| 83 | +$this->set(PsrPlugin::class, function($di) { |
|
| 84 | +return new PsrPlugin($di->g(Psr17Factory::class), $di->g(ServerRequestInterface::class)); |
|
| 85 | +}); |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * Get the request |
| 90 | 90 | * |
| 91 | 91 | * @return array |
| 92 | 92 | */ |
| 93 | - public function getServerParams(): array |
|
| 94 | - { |
|
| 95 | - $xRequest = $this->g(ServerRequestInterface::class); |
|
| 96 | - return $xRequest->getServerParams(); |
|
| 97 | - } |
|
| 93 | +public function getServerParams(): array |
|
| 94 | +{ |
|
| 95 | +$xRequest = $this->g(ServerRequestInterface::class); |
|
| 96 | +return $xRequest->getServerParams(); |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * Get the request with Jaxon parameter as attribute |
| 101 | 101 | * |
| 102 | 102 | * @return ServerRequestInterface |
| 103 | 103 | */ |
| 104 | - public function getRequest(): ServerRequestInterface |
|
| 105 | - { |
|
| 106 | - return $this->g($this->sPsrServerRequest); |
|
| 107 | - } |
|
| 104 | +public function getRequest(): ServerRequestInterface |
|
| 105 | +{ |
|
| 106 | +return $this->g($this->sPsrServerRequest); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Return the array of arguments from the GET or POST data |
| 111 | 111 | * |
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | - public function getRequestArguments(): array |
|
| 115 | - { |
|
| 116 | - return $this->getRequest()->getAttribute('jxncall')['args'] ?? []; |
|
| 117 | - } |
|
| 114 | +public function getRequestArguments(): array |
|
| 115 | +{ |
|
| 116 | +return $this->getRequest()->getAttribute('jxncall')['args'] ?? []; |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - /** |
|
| 119 | +/** |
|
| 120 | 120 | * Get the PSR factory |
| 121 | 121 | * |
| 122 | 122 | * @return PsrFactory |
| 123 | 123 | */ |
| 124 | - public function getPsrFactory(): PsrFactory |
|
| 125 | - { |
|
| 126 | - return $this->g(PsrFactory::class); |
|
| 127 | - } |
|
| 124 | +public function getPsrFactory(): PsrFactory |
|
| 125 | +{ |
|
| 126 | +return $this->g(PsrFactory::class); |
|
| 127 | +} |
|
| 128 | 128 | |
| 129 | - /** |
|
| 129 | +/** |
|
| 130 | 130 | * Get the Psr17 factory |
| 131 | 131 | * |
| 132 | 132 | * @return Psr17Factory |
| 133 | 133 | */ |
| 134 | - public function getPsr17Factory(): Psr17Factory |
|
| 135 | - { |
|
| 136 | - return $this->g(Psr17Factory::class); |
|
| 137 | - } |
|
| 134 | +public function getPsr17Factory(): Psr17Factory |
|
| 135 | +{ |
|
| 136 | +return $this->g(Psr17Factory::class); |
|
| 137 | +} |
|
| 138 | 138 | |
| 139 | - /** |
|
| 139 | +/** |
|
| 140 | 140 | * Get the PSR request handler |
| 141 | 141 | * |
| 142 | 142 | * @return PsrRequestHandler |
| 143 | 143 | */ |
| 144 | - public function getPsrRequestHandler(): PsrRequestHandler |
|
| 145 | - { |
|
| 146 | - return $this->g(PsrRequestHandler::class); |
|
| 147 | - } |
|
| 144 | +public function getPsrRequestHandler(): PsrRequestHandler |
|
| 145 | +{ |
|
| 146 | +return $this->g(PsrRequestHandler::class); |
|
| 147 | +} |
|
| 148 | 148 | |
| 149 | - /** |
|
| 149 | +/** |
|
| 150 | 150 | * Get the PSR config middleware |
| 151 | 151 | * |
| 152 | 152 | * @param string $sConfigFile |
| 153 | 153 | * |
| 154 | 154 | * @return PsrConfigMiddleware |
| 155 | 155 | */ |
| 156 | - public function getPsrConfigMiddleware(string $sConfigFile): PsrConfigMiddleware |
|
| 157 | - { |
|
| 158 | - !$this->h($this->sPsrConfig) && $this->val($this->sPsrConfig, $sConfigFile); |
|
| 159 | - return $this->g(PsrConfigMiddleware::class); |
|
| 160 | - } |
|
| 156 | +public function getPsrConfigMiddleware(string $sConfigFile): PsrConfigMiddleware |
|
| 157 | +{ |
|
| 158 | +!$this->h($this->sPsrConfig) && $this->val($this->sPsrConfig, $sConfigFile); |
|
| 159 | +return $this->g(PsrConfigMiddleware::class); |
|
| 160 | +} |
|
| 161 | 161 | |
| 162 | - /** |
|
| 162 | +/** |
|
| 163 | 163 | * Get the PSR ajax request middleware |
| 164 | 164 | * |
| 165 | 165 | * @return PsrAjaxMiddleware |
| 166 | 166 | */ |
| 167 | - public function getPsrAjaxMiddleware(): PsrAjaxMiddleware |
|
| 168 | - { |
|
| 169 | - return $this->g(PsrAjaxMiddleware::class); |
|
| 170 | - } |
|
| 167 | +public function getPsrAjaxMiddleware(): PsrAjaxMiddleware |
|
| 168 | +{ |
|
| 169 | +return $this->g(PsrAjaxMiddleware::class); |
|
| 170 | +} |
|
| 171 | 171 | } |
@@ -16,104 +16,104 @@ |
||
| 16 | 16 | |
| 17 | 17 | trait AppTrait |
| 18 | 18 | { |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var string |
| 21 | 21 | */ |
| 22 | - private $sJsLibVersion = 'jaxon_javascript_library_version'; |
|
| 22 | +private $sJsLibVersion = 'jaxon_javascript_library_version'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * Register the values into the container |
| 26 | 26 | * |
| 27 | 27 | * @return void |
| 28 | 28 | */ |
| 29 | - private function registerApp(): void |
|
| 30 | - { |
|
| 31 | - // Config Manager |
|
| 32 | - $this->set(ConfigEventManager::class, function($di) { |
|
| 33 | - return new ConfigEventManager($di->g(Container::class)); |
|
| 34 | - }); |
|
| 35 | - $this->set(ConfigManager::class, function($di) { |
|
| 36 | - $aDefaultOptions = require(__DIR__ . '/../../../config/lib.php'); |
|
| 37 | - return new ConfigManager($aDefaultOptions, $di->g(Translator::class), |
|
| 38 | - $di->g(ConfigReader::class), $di->g(ConfigSetter::class), |
|
| 39 | - $di->g(ConfigEventManager::class)); |
|
| 40 | - }); |
|
| 29 | +private function registerApp(): void |
|
| 30 | +{ |
|
| 31 | +// Config Manager |
|
| 32 | +$this->set(ConfigEventManager::class, function($di) { |
|
| 33 | +return new ConfigEventManager($di->g(Container::class)); |
|
| 34 | +}); |
|
| 35 | +$this->set(ConfigManager::class, function($di) { |
|
| 36 | +$aDefaultOptions = require(__DIR__ . '/../../../config/lib.php'); |
|
| 37 | +return new ConfigManager($aDefaultOptions, $di->g(Translator::class), |
|
| 38 | + $di->g(ConfigReader::class), $di->g(ConfigSetter::class), |
|
| 39 | + $di->g(ConfigEventManager::class)); |
|
| 40 | +}); |
|
| 41 | 41 | |
| 42 | - // Jaxon App |
|
| 43 | - $this->set(AppInterface::class, fn() => new App()); |
|
| 44 | - // Jaxon App bootstrap |
|
| 45 | - $this->set(Bootstrap::class, function($di) { |
|
| 46 | - return new Bootstrap($di->g(ConfigManager::class), |
|
| 47 | - $di->g(PackageManager::class), $di->g(CallbackManager::class)); |
|
| 48 | - }); |
|
| 49 | - // The javascript library version |
|
| 50 | - $this->set($this->sJsLibVersion, function($di) { |
|
| 51 | - $xRequest = $di->getRequest(); |
|
| 52 | - $aParams = $xRequest->getMethod() === 'POST' ? |
|
| 53 | - $xRequest->getParsedBody() : $xRequest->getQueryParams(); |
|
| 54 | - return $aParams['jxnv'] ?? '3.3.0'; |
|
| 55 | - }); |
|
| 56 | - } |
|
| 42 | +// Jaxon App |
|
| 43 | +$this->set(AppInterface::class, fn() => new App()); |
|
| 44 | +// Jaxon App bootstrap |
|
| 45 | +$this->set(Bootstrap::class, function($di) { |
|
| 46 | +return new Bootstrap($di->g(ConfigManager::class), |
|
| 47 | + $di->g(PackageManager::class), $di->g(CallbackManager::class)); |
|
| 48 | +}); |
|
| 49 | +// The javascript library version |
|
| 50 | +$this->set($this->sJsLibVersion, function($di) { |
|
| 51 | +$xRequest = $di->getRequest(); |
|
| 52 | +$aParams = $xRequest->getMethod() === 'POST' ? |
|
| 53 | + $xRequest->getParsedBody() : $xRequest->getQueryParams(); |
|
| 54 | +return $aParams['jxnv'] ?? '3.3.0'; |
|
| 55 | +}); |
|
| 56 | +} |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * Register the event handlers |
| 60 | 60 | * |
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | - private function setEventHandlers(): void |
|
| 64 | - { |
|
| 65 | - $xEventManager = $this->g(ConfigEventManager::class); |
|
| 66 | - $xEventManager->addLibConfigListener(Translator::class); |
|
| 67 | - } |
|
| 63 | +private function setEventHandlers(): void |
|
| 64 | +{ |
|
| 65 | +$xEventManager = $this->g(ConfigEventManager::class); |
|
| 66 | +$xEventManager->addLibConfigListener(Translator::class); |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * Get the App instance |
| 71 | 71 | * |
| 72 | 72 | * @return AppInterface |
| 73 | 73 | */ |
| 74 | - public function getApp(): AppInterface |
|
| 75 | - { |
|
| 76 | - return $this->g(AppInterface::class); |
|
| 77 | - } |
|
| 74 | +public function getApp(): AppInterface |
|
| 75 | +{ |
|
| 76 | +return $this->g(AppInterface::class); |
|
| 77 | +} |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * Get the App bootstrap |
| 81 | 81 | * |
| 82 | 82 | * @return Bootstrap |
| 83 | 83 | */ |
| 84 | - public function getBootstrap(): Bootstrap |
|
| 85 | - { |
|
| 86 | - return $this->g(Bootstrap::class); |
|
| 87 | - } |
|
| 84 | +public function getBootstrap(): Bootstrap |
|
| 85 | +{ |
|
| 86 | +return $this->g(Bootstrap::class); |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * Get the config manager |
| 91 | 91 | * |
| 92 | 92 | * @return ConfigManager |
| 93 | 93 | */ |
| 94 | - public function config(): ConfigManager |
|
| 95 | - { |
|
| 96 | - return $this->g(ConfigManager::class); |
|
| 97 | - } |
|
| 94 | +public function config(): ConfigManager |
|
| 95 | +{ |
|
| 96 | +return $this->g(ConfigManager::class); |
|
| 97 | +} |
|
| 98 | 98 | |
| 99 | - /** |
|
| 99 | +/** |
|
| 100 | 100 | * Get the javascript library version |
| 101 | 101 | * |
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | - public function getJsLibVersion(): string |
|
| 105 | - { |
|
| 106 | - return $this->g($this->sJsLibVersion); |
|
| 107 | - } |
|
| 104 | +public function getJsLibVersion(): string |
|
| 105 | +{ |
|
| 106 | +return $this->g($this->sJsLibVersion); |
|
| 107 | +} |
|
| 108 | 108 | |
| 109 | - /** |
|
| 109 | +/** |
|
| 110 | 110 | * Get the default request URI |
| 111 | 111 | * |
| 112 | 112 | * @return string |
| 113 | 113 | */ |
| 114 | - public function getRequestUri(): string |
|
| 115 | - { |
|
| 116 | - return $this->config()->getOption('core.request.uri', |
|
| 117 | - $this->getParameterReader()->uri()); |
|
| 118 | - } |
|
| 114 | +public function getRequestUri(): string |
|
| 115 | +{ |
|
| 116 | +return $this->config()->getOption('core.request.uri', |
|
| 117 | +$this->getParameterReader()->uri()); |
|
| 118 | +} |
|
| 119 | 119 | } |
@@ -15,64 +15,64 @@ |
||
| 15 | 15 | |
| 16 | 16 | trait ResponseTrait |
| 17 | 17 | { |
| 18 | - /** |
|
| 18 | +/** |
|
| 19 | 19 | * Register the values into the container |
| 20 | 20 | * |
| 21 | 21 | * @return void |
| 22 | 22 | */ |
| 23 | - private function registerResponses(): void |
|
| 24 | - { |
|
| 25 | - // Global Response |
|
| 26 | - $this->set(Response::class, function($di) { |
|
| 27 | - return new Response($di->g(ResponseManager::class), $di->g(PluginManager::class)); |
|
| 28 | - }); |
|
| 29 | - // Response Manager |
|
| 30 | - $this->set(ResponseManager::class, function($di) { |
|
| 31 | - $sEncoding = trim($di->g(ConfigManager::class)->getOption('core.encoding', '')); |
|
| 32 | - return new ResponseManager($di->g(Container::class), $di->g(Translator::class), $sEncoding); |
|
| 33 | - }); |
|
| 34 | - } |
|
| 23 | +private function registerResponses(): void |
|
| 24 | +{ |
|
| 25 | +// Global Response |
|
| 26 | +$this->set(Response::class, function($di) { |
|
| 27 | +return new Response($di->g(ResponseManager::class), $di->g(PluginManager::class)); |
|
| 28 | +}); |
|
| 29 | +// Response Manager |
|
| 30 | +$this->set(ResponseManager::class, function($di) { |
|
| 31 | +$sEncoding = trim($di->g(ConfigManager::class)->getOption('core.encoding', '')); |
|
| 32 | +return new ResponseManager($di->g(Container::class), $di->g(Translator::class), $sEncoding); |
|
| 33 | +}); |
|
| 34 | +} |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | +/** |
|
| 37 | 37 | * Get the response manager |
| 38 | 38 | * |
| 39 | 39 | * @return ResponseManager |
| 40 | 40 | */ |
| 41 | - public function getResponseManager(): ResponseManager |
|
| 42 | - { |
|
| 43 | - return $this->g(ResponseManager::class); |
|
| 44 | - } |
|
| 41 | +public function getResponseManager(): ResponseManager |
|
| 42 | +{ |
|
| 43 | +return $this->g(ResponseManager::class); |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * Get the global Response object |
| 48 | 48 | * |
| 49 | 49 | * @return Response |
| 50 | 50 | */ |
| 51 | - public function getResponse(): Response |
|
| 52 | - { |
|
| 53 | - return $this->g(Response::class); |
|
| 54 | - } |
|
| 51 | +public function getResponse(): Response |
|
| 52 | +{ |
|
| 53 | +return $this->g(Response::class); |
|
| 54 | +} |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * Create a new Jaxon response |
| 58 | 58 | * |
| 59 | 59 | * @return Response |
| 60 | 60 | */ |
| 61 | - public function newResponse(): Response |
|
| 62 | - { |
|
| 63 | - return new Response($this->g(ResponseManager::class), $this->g(PluginManager::class)); |
|
| 64 | - } |
|
| 61 | +public function newResponse(): Response |
|
| 62 | +{ |
|
| 63 | +return new Response($this->g(ResponseManager::class), $this->g(PluginManager::class)); |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * Create a new reponse for a Jaxon component |
| 68 | 68 | * |
| 69 | 69 | * @param JxnCall $xJxnCall |
| 70 | 70 | * |
| 71 | 71 | * @return NodeResponse |
| 72 | 72 | */ |
| 73 | - public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 74 | - { |
|
| 75 | - return new NodeResponse($this->g(ResponseManager::class), |
|
| 76 | - $this->g(PluginManager::class), $xJxnCall); |
|
| 77 | - } |
|
| 73 | +public function newNodeResponse(JxnCall $xJxnCall): NodeResponse |
|
| 74 | +{ |
|
| 75 | +return new NodeResponse($this->g(ResponseManager::class), |
|
| 76 | +$this->g(PluginManager::class), $xJxnCall); |
|
| 77 | +} |
|
| 78 | 78 | } |
@@ -18,78 +18,78 @@ |
||
| 18 | 18 | |
| 19 | 19 | trait ViewTrait |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Register the values into the container |
| 23 | 23 | * |
| 24 | 24 | * @return void |
| 25 | 25 | */ |
| 26 | - private function registerViews(): void |
|
| 27 | - { |
|
| 28 | - // Jaxon template view |
|
| 29 | - $this->set(TemplateView::class, function($di) { |
|
| 30 | - return new TemplateView($di->g(TemplateEngine::class)); |
|
| 31 | - }); |
|
| 32 | - // View Renderer |
|
| 33 | - $this->set(ViewRenderer::class, function($di) { |
|
| 34 | - $xViewRenderer = new ViewRenderer($di->g(Container::class)); |
|
| 35 | - // Add the default view renderer |
|
| 36 | - $xViewRenderer->addRenderer('jaxon', function($di) { |
|
| 37 | - return $di->g(TemplateView::class); |
|
| 38 | - }); |
|
| 39 | - $sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\'); |
|
| 40 | - $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination'; |
|
| 41 | - // By default, render pagination templates with Jaxon. |
|
| 42 | - $xViewRenderer->addNamespace('jaxon', $sTemplateDir, '.php', 'jaxon'); |
|
| 43 | - $xViewRenderer->addNamespace('pagination', $sPaginationDir, '.php', 'jaxon'); |
|
| 44 | - return $xViewRenderer; |
|
| 45 | - }); |
|
| 26 | +private function registerViews(): void |
|
| 27 | +{ |
|
| 28 | +// Jaxon template view |
|
| 29 | +$this->set(TemplateView::class, function($di) { |
|
| 30 | +return new TemplateView($di->g(TemplateEngine::class)); |
|
| 31 | +}); |
|
| 32 | +// View Renderer |
|
| 33 | +$this->set(ViewRenderer::class, function($di) { |
|
| 34 | +$xViewRenderer = new ViewRenderer($di->g(Container::class)); |
|
| 35 | +// Add the default view renderer |
|
| 36 | +$xViewRenderer->addRenderer('jaxon', function($di) { |
|
| 37 | + return $di->g(TemplateView::class); |
|
| 38 | +}); |
|
| 39 | +$sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\'); |
|
| 40 | +$sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination'; |
|
| 41 | +// By default, render pagination templates with Jaxon. |
|
| 42 | +$xViewRenderer->addNamespace('jaxon', $sTemplateDir, '.php', 'jaxon'); |
|
| 43 | +$xViewRenderer->addNamespace('pagination', $sPaginationDir, '.php', 'jaxon'); |
|
| 44 | +return $xViewRenderer; |
|
| 45 | +}); |
|
| 46 | 46 | |
| 47 | - // By default there is no dialog library registry. |
|
| 48 | - $this->set(LibraryRegistryInterface::class, function($di) { |
|
| 49 | - return null; |
|
| 50 | - }); |
|
| 51 | - // Dialog command |
|
| 52 | - $this->set(DialogCommand::class, function($di) { |
|
| 53 | - return new DialogCommand($di->g(LibraryRegistryInterface::class)); |
|
| 54 | - }); |
|
| 55 | - // Pagination renderer |
|
| 56 | - $this->set(RendererInterface::class, function($di) { |
|
| 57 | - return new Renderer($di->g(ViewRenderer::class)); |
|
| 58 | - }); |
|
| 47 | +// By default there is no dialog library registry. |
|
| 48 | +$this->set(LibraryRegistryInterface::class, function($di) { |
|
| 49 | +return null; |
|
| 50 | +}); |
|
| 51 | +// Dialog command |
|
| 52 | +$this->set(DialogCommand::class, function($di) { |
|
| 53 | +return new DialogCommand($di->g(LibraryRegistryInterface::class)); |
|
| 54 | +}); |
|
| 55 | +// Pagination renderer |
|
| 56 | +$this->set(RendererInterface::class, function($di) { |
|
| 57 | +return new Renderer($di->g(ViewRenderer::class)); |
|
| 58 | +}); |
|
| 59 | 59 | |
| 60 | - // Helpers for HTML custom attributes formatting |
|
| 61 | - $this->set(HtmlAttrHelper::class, function($di) { |
|
| 62 | - return new HtmlAttrHelper($di->g(ComponentContainer::class)); |
|
| 63 | - }); |
|
| 64 | - } |
|
| 60 | +// Helpers for HTML custom attributes formatting |
|
| 61 | +$this->set(HtmlAttrHelper::class, function($di) { |
|
| 62 | +return new HtmlAttrHelper($di->g(ComponentContainer::class)); |
|
| 63 | +}); |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * Get the view renderer |
| 68 | 68 | * |
| 69 | 69 | * @return ViewRenderer |
| 70 | 70 | */ |
| 71 | - public function getViewRenderer(): ViewRenderer |
|
| 72 | - { |
|
| 73 | - return $this->g(ViewRenderer::class); |
|
| 74 | - } |
|
| 71 | +public function getViewRenderer(): ViewRenderer |
|
| 72 | +{ |
|
| 73 | +return $this->g(ViewRenderer::class); |
|
| 74 | +} |
|
| 75 | 75 | |
| 76 | - /** |
|
| 76 | +/** |
|
| 77 | 77 | * Get the custom attributes helper |
| 78 | 78 | * |
| 79 | 79 | * @return HtmlAttrHelper |
| 80 | 80 | */ |
| 81 | - public function getHtmlAttrHelper(): HtmlAttrHelper |
|
| 82 | - { |
|
| 83 | - return $this->g(HtmlAttrHelper::class); |
|
| 84 | - } |
|
| 81 | +public function getHtmlAttrHelper(): HtmlAttrHelper |
|
| 82 | +{ |
|
| 83 | +return $this->g(HtmlAttrHelper::class); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * Get the dialog command |
| 88 | 88 | * |
| 89 | 89 | * @return DialogCommand |
| 90 | 90 | */ |
| 91 | - public function getDialogCommand(): DialogCommand |
|
| 92 | - { |
|
| 93 | - return $this->g(DialogCommand::class); |
|
| 94 | - } |
|
| 91 | +public function getDialogCommand(): DialogCommand |
|
| 92 | +{ |
|
| 93 | +return $this->g(DialogCommand::class); |
|
| 94 | +} |
|
| 95 | 95 | } |
@@ -14,78 +14,78 @@ |
||
| 14 | 14 | |
| 15 | 15 | trait UtilTrait |
| 16 | 16 | { |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * Register the values into the container |
| 19 | 19 | * |
| 20 | 20 | * @return void |
| 21 | 21 | */ |
| 22 | - private function registerUtils(): void |
|
| 23 | - { |
|
| 24 | - // Translator |
|
| 25 | - $this->set(Translator::class, function($di) { |
|
| 26 | - $xTranslator = new Translator(); |
|
| 27 | - $sResourceDir = rtrim(trim($di->g('jaxon.core.dir.translation')), '/\\'); |
|
| 28 | - // Load the debug translations |
|
| 29 | - $xTranslator->loadTranslations($sResourceDir . '/en/errors.php', 'en'); |
|
| 30 | - $xTranslator->loadTranslations($sResourceDir . '/fr/errors.php', 'fr'); |
|
| 31 | - $xTranslator->loadTranslations($sResourceDir . '/es/errors.php', 'es'); |
|
| 32 | - // Load the config translations |
|
| 33 | - $xTranslator->loadTranslations($sResourceDir . '/en/config.php', 'en'); |
|
| 34 | - $xTranslator->loadTranslations($sResourceDir . '/fr/config.php', 'fr'); |
|
| 35 | - $xTranslator->loadTranslations($sResourceDir . '/es/config.php', 'es'); |
|
| 36 | - // Load the labels translations |
|
| 37 | - $xTranslator->loadTranslations($sResourceDir . '/en/labels.php', 'en'); |
|
| 38 | - $xTranslator->loadTranslations($sResourceDir . '/fr/labels.php', 'fr'); |
|
| 39 | - $xTranslator->loadTranslations($sResourceDir . '/es/labels.php', 'es'); |
|
| 40 | - return $xTranslator; |
|
| 41 | - }); |
|
| 22 | +private function registerUtils(): void |
|
| 23 | +{ |
|
| 24 | +// Translator |
|
| 25 | +$this->set(Translator::class, function($di) { |
|
| 26 | +$xTranslator = new Translator(); |
|
| 27 | +$sResourceDir = rtrim(trim($di->g('jaxon.core.dir.translation')), '/\\'); |
|
| 28 | +// Load the debug translations |
|
| 29 | +$xTranslator->loadTranslations($sResourceDir . '/en/errors.php', 'en'); |
|
| 30 | +$xTranslator->loadTranslations($sResourceDir . '/fr/errors.php', 'fr'); |
|
| 31 | +$xTranslator->loadTranslations($sResourceDir . '/es/errors.php', 'es'); |
|
| 32 | +// Load the config translations |
|
| 33 | +$xTranslator->loadTranslations($sResourceDir . '/en/config.php', 'en'); |
|
| 34 | +$xTranslator->loadTranslations($sResourceDir . '/fr/config.php', 'fr'); |
|
| 35 | +$xTranslator->loadTranslations($sResourceDir . '/es/config.php', 'es'); |
|
| 36 | +// Load the labels translations |
|
| 37 | +$xTranslator->loadTranslations($sResourceDir . '/en/labels.php', 'en'); |
|
| 38 | +$xTranslator->loadTranslations($sResourceDir . '/fr/labels.php', 'fr'); |
|
| 39 | +$xTranslator->loadTranslations($sResourceDir . '/es/labels.php', 'es'); |
|
| 40 | +return $xTranslator; |
|
| 41 | +}); |
|
| 42 | 42 | |
| 43 | - // Config reader |
|
| 44 | - $this->set(ConfigReader::class, function($di) { |
|
| 45 | - return new ConfigReader($di->g(ConfigSetter::class)); |
|
| 46 | - }); |
|
| 47 | - // Config setter |
|
| 48 | - $this->set(ConfigSetter::class, function() { |
|
| 49 | - return new ConfigSetter(); |
|
| 50 | - }); |
|
| 51 | - // Template engine |
|
| 52 | - $this->set(TemplateEngine::class, function($di) { |
|
| 53 | - $xTemplateEngine = new TemplateEngine(); |
|
| 54 | - $sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\'); |
|
| 55 | - $sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination'; |
|
| 56 | - $xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php'); |
|
| 57 | - $xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php'); |
|
| 58 | - $xTemplateEngine->setDefaultNamespace('jaxon'); |
|
| 59 | - return $xTemplateEngine; |
|
| 60 | - }); |
|
| 61 | - // URI detector |
|
| 62 | - $this->set(UriDetector::class, function() { |
|
| 63 | - return new UriDetector(); |
|
| 64 | - }); |
|
| 43 | +// Config reader |
|
| 44 | +$this->set(ConfigReader::class, function($di) { |
|
| 45 | +return new ConfigReader($di->g(ConfigSetter::class)); |
|
| 46 | +}); |
|
| 47 | +// Config setter |
|
| 48 | +$this->set(ConfigSetter::class, function() { |
|
| 49 | +return new ConfigSetter(); |
|
| 50 | +}); |
|
| 51 | +// Template engine |
|
| 52 | +$this->set(TemplateEngine::class, function($di) { |
|
| 53 | +$xTemplateEngine = new TemplateEngine(); |
|
| 54 | +$sTemplateDir = rtrim(trim($di->g('jaxon.core.dir.template')), '/\\'); |
|
| 55 | +$sPaginationDir = $sTemplateDir . DIRECTORY_SEPARATOR . 'pagination'; |
|
| 56 | +$xTemplateEngine->addNamespace('jaxon', $sTemplateDir, '.php'); |
|
| 57 | +$xTemplateEngine->addNamespace('pagination', $sPaginationDir, '.php'); |
|
| 58 | +$xTemplateEngine->setDefaultNamespace('jaxon'); |
|
| 59 | +return $xTemplateEngine; |
|
| 60 | +}); |
|
| 61 | +// URI detector |
|
| 62 | +$this->set(UriDetector::class, function() { |
|
| 63 | +return new UriDetector(); |
|
| 64 | +}); |
|
| 65 | 65 | |
| 66 | - // Temp cache for Jaxon components |
|
| 67 | - $this->set(Stash::class, function() { |
|
| 68 | - return new Stash(); |
|
| 69 | - }); |
|
| 70 | - } |
|
| 66 | +// Temp cache for Jaxon components |
|
| 67 | +$this->set(Stash::class, function() { |
|
| 68 | +return new Stash(); |
|
| 69 | +}); |
|
| 70 | +} |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * Get the template engine |
| 74 | 74 | * |
| 75 | 75 | * @return TemplateEngine |
| 76 | 76 | */ |
| 77 | - public function getTemplateEngine(): TemplateEngine |
|
| 78 | - { |
|
| 79 | - return $this->g(TemplateEngine::class); |
|
| 80 | - } |
|
| 77 | +public function getTemplateEngine(): TemplateEngine |
|
| 78 | +{ |
|
| 79 | +return $this->g(TemplateEngine::class); |
|
| 80 | +} |
|
| 81 | 81 | |
| 82 | - /** |
|
| 82 | +/** |
|
| 83 | 83 | * Get the temp cache for Jaxon components |
| 84 | 84 | * |
| 85 | 85 | * @return Stash |
| 86 | 86 | */ |
| 87 | - public function getStash(): Stash |
|
| 88 | - { |
|
| 89 | - return $this->g(Stash::class); |
|
| 90 | - } |
|
| 87 | +public function getStash(): Stash |
|
| 88 | +{ |
|
| 89 | +return $this->g(Stash::class); |
|
| 90 | +} |
|
| 91 | 91 | } |