@@ -21,161 +21,161 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Metadata |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var array<string, array<string, Data\AbstractData>> |
| 26 | 26 | */ |
| 27 | - private array $aAttributes = [ |
|
| 28 | - 'exclude' => [], |
|
| 29 | - 'container' => [], |
|
| 30 | - 'databag' => [], |
|
| 31 | - 'callback' => [], |
|
| 32 | - 'before' => [], |
|
| 33 | - 'after' => [], |
|
| 34 | - 'upload' => [], |
|
| 35 | - ]; |
|
| 36 | - |
|
| 37 | - /** |
|
| 27 | +private array $aAttributes = [ |
|
| 28 | +'exclude' => [], |
|
| 29 | +'container' => [], |
|
| 30 | +'databag' => [], |
|
| 31 | +'callback' => [], |
|
| 32 | +'before' => [], |
|
| 33 | +'after' => [], |
|
| 34 | +'upload' => [], |
|
| 35 | +]; |
|
| 36 | + |
|
| 37 | +/** |
|
| 38 | 38 | * @return array<string, array<string, Data\AbstractData>> |
| 39 | 39 | */ |
| 40 | - public function getAttributes(): array |
|
| 41 | - { |
|
| 42 | - return $this->aAttributes; |
|
| 43 | - } |
|
| 40 | +public function getAttributes(): array |
|
| 41 | +{ |
|
| 42 | +return $this->aAttributes; |
|
| 43 | +} |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * @param string $sMethod |
| 47 | 47 | * |
| 48 | 48 | * @return Data\ExcludeData |
| 49 | 49 | */ |
| 50 | - public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 51 | - { |
|
| 52 | - return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 53 | - $this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 54 | - } |
|
| 50 | +public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 51 | +{ |
|
| 52 | +return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 53 | +$this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 54 | +} |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | +/** |
|
| 57 | 57 | * @param string $sMethod |
| 58 | 58 | * |
| 59 | 59 | * @return Data\ContainerData |
| 60 | 60 | */ |
| 61 | - public function container(string $sMethod = '*'): Data\ContainerData |
|
| 62 | - { |
|
| 63 | - return $this->aAttributes['container'][$sMethod] ?? |
|
| 64 | - $this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 65 | - } |
|
| 61 | +public function container(string $sMethod = '*'): Data\ContainerData |
|
| 62 | +{ |
|
| 63 | +return $this->aAttributes['container'][$sMethod] ?? |
|
| 64 | +$this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 65 | +} |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | +/** |
|
| 68 | 68 | * @param string $sMethod |
| 69 | 69 | * |
| 70 | 70 | * @return Data\DatabagData |
| 71 | 71 | */ |
| 72 | - public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 73 | - { |
|
| 74 | - return $this->aAttributes['databag'][$sMethod] ?? |
|
| 75 | - $this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 76 | - } |
|
| 72 | +public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 73 | +{ |
|
| 74 | +return $this->aAttributes['databag'][$sMethod] ?? |
|
| 75 | +$this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 76 | +} |
|
| 77 | 77 | |
| 78 | - /** |
|
| 78 | +/** |
|
| 79 | 79 | * @param string $sMethod |
| 80 | 80 | * |
| 81 | 81 | * @return Data\CallbackData |
| 82 | 82 | */ |
| 83 | - public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 84 | - { |
|
| 85 | - return $this->aAttributes['callback'][$sMethod] ?? |
|
| 86 | - $this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 87 | - } |
|
| 83 | +public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 84 | +{ |
|
| 85 | +return $this->aAttributes['callback'][$sMethod] ?? |
|
| 86 | +$this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 87 | +} |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | +/** |
|
| 90 | 90 | * @param string $sMethod |
| 91 | 91 | * |
| 92 | 92 | * @return Data\BeforeData |
| 93 | 93 | */ |
| 94 | - public function before(string $sMethod = '*'): Data\BeforeData |
|
| 95 | - { |
|
| 96 | - return $this->aAttributes['before'][$sMethod] ?? |
|
| 97 | - $this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 98 | - } |
|
| 94 | +public function before(string $sMethod = '*'): Data\BeforeData |
|
| 95 | +{ |
|
| 96 | +return $this->aAttributes['before'][$sMethod] ?? |
|
| 97 | +$this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 98 | +} |
|
| 99 | 99 | |
| 100 | - /** |
|
| 100 | +/** |
|
| 101 | 101 | * @param string $sMethod |
| 102 | 102 | * |
| 103 | 103 | * @return Data\AfterData |
| 104 | 104 | */ |
| 105 | - public function after(string $sMethod = '*'): Data\AfterData |
|
| 106 | - { |
|
| 107 | - return $this->aAttributes['after'][$sMethod] ?? |
|
| 108 | - $this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 109 | - } |
|
| 105 | +public function after(string $sMethod = '*'): Data\AfterData |
|
| 106 | +{ |
|
| 107 | +return $this->aAttributes['after'][$sMethod] ?? |
|
| 108 | +$this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 109 | +} |
|
| 110 | 110 | |
| 111 | - /** |
|
| 111 | +/** |
|
| 112 | 112 | * @param string $sMethod |
| 113 | 113 | * |
| 114 | 114 | * @return Data\UploadData |
| 115 | 115 | */ |
| 116 | - public function upload(string $sMethod = '*'): Data\UploadData |
|
| 117 | - { |
|
| 118 | - return $this->aAttributes['upload'][$sMethod] ?? |
|
| 119 | - $this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 120 | - } |
|
| 116 | +public function upload(string $sMethod = '*'): Data\UploadData |
|
| 117 | +{ |
|
| 118 | +return $this->aAttributes['upload'][$sMethod] ?? |
|
| 119 | +$this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 120 | +} |
|
| 121 | 121 | |
| 122 | - /** |
|
| 122 | +/** |
|
| 123 | 123 | * True if the class is excluded |
| 124 | 124 | * |
| 125 | 125 | * @return bool |
| 126 | 126 | */ |
| 127 | - public function isExcluded(): bool |
|
| 128 | - { |
|
| 129 | - $xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 130 | - return $xData !== null && $xData->getValue() === true; |
|
| 131 | - } |
|
| 127 | +public function isExcluded(): bool |
|
| 128 | +{ |
|
| 129 | +$xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 130 | +return $xData !== null && $xData->getValue() === true; |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get the properties of the class methods |
| 135 | 135 | * |
| 136 | 136 | * @return array |
| 137 | 137 | */ |
| 138 | - public function getProperties(): array |
|
| 138 | +public function getProperties(): array |
|
| 139 | +{ |
|
| 140 | +$aProperties = []; |
|
| 141 | +$aClassProperties = []; |
|
| 142 | +foreach($this->aAttributes as $sType => $aValues) |
|
| 143 | +{ |
|
| 144 | +if($sType === 'exclude') |
|
| 145 | +{ |
|
| 146 | + continue; |
|
| 147 | +} |
|
| 148 | + |
|
| 149 | +foreach($aValues as $sMethod => $xData) |
|
| 150 | +{ |
|
| 151 | + if($sMethod === '*') |
|
| 139 | 152 | { |
| 140 | - $aProperties = []; |
|
| 141 | - $aClassProperties = []; |
|
| 142 | - foreach($this->aAttributes as $sType => $aValues) |
|
| 143 | - { |
|
| 144 | - if($sType === 'exclude') |
|
| 145 | - { |
|
| 146 | - continue; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - foreach($aValues as $sMethod => $xData) |
|
| 150 | - { |
|
| 151 | - if($sMethod === '*') |
|
| 152 | - { |
|
| 153 | - $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 154 | - continue; |
|
| 155 | - } |
|
| 156 | - $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if(count($aClassProperties) > 0) |
|
| 161 | - { |
|
| 162 | - $aProperties['*'] = $aClassProperties; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $aProperties; |
|
| 153 | + $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 154 | + continue; |
|
| 166 | 155 | } |
| 156 | + $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 157 | +} |
|
| 158 | +} |
|
| 159 | + |
|
| 160 | +if(count($aClassProperties) > 0) |
|
| 161 | +{ |
|
| 162 | +$aProperties['*'] = $aClassProperties; |
|
| 163 | +} |
|
| 164 | + |
|
| 165 | +return $aProperties; |
|
| 166 | +} |
|
| 167 | 167 | |
| 168 | - /** |
|
| 168 | +/** |
|
| 169 | 169 | * Get the protected methods |
| 170 | 170 | * |
| 171 | 171 | * @return array |
| 172 | 172 | */ |
| 173 | - public function getProtectedMethods(): array |
|
| 174 | - { |
|
| 175 | - /** @var array<Data\ExcludeData> */ |
|
| 176 | - $aAttributes = $this->aAttributes['exclude']; |
|
| 177 | - $aMethods = array_keys($aAttributes); |
|
| 178 | - return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 179 | - $sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 180 | - } |
|
| 173 | +public function getProtectedMethods(): array |
|
| 174 | +{ |
|
| 175 | +/** @var array<Data\ExcludeData> */ |
|
| 176 | +$aAttributes = $this->aAttributes['exclude']; |
|
| 177 | +$aMethods = array_keys($aAttributes); |
|
| 178 | +return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 179 | +$sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 180 | +} |
|
| 181 | 181 | } |
@@ -16,27 +16,27 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | function _register(): void |
| 18 | 18 | { |
| 19 | - $di = jaxon()->di(); |
|
| 19 | +$di = jaxon()->di(); |
|
| 20 | 20 | |
| 21 | - $di->set(AnnotationReader::class, function($c) { |
|
| 22 | - $sKey = 'jaxon_annotations_cache_dir'; |
|
| 23 | - $sCacheDir = $c->h($sKey) ? $c->g($sKey) : sys_get_temp_dir(); |
|
| 24 | - $xAnnotationManager = new AnnotationManager(); |
|
| 25 | - $xAnnotationManager->cache = new AnnotationCache($sCacheDir); |
|
| 21 | +$di->set(AnnotationReader::class, function($c) { |
|
| 22 | +$sKey = 'jaxon_annotations_cache_dir'; |
|
| 23 | +$sCacheDir = $c->h($sKey) ? $c->g($sKey) : sys_get_temp_dir(); |
|
| 24 | +$xAnnotationManager = new AnnotationManager(); |
|
| 25 | +$xAnnotationManager->cache = new AnnotationCache($sCacheDir); |
|
| 26 | 26 | |
| 27 | - return new AnnotationReader($xAnnotationManager); |
|
| 28 | - }); |
|
| 27 | +return new AnnotationReader($xAnnotationManager); |
|
| 28 | +}); |
|
| 29 | 29 | |
| 30 | - $di->alias('metadata_reader_annotations', AnnotationReader::class); |
|
| 30 | +$di->alias('metadata_reader_annotations', AnnotationReader::class); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | function register(): void |
| 34 | 34 | { |
| 35 | - // Do nothing if running in cli. |
|
| 36 | - if(php_sapi_name() !== 'cli') |
|
| 37 | - { |
|
| 38 | - _register(); |
|
| 39 | - }; |
|
| 35 | +// Do nothing if running in cli. |
|
| 36 | +if(php_sapi_name() !== 'cli') |
|
| 37 | +{ |
|
| 38 | +_register(); |
|
| 39 | +}; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | register(); |
@@ -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 | } |
@@ -20,61 +20,61 @@ |
||
| 20 | 20 | |
| 21 | 21 | class UploadData extends AbstractData |
| 22 | 22 | { |
| 23 | - /** |
|
| 23 | +/** |
|
| 24 | 24 | * The id of the upload field |
| 25 | 25 | * |
| 26 | 26 | * @var string |
| 27 | 27 | */ |
| 28 | - protected $sField = ''; |
|
| 28 | +protected $sField = ''; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function getName(): string |
|
| 34 | - { |
|
| 35 | - return 'upload'; |
|
| 36 | - } |
|
| 33 | +public function getName(): string |
|
| 34 | +{ |
|
| 35 | +return 'upload'; |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @return mixed |
| 40 | 40 | */ |
| 41 | - public function getValue(): mixed |
|
| 42 | - { |
|
| 43 | - // The field id is surrounded with simple quotes. |
|
| 44 | - return "'{$this->sField}'"; |
|
| 45 | - } |
|
| 41 | +public function getValue(): mixed |
|
| 42 | +{ |
|
| 43 | +// The field id is surrounded with simple quotes. |
|
| 44 | +return "'{$this->sField}'"; |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @param string $sField |
| 49 | 49 | * |
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | - protected function validateField(string $sField): void |
|
| 53 | - { |
|
| 54 | - if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sField) > 0) |
|
| 55 | - { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - throw new SetupException("$sField is not a valid \"field\" value for upload"); |
|
| 59 | - } |
|
| 52 | +protected function validateField(string $sField): void |
|
| 53 | +{ |
|
| 54 | +if(preg_match('/^[a-zA-Z][a-zA-Z0-9_\-\.]*$/', $sField) > 0) |
|
| 55 | +{ |
|
| 56 | +return; |
|
| 57 | +} |
|
| 58 | +throw new SetupException("$sField is not a valid \"field\" value for upload"); |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @param string $sField |
| 63 | 63 | * |
| 64 | 64 | * @return void |
| 65 | 65 | */ |
| 66 | - public function setValue(string $sField): void |
|
| 67 | - { |
|
| 68 | - $this->validateField($sField); |
|
| 66 | +public function setValue(string $sField): void |
|
| 67 | +{ |
|
| 68 | +$this->validateField($sField); |
|
| 69 | 69 | |
| 70 | - $this->sField = $sField; |
|
| 71 | - } |
|
| 70 | +$this->sField = $sField; |
|
| 71 | +} |
|
| 72 | 72 | |
| 73 | - /** |
|
| 73 | +/** |
|
| 74 | 74 | * @inheritDoc |
| 75 | 75 | */ |
| 76 | - public function encode(string $sVarName): array |
|
| 77 | - { |
|
| 78 | - return ["{$sVarName}->setValue('{$this->sField}');"]; |
|
| 79 | - } |
|
| 76 | +public function encode(string $sVarName): array |
|
| 77 | +{ |
|
| 78 | +return ["{$sVarName}->setValue('{$this->sField}');"]; |
|
| 79 | +} |
|
| 80 | 80 | } |
@@ -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 string |
| 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 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | class PackageManager |
| 36 | 36 | { |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The constructor |
| 39 | 39 | * |
| 40 | 40 | * @param Container $di |
@@ -46,48 +46,48 @@ discard block |
||
| 46 | 46 | * @param CallbackManager $xCallbackManager |
| 47 | 47 | * @param ComponentRegistry $xRegistry |
| 48 | 48 | */ |
| 49 | - public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | - private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | - private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | - private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | - {} |
|
| 49 | +public function __construct(private Container $di, private Translator $xTranslator, |
|
| 50 | +private PluginManager $xPluginManager, private ConfigManager $xConfigManager, |
|
| 51 | +private CodeGenerator $xCodeGenerator, private ViewRenderer $xViewRenderer, |
|
| 52 | +private CallbackManager $xCallbackManager, private ComponentRegistry $xRegistry) |
|
| 53 | +{} |
|
| 54 | 54 | |
| 55 | - /** |
|
| 55 | +/** |
|
| 56 | 56 | * Save items in the DI container |
| 57 | 57 | * |
| 58 | 58 | * @param Config $xConfig |
| 59 | 59 | * |
| 60 | 60 | * @return void |
| 61 | 61 | */ |
| 62 | - private function updateContainer(Config $xConfig): void |
|
| 63 | - { |
|
| 64 | - $aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | - foreach($aOptions as $xKey => $xValue) |
|
| 66 | - { |
|
| 67 | - // The key is the class name. It must be a string. |
|
| 68 | - $this->di->set((string)$xKey, $xValue); |
|
| 69 | - } |
|
| 70 | - $aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | - foreach($aOptions as $xKey => $xValue) |
|
| 72 | - { |
|
| 73 | - // The key is the class name. It must be a string. |
|
| 74 | - $this->di->val((string)$xKey, $xValue); |
|
| 75 | - } |
|
| 76 | - $aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | - foreach($aOptions as $xValue) |
|
| 78 | - { |
|
| 79 | - // The key is the class name. It must be a string. |
|
| 80 | - $this->di->auto((string)$xValue); |
|
| 81 | - } |
|
| 82 | - $aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | - foreach($aOptions as $xKey => $xValue) |
|
| 84 | - { |
|
| 85 | - // The key is the class name. It must be a string. |
|
| 86 | - $this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | - } |
|
| 88 | - } |
|
| 62 | +private function updateContainer(Config $xConfig): void |
|
| 63 | +{ |
|
| 64 | +$aOptions = $xConfig->getOption('container.set', []); |
|
| 65 | +foreach($aOptions as $xKey => $xValue) |
|
| 66 | +{ |
|
| 67 | +// The key is the class name. It must be a string. |
|
| 68 | +$this->di->set((string)$xKey, $xValue); |
|
| 69 | +} |
|
| 70 | +$aOptions = $xConfig->getOption('container.val', []); |
|
| 71 | +foreach($aOptions as $xKey => $xValue) |
|
| 72 | +{ |
|
| 73 | +// The key is the class name. It must be a string. |
|
| 74 | +$this->di->val((string)$xKey, $xValue); |
|
| 75 | +} |
|
| 76 | +$aOptions = $xConfig->getOption('container.auto', []); |
|
| 77 | +foreach($aOptions as $xValue) |
|
| 78 | +{ |
|
| 79 | +// The key is the class name. It must be a string. |
|
| 80 | +$this->di->auto((string)$xValue); |
|
| 81 | +} |
|
| 82 | +$aOptions = $xConfig->getOption('container.alias', []); |
|
| 83 | +foreach($aOptions as $xKey => $xValue) |
|
| 84 | +{ |
|
| 85 | +// The key is the class name. It must be a string. |
|
| 86 | +$this->di->alias((string)$xKey, (string)$xValue); |
|
| 87 | +} |
|
| 88 | +} |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | +/** |
|
| 91 | 91 | * Register callables from a section of the config |
| 92 | 92 | * |
| 93 | 93 | * @param array $aOptions The content of the config section |
@@ -96,41 +96,41 @@ discard block |
||
| 96 | 96 | * @return void |
| 97 | 97 | * @throws SetupException |
| 98 | 98 | */ |
| 99 | - private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | - { |
|
| 101 | - foreach($aOptions as $xKey => $xValue) |
|
| 102 | - { |
|
| 103 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | - { |
|
| 105 | - // Register a function without options |
|
| 106 | - $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | - continue; |
|
| 108 | - } |
|
| 99 | +private function registerCallables(array $aOptions, string $sCallableType): void |
|
| 100 | +{ |
|
| 101 | +foreach($aOptions as $xKey => $xValue) |
|
| 102 | +{ |
|
| 103 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 104 | +{ |
|
| 105 | + // Register a function without options |
|
| 106 | + $this->xPluginManager->registerCallable($sCallableType, $xValue); |
|
| 107 | + continue; |
|
| 108 | +} |
|
| 109 | 109 | |
| 110 | - if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | - { |
|
| 112 | - // Register a function with options |
|
| 113 | - $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | +if(is_string($xKey) && (is_array($xValue) || is_string($xValue))) |
|
| 111 | +{ |
|
| 112 | + // Register a function with options |
|
| 113 | + $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue); |
|
| 114 | +} |
|
| 115 | +} |
|
| 116 | +} |
|
| 117 | 117 | |
| 118 | - /** |
|
| 118 | +/** |
|
| 119 | 119 | * Register exceptions handlers |
| 120 | 120 | * |
| 121 | 121 | * @param Config $xConfig |
| 122 | 122 | * |
| 123 | 123 | * @return void |
| 124 | 124 | */ |
| 125 | - private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | - { |
|
| 127 | - foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | - { |
|
| 129 | - $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | - } |
|
| 131 | - } |
|
| 125 | +private function registerExceptionHandlers(Config $xConfig): void |
|
| 126 | +{ |
|
| 127 | +foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler) |
|
| 128 | +{ |
|
| 129 | +$this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : ''); |
|
| 130 | +} |
|
| 131 | +} |
|
| 132 | 132 | |
| 133 | - /** |
|
| 133 | +/** |
|
| 134 | 134 | * Get a callable list from config |
| 135 | 135 | * |
| 136 | 136 | * @param Config $xConfig |
@@ -140,36 +140,36 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | - private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | - string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | - { |
|
| 146 | - // The callable (directory path, class or function name) can be used as the |
|
| 147 | - // key of the array item, a string as the value of an entry without a key, |
|
| 148 | - // or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | - $aCallables = []; |
|
| 150 | - foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | - { |
|
| 152 | - if(is_string($xKey)) |
|
| 153 | - { |
|
| 154 | - $aCallables[$xKey] = $xValue; |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - if(is_string($xValue)) |
|
| 158 | - { |
|
| 159 | - $aCallables[] = $xValue; |
|
| 160 | - continue; |
|
| 161 | - } |
|
| 143 | +private function registerCallablesFromConfig(Config $xConfig, |
|
| 144 | +string $sOptionName, string $sOptionKey, string $sCallableType): void |
|
| 145 | +{ |
|
| 146 | +// The callable (directory path, class or function name) can be used as the |
|
| 147 | +// key of the array item, a string as the value of an entry without a key, |
|
| 148 | +// or set with the key $sOptionKey in an array entry without a key. |
|
| 149 | +$aCallables = []; |
|
| 150 | +foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue) |
|
| 151 | +{ |
|
| 152 | +if(is_string($xKey)) |
|
| 153 | +{ |
|
| 154 | + $aCallables[$xKey] = $xValue; |
|
| 155 | + continue; |
|
| 156 | +} |
|
| 157 | +if(is_string($xValue)) |
|
| 158 | +{ |
|
| 159 | + $aCallables[] = $xValue; |
|
| 160 | + continue; |
|
| 161 | +} |
|
| 162 | 162 | |
| 163 | - if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | - { |
|
| 165 | - $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | - } |
|
| 167 | - // Invalid values are ignored. |
|
| 168 | - } |
|
| 169 | - $this->registerCallables($aCallables, $sCallableType); |
|
| 170 | - } |
|
| 163 | +if(is_array($xValue) && isset($xValue[$sOptionKey])) |
|
| 164 | +{ |
|
| 165 | + $aCallables[$xValue[$sOptionKey]] = $xValue; |
|
| 166 | +} |
|
| 167 | +// Invalid values are ignored. |
|
| 168 | +} |
|
| 169 | +$this->registerCallables($aCallables, $sCallableType); |
|
| 170 | +} |
|
| 171 | 171 | |
| 172 | - /** |
|
| 172 | +/** |
|
| 173 | 173 | * Read and set Jaxon options from a JSON config file |
| 174 | 174 | * |
| 175 | 175 | * @param Config $xConfig The config options |
@@ -177,33 +177,33 @@ discard block |
||
| 177 | 177 | * @return void |
| 178 | 178 | * @throws SetupException |
| 179 | 179 | */ |
| 180 | - private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | - { |
|
| 182 | - // Set the config for the registered callables. |
|
| 183 | - $this->xRegistry->setPackageConfig($xConfig); |
|
| 180 | +private function registerItemsFromConfig(Config $xConfig): void |
|
| 181 | +{ |
|
| 182 | +// Set the config for the registered callables. |
|
| 183 | +$this->xRegistry->setPackageConfig($xConfig); |
|
| 184 | 184 | |
| 185 | - // Register functions, classes and directories |
|
| 186 | - $this->registerCallablesFromConfig($xConfig, |
|
| 187 | - 'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | - $this->registerCallablesFromConfig($xConfig, |
|
| 189 | - 'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | - $this->registerCallablesFromConfig($xConfig, |
|
| 191 | - 'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 185 | +// Register functions, classes and directories |
|
| 186 | +$this->registerCallablesFromConfig($xConfig, |
|
| 187 | +'functions', 'name', Jaxon::CALLABLE_FUNCTION); |
|
| 188 | +$this->registerCallablesFromConfig($xConfig, |
|
| 189 | +'classes', 'name', Jaxon::CALLABLE_CLASS); |
|
| 190 | +$this->registerCallablesFromConfig($xConfig, |
|
| 191 | +'directories', 'path', Jaxon::CALLABLE_DIR); |
|
| 192 | 192 | |
| 193 | - // Unset the current config. |
|
| 194 | - $this->xRegistry->unsetPackageConfig(); |
|
| 193 | +// Unset the current config. |
|
| 194 | +$this->xRegistry->unsetPackageConfig(); |
|
| 195 | 195 | |
| 196 | - // Register the view namespaces |
|
| 197 | - // Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | - // the user defined view namespaces. That's why it is needed here. |
|
| 199 | - $this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | - // Save items in the DI container |
|
| 201 | - $this->updateContainer($xConfig); |
|
| 202 | - // Register the exception handlers |
|
| 203 | - $this->registerExceptionHandlers($xConfig); |
|
| 204 | - } |
|
| 196 | +// Register the view namespaces |
|
| 197 | +// Note: the $xUserConfig can provide a "template" option, which is used to customize |
|
| 198 | +// the user defined view namespaces. That's why it is needed here. |
|
| 199 | +$this->xViewRenderer->addNamespaces($xConfig); |
|
| 200 | +// Save items in the DI container |
|
| 201 | +$this->updateContainer($xConfig); |
|
| 202 | +// Register the exception handlers |
|
| 203 | +$this->registerExceptionHandlers($xConfig); |
|
| 204 | +} |
|
| 205 | 205 | |
| 206 | - /** |
|
| 206 | +/** |
|
| 207 | 207 | * Get the options provided by the package library |
| 208 | 208 | * |
| 209 | 209 | * @param class-string $sClassName The package class |
@@ -211,27 +211,27 @@ discard block |
||
| 211 | 211 | * @return Config |
| 212 | 212 | * @throws SetupException |
| 213 | 213 | */ |
| 214 | - private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | - { |
|
| 216 | - // $this->aPackages contains packages config file paths. |
|
| 217 | - $aLibOptions = $sClassName::config(); |
|
| 218 | - if(is_string($aLibOptions)) |
|
| 219 | - { |
|
| 220 | - // A string is supposed to be the path to a config file. |
|
| 221 | - $aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | - } |
|
| 223 | - elseif(!is_array($aLibOptions)) |
|
| 224 | - { |
|
| 225 | - // Otherwise, anything else than an array is not accepted. |
|
| 226 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | - throw new SetupException($sMessage); |
|
| 228 | - } |
|
| 229 | - // Add the package name to the config |
|
| 230 | - $aLibOptions['package'] = $sClassName; |
|
| 231 | - return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | - } |
|
| 214 | +private function getPackageLibConfig(string $sClassName): Config |
|
| 215 | +{ |
|
| 216 | +// $this->aPackages contains packages config file paths. |
|
| 217 | +$aLibOptions = $sClassName::config(); |
|
| 218 | +if(is_string($aLibOptions)) |
|
| 219 | +{ |
|
| 220 | +// A string is supposed to be the path to a config file. |
|
| 221 | +$aLibOptions = $this->xConfigManager->read($aLibOptions); |
|
| 222 | +} |
|
| 223 | +elseif(!is_array($aLibOptions)) |
|
| 224 | +{ |
|
| 225 | +// Otherwise, anything else than an array is not accepted. |
|
| 226 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 227 | +throw new SetupException($sMessage); |
|
| 228 | +} |
|
| 229 | +// Add the package name to the config |
|
| 230 | +$aLibOptions['package'] = $sClassName; |
|
| 231 | +return $this->xConfigManager->newConfig($aLibOptions); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 234 | +/** |
|
| 235 | 235 | * Register a package |
| 236 | 236 | * |
| 237 | 237 | * @param class-string $sClassName The package class |
@@ -240,27 +240,27 @@ discard block |
||
| 240 | 240 | * @return void |
| 241 | 241 | * @throws SetupException |
| 242 | 242 | */ |
| 243 | - public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | - { |
|
| 245 | - $sClassName = trim($sClassName, '\\ '); |
|
| 246 | - if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | - { |
|
| 248 | - $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | - throw new SetupException($sMessage); |
|
| 250 | - } |
|
| 243 | +public function registerPackage(string $sClassName, array $aUserOptions = []): void |
|
| 244 | +{ |
|
| 245 | +$sClassName = trim($sClassName, '\\ '); |
|
| 246 | +if(!is_subclass_of($sClassName, AbstractPackage::class)) |
|
| 247 | +{ |
|
| 248 | +$sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]); |
|
| 249 | +throw new SetupException($sMessage); |
|
| 250 | +} |
|
| 251 | 251 | |
| 252 | - // Register the declarations in the package config. |
|
| 253 | - $xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 252 | +// Register the declarations in the package config. |
|
| 253 | +$xAppConfig = $this->getPackageLibConfig($sClassName); |
|
| 254 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 255 | 255 | |
| 256 | - // Register the package and its options in the DI |
|
| 257 | - $this->di->registerPackage($sClassName, $aUserOptions); |
|
| 256 | +// Register the package and its options in the DI |
|
| 257 | +$this->di->registerPackage($sClassName, $aUserOptions); |
|
| 258 | 258 | |
| 259 | - // Register the package as a code generator. |
|
| 260 | - $this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | - } |
|
| 259 | +// Register the package as a code generator. |
|
| 260 | +$this->xCodeGenerator->addCodeGenerator($sClassName, 500); |
|
| 261 | +} |
|
| 262 | 262 | |
| 263 | - /** |
|
| 263 | +/** |
|
| 264 | 264 | * Get a package instance |
| 265 | 265 | * |
| 266 | 266 | * @template T of AbstractPackage |
@@ -268,42 +268,42 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * @return T|null |
| 270 | 270 | */ |
| 271 | - public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | - { |
|
| 273 | - $sClassName = trim($sClassName, '\\ '); |
|
| 274 | - return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | - } |
|
| 271 | +public function getPackage(string $sClassName): ?AbstractPackage |
|
| 272 | +{ |
|
| 273 | +$sClassName = trim($sClassName, '\\ '); |
|
| 274 | +return $this->di->h($sClassName) ? $this->di->g($sClassName) : null; |
|
| 275 | +} |
|
| 276 | 276 | |
| 277 | - /** |
|
| 277 | +/** |
|
| 278 | 278 | * Read and set Jaxon options from the config |
| 279 | 279 | * |
| 280 | 280 | * @return void |
| 281 | 281 | * @throws SetupException |
| 282 | 282 | */ |
| 283 | - public function registerFromConfig(): void |
|
| 284 | - { |
|
| 285 | - $xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | - $this->registerItemsFromConfig($xAppConfig); |
|
| 283 | +public function registerFromConfig(): void |
|
| 284 | +{ |
|
| 285 | +$xAppConfig = $this->xConfigManager->getAppConfig(); |
|
| 286 | +$this->registerItemsFromConfig($xAppConfig); |
|
| 287 | 287 | |
| 288 | - // Register packages |
|
| 289 | - $aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | - foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | - { |
|
| 292 | - if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | - { |
|
| 294 | - // Register a package without options |
|
| 295 | - $sClassName = $xValue; |
|
| 296 | - $this->registerPackage($sClassName); |
|
| 297 | - continue; |
|
| 298 | - } |
|
| 288 | +// Register packages |
|
| 289 | +$aPackageConfig = $xAppConfig->getOption('packages', []); |
|
| 290 | +foreach($aPackageConfig as $xKey => $xValue) |
|
| 291 | +{ |
|
| 292 | +if(is_integer($xKey) && is_string($xValue)) |
|
| 293 | +{ |
|
| 294 | + // Register a package without options |
|
| 295 | + $sClassName = $xValue; |
|
| 296 | + $this->registerPackage($sClassName); |
|
| 297 | + continue; |
|
| 298 | +} |
|
| 299 | 299 | |
| 300 | - if(is_string($xKey) && is_array($xValue)) |
|
| 301 | - { |
|
| 302 | - // Register a package with options |
|
| 303 | - $sClassName = $xKey; |
|
| 304 | - $aPkgOptions = $xValue; |
|
| 305 | - $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 300 | +if(is_string($xKey) && is_array($xValue)) |
|
| 301 | +{ |
|
| 302 | + // Register a package with options |
|
| 303 | + $sClassName = $xKey; |
|
| 304 | + $aPkgOptions = $xValue; |
|
| 305 | + $this->registerPackage($sClassName, $aPkgOptions); |
|
| 306 | +} |
|
| 307 | +} |
|
| 308 | +} |
|
| 309 | 309 | } |
@@ -27,56 +27,56 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | class ComponentOptions |
| 29 | 29 | { |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * Check if the js code for this object must be generated |
| 32 | 32 | * |
| 33 | 33 | * @var bool |
| 34 | 34 | */ |
| 35 | - private $bExcluded = false; |
|
| 35 | +private $bExcluded = false; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 37 | +/** |
|
| 38 | 38 | * The character to use as separator in javascript class names |
| 39 | 39 | * |
| 40 | 40 | * @var string |
| 41 | 41 | */ |
| 42 | - private $sSeparator = '.'; |
|
| 42 | +private $sSeparator = '.'; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | +/** |
|
| 45 | 45 | * A list of methods of the user registered callable object the library must not export to javascript |
| 46 | 46 | * |
| 47 | 47 | * @var array |
| 48 | 48 | */ |
| 49 | - private $aProtectedMethods = []; |
|
| 49 | +private $aProtectedMethods = []; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | +/** |
|
| 52 | 52 | * A list of methods to call before processing the request |
| 53 | 53 | * |
| 54 | 54 | * @var array |
| 55 | 55 | */ |
| 56 | - private $aBeforeMethods = []; |
|
| 56 | +private $aBeforeMethods = []; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 58 | +/** |
|
| 59 | 59 | * A list of methods to call after processing the request |
| 60 | 60 | * |
| 61 | 61 | * @var array |
| 62 | 62 | */ |
| 63 | - private $aAfterMethods = []; |
|
| 63 | +private $aAfterMethods = []; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | +/** |
|
| 66 | 66 | * The javascript class options |
| 67 | 67 | * |
| 68 | 68 | * @var array |
| 69 | 69 | */ |
| 70 | - private $aJsOptions = []; |
|
| 70 | +private $aJsOptions = []; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 72 | +/** |
|
| 73 | 73 | * The DI options |
| 74 | 74 | * |
| 75 | 75 | * @var array |
| 76 | 76 | */ |
| 77 | - private $aDiOptions = []; |
|
| 77 | +private $aDiOptions = []; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * The constructor |
| 81 | 81 | * |
| 82 | 82 | * @param array $aOptions |
@@ -84,119 +84,119 @@ discard block |
||
| 84 | 84 | * @param array $aProtectedMethods |
| 85 | 85 | * @param array $aProperties |
| 86 | 86 | */ |
| 87 | - public function __construct(array $aOptions, bool $bExcluded = false, |
|
| 88 | - array $aProtectedMethods = [], array $aProperties = []) |
|
| 89 | - { |
|
| 90 | - $this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
| 91 | - if($this->bExcluded) |
|
| 92 | - { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 87 | +public function __construct(array $aOptions, bool $bExcluded = false, |
|
| 88 | +array $aProtectedMethods = [], array $aProperties = []) |
|
| 89 | +{ |
|
| 90 | +$this->bExcluded = $bExcluded || (bool)($aOptions['excluded'] ?? false); |
|
| 91 | +if($this->bExcluded) |
|
| 92 | +{ |
|
| 93 | +return; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - $sSeparator = $aOptions['separator']; |
|
| 97 | - if($sSeparator === '_' || $sSeparator === '.') |
|
| 98 | - { |
|
| 99 | - $this->sSeparator = $sSeparator; |
|
| 100 | - } |
|
| 101 | - $this->addProtectedMethods($aOptions['protected']); |
|
| 102 | - $this->addProtectedMethods($aProtectedMethods); |
|
| 96 | +$sSeparator = $aOptions['separator']; |
|
| 97 | +if($sSeparator === '_' || $sSeparator === '.') |
|
| 98 | +{ |
|
| 99 | +$this->sSeparator = $sSeparator; |
|
| 100 | +} |
|
| 101 | +$this->addProtectedMethods($aOptions['protected']); |
|
| 102 | +$this->addProtectedMethods($aProtectedMethods); |
|
| 103 | 103 | |
| 104 | - foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 105 | - { |
|
| 106 | - // Names are in a comma-separated list. |
|
| 107 | - $aFunctionNames = explode(',', $sNames); |
|
| 108 | - foreach($aFunctionNames as $sFunctionName) |
|
| 109 | - { |
|
| 110 | - $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - foreach($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 114 | - { |
|
| 115 | - $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 116 | - } |
|
| 117 | - } |
|
| 104 | +foreach($aOptions['functions'] as $sNames => $aFunctionOptions) |
|
| 105 | +{ |
|
| 106 | +// Names are in a comma-separated list. |
|
| 107 | +$aFunctionNames = explode(',', $sNames); |
|
| 108 | +foreach($aFunctionNames as $sFunctionName) |
|
| 109 | +{ |
|
| 110 | + $this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 111 | +} |
|
| 112 | +} |
|
| 113 | +foreach($aProperties as $sFunctionName => $aFunctionOptions) |
|
| 114 | +{ |
|
| 115 | +$this->addFunctionOptions($sFunctionName, $aFunctionOptions); |
|
| 116 | +} |
|
| 117 | +} |
|
| 118 | 118 | |
| 119 | - /** |
|
| 119 | +/** |
|
| 120 | 120 | * @param array|string $xMethods |
| 121 | 121 | * |
| 122 | 122 | * @return void |
| 123 | 123 | */ |
| 124 | - private function addProtectedMethods(array|string $xMethods): void |
|
| 125 | - { |
|
| 126 | - if(!is_array($xMethods)) |
|
| 127 | - { |
|
| 128 | - $this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
| 129 | - return; |
|
| 130 | - } |
|
| 124 | +private function addProtectedMethods(array|string $xMethods): void |
|
| 125 | +{ |
|
| 126 | +if(!is_array($xMethods)) |
|
| 127 | +{ |
|
| 128 | +$this->aProtectedMethods[trim((string)$xMethods)] = true; |
|
| 129 | +return; |
|
| 130 | +} |
|
| 131 | 131 | |
| 132 | - foreach($xMethods as $sMethod) |
|
| 133 | - { |
|
| 134 | - $this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
| 135 | - } |
|
| 136 | - } |
|
| 132 | +foreach($xMethods as $sMethod) |
|
| 133 | +{ |
|
| 134 | +$this->aProtectedMethods[trim((string)$sMethod)] = true; |
|
| 135 | +} |
|
| 136 | +} |
|
| 137 | 137 | |
| 138 | - /** |
|
| 138 | +/** |
|
| 139 | 139 | * @param string $sMethodName |
| 140 | 140 | * |
| 141 | 141 | * @return bool |
| 142 | 142 | */ |
| 143 | - public function isProtectedMethod(string $sMethodName): bool |
|
| 144 | - { |
|
| 145 | - return isset($this->aProtectedMethods['*']) || |
|
| 146 | - isset($this->aProtectedMethods[$sMethodName]); |
|
| 147 | - } |
|
| 143 | +public function isProtectedMethod(string $sMethodName): bool |
|
| 144 | +{ |
|
| 145 | +return isset($this->aProtectedMethods['*']) || |
|
| 146 | +isset($this->aProtectedMethods[$sMethodName]); |
|
| 147 | +} |
|
| 148 | 148 | |
| 149 | - /** |
|
| 149 | +/** |
|
| 150 | 150 | * Check if the js code for this object must be generated |
| 151 | 151 | * |
| 152 | 152 | * @return bool |
| 153 | 153 | */ |
| 154 | - public function excluded(): bool |
|
| 155 | - { |
|
| 156 | - return $this->bExcluded; |
|
| 157 | - } |
|
| 154 | +public function excluded(): bool |
|
| 155 | +{ |
|
| 156 | +return $this->bExcluded; |
|
| 157 | +} |
|
| 158 | 158 | |
| 159 | - /** |
|
| 159 | +/** |
|
| 160 | 160 | * @return string |
| 161 | 161 | */ |
| 162 | - public function separator(): string |
|
| 163 | - { |
|
| 164 | - return $this->sSeparator; |
|
| 165 | - } |
|
| 162 | +public function separator(): string |
|
| 163 | +{ |
|
| 164 | +return $this->sSeparator; |
|
| 165 | +} |
|
| 166 | 166 | |
| 167 | - /** |
|
| 167 | +/** |
|
| 168 | 168 | * @return array |
| 169 | 169 | */ |
| 170 | - public function beforeMethods(): array |
|
| 171 | - { |
|
| 172 | - return $this->aBeforeMethods; |
|
| 173 | - } |
|
| 170 | +public function beforeMethods(): array |
|
| 171 | +{ |
|
| 172 | +return $this->aBeforeMethods; |
|
| 173 | +} |
|
| 174 | 174 | |
| 175 | - /** |
|
| 175 | +/** |
|
| 176 | 176 | * @return array |
| 177 | 177 | */ |
| 178 | - public function afterMethods(): array |
|
| 179 | - { |
|
| 180 | - return $this->aAfterMethods; |
|
| 181 | - } |
|
| 178 | +public function afterMethods(): array |
|
| 179 | +{ |
|
| 180 | +return $this->aAfterMethods; |
|
| 181 | +} |
|
| 182 | 182 | |
| 183 | - /** |
|
| 183 | +/** |
|
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - public function diOptions(): array |
|
| 187 | - { |
|
| 188 | - return $this->aDiOptions; |
|
| 189 | - } |
|
| 186 | +public function diOptions(): array |
|
| 187 | +{ |
|
| 188 | +return $this->aDiOptions; |
|
| 189 | +} |
|
| 190 | 190 | |
| 191 | - /** |
|
| 191 | +/** |
|
| 192 | 192 | * @return array |
| 193 | 193 | */ |
| 194 | - public function jsOptions(): array |
|
| 195 | - { |
|
| 196 | - return $this->aJsOptions; |
|
| 197 | - } |
|
| 194 | +public function jsOptions(): array |
|
| 195 | +{ |
|
| 196 | +return $this->aJsOptions; |
|
| 197 | +} |
|
| 198 | 198 | |
| 199 | - /** |
|
| 199 | +/** |
|
| 200 | 200 | * Set hook methods |
| 201 | 201 | * |
| 202 | 202 | * @param array $aHookMethods The array of hook methods |
@@ -204,34 +204,34 @@ discard block |
||
| 204 | 204 | * |
| 205 | 205 | * @return void |
| 206 | 206 | */ |
| 207 | - private function setHookMethods(array &$aHookMethods, $xValue): void |
|
| 208 | - { |
|
| 209 | - foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 210 | - { |
|
| 211 | - if(!isset($aHookMethods[$sCalledMethod])) |
|
| 212 | - { |
|
| 213 | - $aHookMethods[$sCalledMethod] = []; |
|
| 214 | - } |
|
| 215 | - if(is_array($xMethodToCall)) |
|
| 216 | - { |
|
| 217 | - $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
|
| 218 | - } |
|
| 219 | - elseif(is_string($xMethodToCall)) |
|
| 220 | - { |
|
| 221 | - $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 207 | +private function setHookMethods(array &$aHookMethods, $xValue): void |
|
| 208 | +{ |
|
| 209 | +foreach($xValue as $sCalledMethod => $xMethodToCall) |
|
| 210 | +{ |
|
| 211 | +if(!isset($aHookMethods[$sCalledMethod])) |
|
| 212 | +{ |
|
| 213 | + $aHookMethods[$sCalledMethod] = []; |
|
| 214 | +} |
|
| 215 | +if(is_array($xMethodToCall)) |
|
| 216 | +{ |
|
| 217 | + $aHookMethods[$sCalledMethod] = array_merge($aHookMethods[$sCalledMethod], $xMethodToCall); |
|
| 218 | +} |
|
| 219 | +elseif(is_string($xMethodToCall)) |
|
| 220 | +{ |
|
| 221 | + $aHookMethods[$sCalledMethod][] = $xMethodToCall; |
|
| 222 | +} |
|
| 223 | +} |
|
| 224 | +} |
|
| 225 | 225 | |
| 226 | - /** |
|
| 226 | +/** |
|
| 227 | 227 | * @param array $aDiOptions |
| 228 | 228 | */ |
| 229 | - private function addDiOption(array $aDiOptions): void |
|
| 230 | - { |
|
| 231 | - $this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions); |
|
| 232 | - } |
|
| 229 | +private function addDiOption(array $aDiOptions): void |
|
| 230 | +{ |
|
| 231 | +$this->aDiOptions = array_merge($this->aDiOptions, $aDiOptions); |
|
| 232 | +} |
|
| 233 | 233 | |
| 234 | - /** |
|
| 234 | +/** |
|
| 235 | 235 | * Set configuration options / call options for each method |
| 236 | 236 | * |
| 237 | 237 | * @param string $sName The name of the configuration option |
@@ -239,25 +239,25 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return void |
| 241 | 241 | */ |
| 242 | - private function addOption(string $sName, $xValue): void |
|
| 243 | - { |
|
| 244 | - switch($sName) |
|
| 245 | - { |
|
| 246 | - // Set the methods to call before processing the request |
|
| 247 | - case '__before': |
|
| 248 | - $this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 249 | - break; |
|
| 250 | - // Set the methods to call after processing the request |
|
| 251 | - case '__after': |
|
| 252 | - $this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 253 | - break; |
|
| 254 | - // Set the attributes to inject in the callable object |
|
| 255 | - case '__di': |
|
| 256 | - $this->addDiOption($xValue); |
|
| 257 | - break; |
|
| 258 | - default: |
|
| 259 | - break; |
|
| 260 | - } |
|
| 242 | +private function addOption(string $sName, $xValue): void |
|
| 243 | +{ |
|
| 244 | +switch($sName) |
|
| 245 | +{ |
|
| 246 | +// Set the methods to call before processing the request |
|
| 247 | +case '__before': |
|
| 248 | +$this->setHookMethods($this->aBeforeMethods, $xValue); |
|
| 249 | +break; |
|
| 250 | +// Set the methods to call after processing the request |
|
| 251 | +case '__after': |
|
| 252 | +$this->setHookMethods($this->aAfterMethods, $xValue); |
|
| 253 | +break; |
|
| 254 | +// Set the attributes to inject in the callable object |
|
| 255 | +case '__di': |
|
| 256 | +$this->addDiOption($xValue); |
|
| 257 | +break; |
|
| 258 | +default: |
|
| 259 | +break; |
|
| 260 | +} |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -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 | } |