@@ -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 | } |
@@ -39,73 +39,73 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | class ComponentContainer |
| 41 | 41 | { |
| 42 | - use Traits\DiAutoTrait; |
|
| 43 | - use Traits\ComponentTrait; |
|
| 42 | +use Traits\DiAutoTrait; |
|
| 43 | +use Traits\ComponentTrait; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 45 | +/** |
|
| 46 | 46 | * The Dependency Injection Container for registered classes |
| 47 | 47 | * |
| 48 | 48 | * @var PimpleContainer |
| 49 | 49 | */ |
| 50 | - private $xContainer; |
|
| 50 | +private $xContainer; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 52 | +/** |
|
| 53 | 53 | * This will be set only when getting the object targetted by the ajax request. |
| 54 | 54 | * |
| 55 | 55 | * @var Target |
| 56 | 56 | */ |
| 57 | - private $xTarget = null; |
|
| 57 | +private $xTarget = null; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * The class constructor |
| 61 | 61 | * |
| 62 | 62 | * @param Container $di |
| 63 | 63 | */ |
| 64 | - public function __construct(private Container $di) |
|
| 65 | - { |
|
| 66 | - $this->xContainer = new PimpleContainer(); |
|
| 67 | - $this->val(ComponentContainer::class, $this); |
|
| 68 | - |
|
| 69 | - // Register the call factory for registered functions |
|
| 70 | - $this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | - new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | - ->getOption('core.prefix.function', ''))); |
|
| 73 | - |
|
| 74 | - // Register the pagination component, but do not export to js. |
|
| 75 | - $this->saveComponent(Pagination::class, [ |
|
| 76 | - 'excluded' => true, |
|
| 77 | - 'separator' => '.', |
|
| 78 | - // The namespace has the same name as the Component class. |
|
| 79 | - 'namespace' => Component::class, |
|
| 80 | - ]); |
|
| 81 | - |
|
| 82 | - $this->setComponentPublicMethods('node', NodeComponent::class); |
|
| 83 | - $this->setComponentPublicMethods('func', FuncComponent::class); |
|
| 84 | - } |
|
| 64 | +public function __construct(private Container $di) |
|
| 65 | +{ |
|
| 66 | +$this->xContainer = new PimpleContainer(); |
|
| 67 | +$this->val(ComponentContainer::class, $this); |
|
| 68 | + |
|
| 69 | +// Register the call factory for registered functions |
|
| 70 | +$this->set($this->getRequestFactoryKey(JxnCall::class), fn() => |
|
| 71 | +new JxnCall($this->di->g(ConfigManager::class) |
|
| 72 | + ->getOption('core.prefix.function', ''))); |
|
| 73 | + |
|
| 74 | +// Register the pagination component, but do not export to js. |
|
| 75 | +$this->saveComponent(Pagination::class, [ |
|
| 76 | +'excluded' => true, |
|
| 77 | +'separator' => '.', |
|
| 78 | +// The namespace has the same name as the Component class. |
|
| 79 | +'namespace' => Component::class, |
|
| 80 | +]); |
|
| 81 | + |
|
| 82 | +$this->setComponentPublicMethods('node', NodeComponent::class); |
|
| 83 | +$this->setComponentPublicMethods('func', FuncComponent::class); |
|
| 84 | +} |
|
| 85 | 85 | |
| 86 | - /** |
|
| 86 | +/** |
|
| 87 | 87 | * The container for parameters |
| 88 | 88 | * |
| 89 | 89 | * @return Container |
| 90 | 90 | */ |
| 91 | - protected function cn(): Container |
|
| 92 | - { |
|
| 93 | - return $this->di; |
|
| 94 | - } |
|
| 91 | +protected function cn(): Container |
|
| 92 | +{ |
|
| 93 | +return $this->di; |
|
| 94 | +} |
|
| 95 | 95 | |
| 96 | - /** |
|
| 96 | +/** |
|
| 97 | 97 | * Check if a class is defined in the container |
| 98 | 98 | * |
| 99 | 99 | * @param class-string $sClass The full class name |
| 100 | 100 | * |
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | - public function has(string $sClass): bool |
|
| 104 | - { |
|
| 105 | - return $this->xContainer->offsetExists($sClass); |
|
| 106 | - } |
|
| 103 | +public function has(string $sClass): bool |
|
| 104 | +{ |
|
| 105 | +return $this->xContainer->offsetExists($sClass); |
|
| 106 | +} |
|
| 107 | 107 | |
| 108 | - /** |
|
| 108 | +/** |
|
| 109 | 109 | * Save a closure in the container |
| 110 | 110 | * |
| 111 | 111 | * @param class-string $sClass The full class name |
@@ -113,12 +113,12 @@ discard block |
||
| 113 | 113 | * |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function set(string $sClass, Closure $xClosure) |
|
| 117 | - { |
|
| 118 | - $this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | - } |
|
| 116 | +public function set(string $sClass, Closure $xClosure) |
|
| 117 | +{ |
|
| 118 | +$this->xContainer->offsetSet($sClass, fn() => $xClosure($this)); |
|
| 119 | +} |
|
| 120 | 120 | |
| 121 | - /** |
|
| 121 | +/** |
|
| 122 | 122 | * Save a value in the container |
| 123 | 123 | * |
| 124 | 124 | * @param string|class-string $sKey The key |
@@ -126,12 +126,12 @@ discard block |
||
| 126 | 126 | * |
| 127 | 127 | * @return void |
| 128 | 128 | */ |
| 129 | - public function val(string $sKey, $xValue) |
|
| 130 | - { |
|
| 131 | - $this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | - } |
|
| 129 | +public function val(string $sKey, $xValue) |
|
| 130 | +{ |
|
| 131 | +$this->xContainer->offsetSet($sKey, $xValue); |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * Get a class instance |
| 136 | 136 | * |
| 137 | 137 | * @template T |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @return T |
| 141 | 141 | */ |
| 142 | - public function get(string $sClass) |
|
| 143 | - { |
|
| 144 | - return $this->xContainer->offsetGet($sClass); |
|
| 145 | - } |
|
| 142 | +public function get(string $sClass) |
|
| 143 | +{ |
|
| 144 | +return $this->xContainer->offsetGet($sClass); |
|
| 145 | +} |
|
| 146 | 146 | |
| 147 | - /** |
|
| 147 | +/** |
|
| 148 | 148 | * Get a component when one of its method needs to be called |
| 149 | 149 | * |
| 150 | 150 | * @template T |
@@ -153,17 +153,17 @@ discard block |
||
| 153 | 153 | * |
| 154 | 154 | * @return T|null |
| 155 | 155 | */ |
| 156 | - public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | - { |
|
| 158 | - // Set the target only when getting the object targetted by the ajax request. |
|
| 159 | - $this->xTarget = $xTarget; |
|
| 160 | - $xComponent = $this->get($sClassName); |
|
| 161 | - $this->xTarget = null; |
|
| 156 | +public function getTargetComponent(string $sClassName, Target $xTarget): mixed |
|
| 157 | +{ |
|
| 158 | +// Set the target only when getting the object targetted by the ajax request. |
|
| 159 | +$this->xTarget = $xTarget; |
|
| 160 | +$xComponent = $this->get($sClassName); |
|
| 161 | +$this->xTarget = null; |
|
| 162 | 162 | |
| 163 | - return $xComponent; |
|
| 164 | - } |
|
| 163 | +return $xComponent; |
|
| 164 | +} |
|
| 165 | 165 | |
| 166 | - /** |
|
| 166 | +/** |
|
| 167 | 167 | * Register a component and its options |
| 168 | 168 | * |
| 169 | 169 | * @param class-string $sClassName The class name |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * |
| 172 | 172 | * @return void |
| 173 | 173 | */ |
| 174 | - public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | - { |
|
| 176 | - try |
|
| 177 | - { |
|
| 178 | - // Make sure the registered class exists |
|
| 179 | - if(isset($aOptions['include'])) |
|
| 180 | - { |
|
| 181 | - require_once $aOptions['include']; |
|
| 182 | - } |
|
| 183 | - $xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | - // Check if the class is registrable |
|
| 185 | - if(!$xReflectionClass->isInstantiable()) |
|
| 186 | - { |
|
| 187 | - return; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $this->_saveClassOptions($sClassName, $aOptions); |
|
| 191 | - |
|
| 192 | - $sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | - $this->val($sClassKey, $xReflectionClass); |
|
| 194 | - // Register the user class, but only if the user didn't already. |
|
| 195 | - if(!$this->has($sClassName)) |
|
| 196 | - { |
|
| 197 | - $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - catch(ReflectionException $e) |
|
| 201 | - { |
|
| 202 | - throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | - ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | - } |
|
| 205 | - } |
|
| 174 | +public function saveComponent(string $sClassName, array $aOptions): void |
|
| 175 | +{ |
|
| 176 | +try |
|
| 177 | +{ |
|
| 178 | +// Make sure the registered class exists |
|
| 179 | +if(isset($aOptions['include'])) |
|
| 180 | +{ |
|
| 181 | + require_once $aOptions['include']; |
|
| 182 | +} |
|
| 183 | +$xReflectionClass = new ReflectionClass($sClassName); |
|
| 184 | +// Check if the class is registrable |
|
| 185 | +if(!$xReflectionClass->isInstantiable()) |
|
| 186 | +{ |
|
| 187 | + return; |
|
| 188 | +} |
|
| 189 | + |
|
| 190 | +$this->_saveClassOptions($sClassName, $aOptions); |
|
| 206 | 191 | |
| 207 | - /** |
|
| 192 | +$sClassKey = $this->getReflectionClassKey($sClassName); |
|
| 193 | +$this->val($sClassKey, $xReflectionClass); |
|
| 194 | +// Register the user class, but only if the user didn't already. |
|
| 195 | +if(!$this->has($sClassName)) |
|
| 196 | +{ |
|
| 197 | + $this->set($sClassName, fn() => $this->make($this->get($sClassKey))); |
|
| 198 | +} |
|
| 199 | +} |
|
| 200 | +catch(ReflectionException $e) |
|
| 201 | +{ |
|
| 202 | +throw new SetupException($this->cn()->g(Translator::class) |
|
| 203 | + ->trans('errors.class.invalid', ['name' => $sClassName])); |
|
| 204 | +} |
|
| 205 | +} |
|
| 206 | + |
|
| 207 | +/** |
|
| 208 | 208 | * Register a component |
| 209 | 209 | * |
| 210 | 210 | * @param string $sComponentId The component name |
@@ -212,74 +212,74 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | * @throws SetupException |
| 214 | 214 | */ |
| 215 | - private function _registerComponent(string $sComponentId): string |
|
| 216 | - { |
|
| 217 | - // Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | - $sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | - |
|
| 220 | - $sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | - // Prevent duplication. It's important not to use the class name here. |
|
| 222 | - if($this->has($sComponentObject)) |
|
| 223 | - { |
|
| 224 | - return $sClassName; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Register the helper class |
|
| 228 | - $this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | - $xFactory = $this->di->getCallFactory(); |
|
| 230 | - return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | - $xFactory, $this->di->getViewRenderer(), |
|
| 232 | - $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | - $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | - }); |
|
| 235 | - |
|
| 236 | - $this->discoverComponent($sClassName); |
|
| 237 | - |
|
| 238 | - // Register the callable object |
|
| 239 | - $this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | - $aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | - $xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | - $xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | - return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | - }); |
|
| 245 | - |
|
| 246 | - // Initialize the user class instance |
|
| 247 | - $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | - if($xClassInstance instanceof AbstractComponent) |
|
| 249 | - { |
|
| 250 | - $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | - $xHelper->xTarget = $this->xTarget; |
|
| 252 | - |
|
| 253 | - // Call the protected "initComponent()" method of the Component class. |
|
| 254 | - $cSetter = function($di, $xHelper) { |
|
| 255 | - $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | - }; |
|
| 257 | - $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | - call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // Run the callbacks for class initialisation |
|
| 262 | - $this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | - |
|
| 264 | - // Set attributes from the DI container. |
|
| 265 | - // The class level DI options are set on any component. |
|
| 266 | - // The method level DI options are set only on the targetted component. |
|
| 267 | - /** @var CallableObject */ |
|
| 268 | - $xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | - $xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | - if($this->xTarget !== null) |
|
| 271 | - { |
|
| 272 | - $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | - $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return $xClassInstance; |
|
| 277 | - }); |
|
| 278 | - |
|
| 279 | - return $sClassName; |
|
| 280 | - } |
|
| 215 | +private function _registerComponent(string $sComponentId): string |
|
| 216 | +{ |
|
| 217 | +// Replace all separators ('.' or '_') with antislashes, and trim the class name. |
|
| 218 | +$sClassName = trim(str_replace(['.', '_'], '\\', $sComponentId), '\\'); |
|
| 219 | + |
|
| 220 | +$sComponentObject = $this->getCallableObjectKey($sClassName); |
|
| 221 | +// Prevent duplication. It's important not to use the class name here. |
|
| 222 | +if($this->has($sComponentObject)) |
|
| 223 | +{ |
|
| 224 | +return $sClassName; |
|
| 225 | +} |
|
| 226 | + |
|
| 227 | +// Register the helper class |
|
| 228 | +$this->set($this->getCallableHelperKey($sClassName), function() use($sClassName) { |
|
| 229 | +$xFactory = $this->di->getCallFactory(); |
|
| 230 | +return new ComponentHelper($this, $xFactory->rq($sClassName), |
|
| 231 | + $xFactory, $this->di->getViewRenderer(), |
|
| 232 | + $this->di->getLogger(), $this->di->getSessionManager(), |
|
| 233 | + $this->di->getStash(), $this->di->getUploadHandler()); |
|
| 234 | +}); |
|
| 235 | + |
|
| 236 | +$this->discoverComponent($sClassName); |
|
| 237 | + |
|
| 238 | +// Register the callable object |
|
| 239 | +$this->set($sComponentObject, function() use($sComponentId, $sClassName) { |
|
| 240 | +$aOptions = $this->_getClassOptions($sComponentId); |
|
| 241 | +$xReflectionClass = $this->get($this->getReflectionClassKey($sClassName)); |
|
| 242 | +$xOptions = $this->getComponentOptions($xReflectionClass, $aOptions); |
|
| 243 | +return new CallableObject($this, $this->di, $xReflectionClass, $xOptions); |
|
| 244 | +}); |
|
| 245 | + |
|
| 246 | +// Initialize the user class instance |
|
| 247 | +$this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) { |
|
| 248 | +if($xClassInstance instanceof AbstractComponent) |
|
| 249 | +{ |
|
| 250 | + $xHelper = $this->get($this->getCallableHelperKey($sClassName)); |
|
| 251 | + $xHelper->xTarget = $this->xTarget; |
|
| 252 | + |
|
| 253 | + // Call the protected "initComponent()" method of the Component class. |
|
| 254 | + $cSetter = function($di, $xHelper) { |
|
| 255 | + $this->initComponent($di, $xHelper); // "$this" here refers to the Component class. |
|
| 256 | + }; |
|
| 257 | + $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance); |
|
| 258 | + call_user_func($cSetter, $this->di, $xHelper); |
|
| 259 | +} |
|
| 260 | + |
|
| 261 | +// Run the callbacks for class initialisation |
|
| 262 | +$this->di->g(CallbackManager::class)->onInit($xClassInstance); |
|
| 263 | + |
|
| 264 | +// Set attributes from the DI container. |
|
| 265 | +// The class level DI options are set on any component. |
|
| 266 | +// The method level DI options are set only on the targetted component. |
|
| 267 | +/** @var CallableObject */ |
|
| 268 | +$xCallableObject = $this->get($this->getCallableObjectKey($sClassName)); |
|
| 269 | +$xCallableObject->setDiClassAttributes($xClassInstance); |
|
| 270 | +if($this->xTarget !== null) |
|
| 271 | +{ |
|
| 272 | + $sMethodName = $this->xTarget->getMethodName(); |
|
| 273 | + $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +return $xClassInstance; |
|
| 277 | +}); |
|
| 281 | 278 | |
| 282 | - /** |
|
| 279 | +return $sClassName; |
|
| 280 | +} |
|
| 281 | + |
|
| 282 | +/** |
|
| 283 | 283 | * Get the callable object for a given class |
| 284 | 284 | * The callable object is registered if it is not already in the DI. |
| 285 | 285 | * |
@@ -288,13 +288,13 @@ discard block |
||
| 288 | 288 | * @return CallableObject|null |
| 289 | 289 | * @throws SetupException |
| 290 | 290 | */ |
| 291 | - public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | - { |
|
| 293 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | - return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | - } |
|
| 291 | +public function makeCallableObject(string $sComponentId): ?CallableObject |
|
| 292 | +{ |
|
| 293 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 294 | +return $this->get($this->getCallableObjectKey($sClassName)); |
|
| 295 | +} |
|
| 296 | 296 | |
| 297 | - /** |
|
| 297 | +/** |
|
| 298 | 298 | * Get an instance of a component by name |
| 299 | 299 | * |
| 300 | 300 | * @template T |
@@ -303,53 +303,53 @@ discard block |
||
| 303 | 303 | * @return T|null |
| 304 | 304 | * @throws SetupException |
| 305 | 305 | */ |
| 306 | - public function makeComponent(string $sClassName): mixed |
|
| 307 | - { |
|
| 308 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | - $sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | - return $this->get($sClassName); |
|
| 311 | - } |
|
| 306 | +public function makeComponent(string $sClassName): mixed |
|
| 307 | +{ |
|
| 308 | +$sComponentId = str_replace('\\', '.', $sClassName); |
|
| 309 | +$sClassName = $this->_registerComponent($sComponentId); |
|
| 310 | +return $this->get($sClassName); |
|
| 311 | +} |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | +/** |
|
| 314 | 314 | * Get a factory for a call to a registered function. |
| 315 | 315 | * |
| 316 | 316 | * @return JxnCall |
| 317 | 317 | */ |
| 318 | - public function getFunctionRequestFactory(): JxnCall |
|
| 319 | - { |
|
| 320 | - return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | - } |
|
| 318 | +public function getFunctionRequestFactory(): JxnCall |
|
| 319 | +{ |
|
| 320 | +return $this->get($this->getRequestFactoryKey(JxnCall::class)); |
|
| 321 | +} |
|
| 322 | 322 | |
| 323 | - /** |
|
| 323 | +/** |
|
| 324 | 324 | * Get a factory for a call to a registered component. |
| 325 | 325 | * |
| 326 | 326 | * @param class-string $sClassName |
| 327 | 327 | * |
| 328 | 328 | * @return JxnCall|null |
| 329 | 329 | */ |
| 330 | - public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 330 | +public function getComponentRequestFactory(string $sClassName): ?JxnCall |
|
| 331 | +{ |
|
| 332 | +$sClassName = trim($sClassName, " \t"); |
|
| 333 | +if($sClassName === '') |
|
| 334 | +{ |
|
| 335 | +return null; |
|
| 336 | +} |
|
| 337 | + |
|
| 338 | +$sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | +if(!$this->has($sFactoryKey)) |
|
| 340 | +{ |
|
| 341 | +$this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | + $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | + if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 331 | 344 | { |
| 332 | - $sClassName = trim($sClassName, " \t"); |
|
| 333 | - if($sClassName === '') |
|
| 334 | - { |
|
| 335 | - return null; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $sFactoryKey = $this->getRequestFactoryKey($sClassName); |
|
| 339 | - if(!$this->has($sFactoryKey)) |
|
| 340 | - { |
|
| 341 | - $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) { |
|
| 342 | - $sComponentId = str_replace('\\', '.', $sClassName); |
|
| 343 | - if(!($xCallable = $this->makeCallableObject($sComponentId))) |
|
| 344 | - { |
|
| 345 | - return null; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | - $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | - return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | - }); |
|
| 352 | - } |
|
| 353 | - return $this->get($sFactoryKey); |
|
| 345 | + return null; |
|
| 354 | 346 | } |
| 347 | + |
|
| 348 | + $xConfigManager = $this->di->g(ConfigManager::class); |
|
| 349 | + $sPrefix = $xConfigManager->getOption('core.prefix.class', ''); |
|
| 350 | + return new JxnClassCall($sPrefix . $xCallable->getJsName()); |
|
| 351 | +}); |
|
| 352 | +} |
|
| 353 | +return $this->get($sFactoryKey); |
|
| 354 | +} |
|
| 355 | 355 | } |
@@ -21,186 +21,186 @@ |
||
| 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 | - 'export' => [], |
|
| 30 | - 'container' => [], |
|
| 31 | - 'databag' => [], |
|
| 32 | - 'callback' => [], |
|
| 33 | - 'before' => [], |
|
| 34 | - 'after' => [], |
|
| 35 | - 'upload' => [], |
|
| 36 | - ]; |
|
| 37 | - |
|
| 38 | - /** |
|
| 27 | +private array $aAttributes = [ |
|
| 28 | +'exclude' => [], |
|
| 29 | +'export' => [], |
|
| 30 | +'container' => [], |
|
| 31 | +'databag' => [], |
|
| 32 | +'callback' => [], |
|
| 33 | +'before' => [], |
|
| 34 | +'after' => [], |
|
| 35 | +'upload' => [], |
|
| 36 | +]; |
|
| 37 | + |
|
| 38 | +/** |
|
| 39 | 39 | * @return array<string, array<string, Data\AbstractData>> |
| 40 | 40 | */ |
| 41 | - public function getAttributes(): array |
|
| 42 | - { |
|
| 43 | - return $this->aAttributes; |
|
| 44 | - } |
|
| 41 | +public function getAttributes(): array |
|
| 42 | +{ |
|
| 43 | +return $this->aAttributes; |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @param string $sMethod |
| 48 | 48 | * |
| 49 | 49 | * @return Data\ExcludeData |
| 50 | 50 | */ |
| 51 | - public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 52 | - { |
|
| 53 | - return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 54 | - $this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 55 | - } |
|
| 51 | +public function exclude(string $sMethod = '*'): Data\ExcludeData |
|
| 52 | +{ |
|
| 53 | +return $this->aAttributes['exclude'][$sMethod] ?? |
|
| 54 | +$this->aAttributes['exclude'][$sMethod] = new Data\ExcludeData(); |
|
| 55 | +} |
|
| 56 | 56 | |
| 57 | - /** |
|
| 57 | +/** |
|
| 58 | 58 | * @param string $sMethod |
| 59 | 59 | * |
| 60 | 60 | * @return Data\ExportData |
| 61 | 61 | */ |
| 62 | - public function export(string $sMethod = '*'): Data\ExportData |
|
| 63 | - { |
|
| 64 | - $sMethod = '*'; // On classes only |
|
| 65 | - return $this->aAttributes['export'][$sMethod] ?? |
|
| 66 | - $this->aAttributes['export'][$sMethod] = new Data\ExportData(); |
|
| 67 | - } |
|
| 62 | +public function export(string $sMethod = '*'): Data\ExportData |
|
| 63 | +{ |
|
| 64 | +$sMethod = '*'; // On classes only |
|
| 65 | +return $this->aAttributes['export'][$sMethod] ?? |
|
| 66 | +$this->aAttributes['export'][$sMethod] = new Data\ExportData(); |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * @param string $sMethod |
| 71 | 71 | * |
| 72 | 72 | * @return Data\ContainerData |
| 73 | 73 | */ |
| 74 | - public function container(string $sMethod = '*'): Data\ContainerData |
|
| 75 | - { |
|
| 76 | - return $this->aAttributes['container'][$sMethod] ?? |
|
| 77 | - $this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 78 | - } |
|
| 74 | +public function container(string $sMethod = '*'): Data\ContainerData |
|
| 75 | +{ |
|
| 76 | +return $this->aAttributes['container'][$sMethod] ?? |
|
| 77 | +$this->aAttributes['container'][$sMethod] = new Data\ContainerData(); |
|
| 78 | +} |
|
| 79 | 79 | |
| 80 | - /** |
|
| 80 | +/** |
|
| 81 | 81 | * @param string $sMethod |
| 82 | 82 | * |
| 83 | 83 | * @return Data\DatabagData |
| 84 | 84 | */ |
| 85 | - public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 86 | - { |
|
| 87 | - return $this->aAttributes['databag'][$sMethod] ?? |
|
| 88 | - $this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 89 | - } |
|
| 85 | +public function databag(string $sMethod = '*'): Data\DatabagData |
|
| 86 | +{ |
|
| 87 | +return $this->aAttributes['databag'][$sMethod] ?? |
|
| 88 | +$this->aAttributes['databag'][$sMethod] = new Data\DatabagData(); |
|
| 89 | +} |
|
| 90 | 90 | |
| 91 | - /** |
|
| 91 | +/** |
|
| 92 | 92 | * @param string $sMethod |
| 93 | 93 | * |
| 94 | 94 | * @return Data\CallbackData |
| 95 | 95 | */ |
| 96 | - public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 97 | - { |
|
| 98 | - return $this->aAttributes['callback'][$sMethod] ?? |
|
| 99 | - $this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 100 | - } |
|
| 96 | +public function callback(string $sMethod = '*'): Data\CallbackData |
|
| 97 | +{ |
|
| 98 | +return $this->aAttributes['callback'][$sMethod] ?? |
|
| 99 | +$this->aAttributes['callback'][$sMethod] = new Data\CallbackData(); |
|
| 100 | +} |
|
| 101 | 101 | |
| 102 | - /** |
|
| 102 | +/** |
|
| 103 | 103 | * @param string $sMethod |
| 104 | 104 | * |
| 105 | 105 | * @return Data\BeforeData |
| 106 | 106 | */ |
| 107 | - public function before(string $sMethod = '*'): Data\BeforeData |
|
| 108 | - { |
|
| 109 | - return $this->aAttributes['before'][$sMethod] ?? |
|
| 110 | - $this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 111 | - } |
|
| 107 | +public function before(string $sMethod = '*'): Data\BeforeData |
|
| 108 | +{ |
|
| 109 | +return $this->aAttributes['before'][$sMethod] ?? |
|
| 110 | +$this->aAttributes['before'][$sMethod] = new Data\BeforeData(); |
|
| 111 | +} |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | +/** |
|
| 114 | 114 | * @param string $sMethod |
| 115 | 115 | * |
| 116 | 116 | * @return Data\AfterData |
| 117 | 117 | */ |
| 118 | - public function after(string $sMethod = '*'): Data\AfterData |
|
| 119 | - { |
|
| 120 | - return $this->aAttributes['after'][$sMethod] ?? |
|
| 121 | - $this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 122 | - } |
|
| 118 | +public function after(string $sMethod = '*'): Data\AfterData |
|
| 119 | +{ |
|
| 120 | +return $this->aAttributes['after'][$sMethod] ?? |
|
| 121 | +$this->aAttributes['after'][$sMethod] = new Data\AfterData(); |
|
| 122 | +} |
|
| 123 | 123 | |
| 124 | - /** |
|
| 124 | +/** |
|
| 125 | 125 | * @param string $sMethod |
| 126 | 126 | * |
| 127 | 127 | * @return Data\UploadData |
| 128 | 128 | */ |
| 129 | - public function upload(string $sMethod = '*'): Data\UploadData |
|
| 130 | - { |
|
| 131 | - return $this->aAttributes['upload'][$sMethod] ?? |
|
| 132 | - $this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 133 | - } |
|
| 129 | +public function upload(string $sMethod = '*'): Data\UploadData |
|
| 130 | +{ |
|
| 131 | +return $this->aAttributes['upload'][$sMethod] ?? |
|
| 132 | +$this->aAttributes['upload'][$sMethod] = new Data\UploadData(); |
|
| 133 | +} |
|
| 134 | 134 | |
| 135 | - /** |
|
| 135 | +/** |
|
| 136 | 136 | * True if the class is excluded |
| 137 | 137 | * |
| 138 | 138 | * @return bool |
| 139 | 139 | */ |
| 140 | - public function isExcluded(): bool |
|
| 141 | - { |
|
| 142 | - $xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 143 | - return $xData !== null && $xData->getValue() === true; |
|
| 144 | - } |
|
| 140 | +public function isExcluded(): bool |
|
| 141 | +{ |
|
| 142 | +$xData = $this->aAttributes['exclude']['*'] ?? null; |
|
| 143 | +return $xData !== null && $xData->getValue() === true; |
|
| 144 | +} |
|
| 145 | 145 | |
| 146 | - /** |
|
| 146 | +/** |
|
| 147 | 147 | * Get the properties of the class methods |
| 148 | 148 | * |
| 149 | 149 | * @return array |
| 150 | 150 | */ |
| 151 | - public function getProperties(): array |
|
| 151 | +public function getProperties(): array |
|
| 152 | +{ |
|
| 153 | +$aProperties = []; |
|
| 154 | +$aClassProperties = []; |
|
| 155 | +foreach($this->aAttributes as $sType => $aValues) |
|
| 156 | +{ |
|
| 157 | +if($sType === 'exclude') |
|
| 158 | +{ |
|
| 159 | + continue; |
|
| 160 | +} |
|
| 161 | + |
|
| 162 | +foreach($aValues as $sMethod => $xData) |
|
| 163 | +{ |
|
| 164 | + if($sMethod === '*') |
|
| 152 | 165 | { |
| 153 | - $aProperties = []; |
|
| 154 | - $aClassProperties = []; |
|
| 155 | - foreach($this->aAttributes as $sType => $aValues) |
|
| 156 | - { |
|
| 157 | - if($sType === 'exclude') |
|
| 158 | - { |
|
| 159 | - continue; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - foreach($aValues as $sMethod => $xData) |
|
| 163 | - { |
|
| 164 | - if($sMethod === '*') |
|
| 165 | - { |
|
| 166 | - $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 167 | - continue; |
|
| 168 | - } |
|
| 169 | - $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if(count($aClassProperties) > 0) |
|
| 174 | - { |
|
| 175 | - $aProperties['*'] = $aClassProperties; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $aProperties; |
|
| 166 | + $aClassProperties[$xData->getName()] = $xData->getValue(); |
|
| 167 | + continue; |
|
| 179 | 168 | } |
| 169 | + $aProperties[$sMethod][$xData->getName()] = $xData->getValue(); |
|
| 170 | +} |
|
| 171 | +} |
|
| 172 | + |
|
| 173 | +if(count($aClassProperties) > 0) |
|
| 174 | +{ |
|
| 175 | +$aProperties['*'] = $aClassProperties; |
|
| 176 | +} |
|
| 180 | 177 | |
| 181 | - /** |
|
| 178 | +return $aProperties; |
|
| 179 | +} |
|
| 180 | + |
|
| 181 | +/** |
|
| 182 | 182 | * Get the methods in the export attributes |
| 183 | 183 | * |
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | - public function getExportMethods(): array |
|
| 187 | - { |
|
| 188 | - /** @var Data\ExportData */ |
|
| 189 | - $xExportData = $this->aAttributes['export']['*'] ?? null; |
|
| 190 | - return $xExportData?->getMethods() ?? []; |
|
| 191 | - } |
|
| 186 | +public function getExportMethods(): array |
|
| 187 | +{ |
|
| 188 | +/** @var Data\ExportData */ |
|
| 189 | +$xExportData = $this->aAttributes['export']['*'] ?? null; |
|
| 190 | +return $xExportData?->getMethods() ?? []; |
|
| 191 | +} |
|
| 192 | 192 | |
| 193 | - /** |
|
| 193 | +/** |
|
| 194 | 194 | * Get the protected methods |
| 195 | 195 | * |
| 196 | 196 | * @return array |
| 197 | 197 | */ |
| 198 | - public function getProtectedMethods(): array |
|
| 199 | - { |
|
| 200 | - /** @var array<Data\ExcludeData> */ |
|
| 201 | - $aAttributes = $this->aAttributes['exclude']; |
|
| 202 | - $aMethods = array_keys($aAttributes); |
|
| 203 | - return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 204 | - $sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 205 | - } |
|
| 198 | +public function getProtectedMethods(): array |
|
| 199 | +{ |
|
| 200 | +/** @var array<Data\ExcludeData> */ |
|
| 201 | +$aAttributes = $this->aAttributes['exclude']; |
|
| 202 | +$aMethods = array_keys($aAttributes); |
|
| 203 | +return array_values(array_filter($aMethods, fn(string $sName) => |
|
| 204 | +$sName !== '*' && $aAttributes[$sName]->getValue() === true)); |
|
| 205 | +} |
|
| 206 | 206 | } |
@@ -21,59 +21,59 @@ |
||
| 21 | 21 | |
| 22 | 22 | abstract class HookData extends AbstractData |
| 23 | 23 | { |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $aCalls = []; |
|
| 27 | +protected $aCalls = []; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | - abstract protected function getType(): string; |
|
| 32 | +abstract protected function getType(): string; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @return string |
| 36 | 36 | */ |
| 37 | - public function getName(): string |
|
| 38 | - { |
|
| 39 | - return '__' . $this->getType(); |
|
| 40 | - } |
|
| 37 | +public function getName(): string |
|
| 38 | +{ |
|
| 39 | +return '__' . $this->getType(); |
|
| 40 | +} |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | +/** |
|
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - public function getValue(): mixed |
|
| 46 | - { |
|
| 47 | - return $this->aCalls; |
|
| 48 | - } |
|
| 45 | +public function getValue(): mixed |
|
| 46 | +{ |
|
| 47 | +return $this->aCalls; |
|
| 48 | +} |
|
| 49 | 49 | |
| 50 | - /** |
|
| 50 | +/** |
|
| 51 | 51 | * @param string $sMethod |
| 52 | 52 | * @param array $aParams |
| 53 | 53 | * |
| 54 | 54 | * @return void |
| 55 | 55 | */ |
| 56 | - public function addCall(string $sMethod, array $aParams): void |
|
| 57 | - { |
|
| 58 | - if(!$this->validateMethod($sMethod)) |
|
| 59 | - { |
|
| 60 | - $sType = $this->getType(); |
|
| 61 | - throw new SetupException("'$sMethod' is not a valid \"call\" value for $sType."); |
|
| 62 | - } |
|
| 63 | - $this->aCalls[$sMethod] = $aParams; |
|
| 64 | - } |
|
| 56 | +public function addCall(string $sMethod, array $aParams): void |
|
| 57 | +{ |
|
| 58 | +if(!$this->validateMethod($sMethod)) |
|
| 59 | +{ |
|
| 60 | +$sType = $this->getType(); |
|
| 61 | +throw new SetupException("'$sMethod' is not a valid \"call\" value for $sType."); |
|
| 62 | +} |
|
| 63 | +$this->aCalls[$sMethod] = $aParams; |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * @inheritDoc |
| 68 | 68 | */ |
| 69 | - public function encode(string $sVarName): array |
|
| 70 | - { |
|
| 71 | - $aCalls = []; |
|
| 72 | - foreach($this->aCalls as $sMethod => $aParams) |
|
| 73 | - { |
|
| 74 | - $sParams = addslashes(json_encode($aParams)); |
|
| 75 | - $aCalls[] = "{$sVarName}->addCall('$sMethod', json_decode(\"$sParams\", true));"; |
|
| 76 | - } |
|
| 77 | - return $aCalls; |
|
| 78 | - } |
|
| 69 | +public function encode(string $sVarName): array |
|
| 70 | +{ |
|
| 71 | +$aCalls = []; |
|
| 72 | +foreach($this->aCalls as $sMethod => $aParams) |
|
| 73 | +{ |
|
| 74 | +$sParams = addslashes(json_encode($aParams)); |
|
| 75 | +$aCalls[] = "{$sVarName}->addCall('$sMethod', json_decode(\"$sParams\", true));"; |
|
| 76 | +} |
|
| 77 | +return $aCalls; |
|
| 78 | +} |
|
| 79 | 79 | } |
@@ -18,22 +18,22 @@ |
||
| 18 | 18 | |
| 19 | 19 | abstract class AbstractData |
| 20 | 20 | { |
| 21 | - /** |
|
| 21 | +/** |
|
| 22 | 22 | * Generate the PHP code to populate a Metadata object |
| 23 | 23 | * |
| 24 | 24 | * @param string $sVarName |
| 25 | 25 | * |
| 26 | 26 | * @return array |
| 27 | 27 | */ |
| 28 | - abstract public function encode(string $sVarName): array; |
|
| 28 | +abstract public function encode(string $sVarName): array; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @param string $sMethod |
| 32 | 32 | * |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - protected function validateMethod(string $sMethod): bool |
|
| 36 | - { |
|
| 37 | - return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 38 | - } |
|
| 35 | +protected function validateMethod(string $sMethod): bool |
|
| 36 | +{ |
|
| 37 | +return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $sMethod) > 0; |
|
| 38 | +} |
|
| 39 | 39 | } |
@@ -22,53 +22,53 @@ |
||
| 22 | 22 | |
| 23 | 23 | class ExportData extends AbstractData |
| 24 | 24 | { |
| 25 | - /** |
|
| 25 | +/** |
|
| 26 | 26 | * @var array |
| 27 | 27 | */ |
| 28 | - private array $aMethods = []; |
|
| 28 | +private array $aMethods = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | +/** |
|
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function getName(): string |
|
| 34 | - { |
|
| 35 | - return 'export'; |
|
| 36 | - } |
|
| 33 | +public function getName(): string |
|
| 34 | +{ |
|
| 35 | +return 'export'; |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @return mixed |
| 40 | 40 | */ |
| 41 | - public function getMethods(): mixed |
|
| 42 | - { |
|
| 43 | - return $this->aMethods; |
|
| 44 | - } |
|
| 41 | +public function getMethods(): mixed |
|
| 42 | +{ |
|
| 43 | +return $this->aMethods; |
|
| 44 | +} |
|
| 45 | 45 | |
| 46 | - /** |
|
| 46 | +/** |
|
| 47 | 47 | * @param array $aMethods |
| 48 | 48 | * |
| 49 | 49 | * @return void |
| 50 | 50 | */ |
| 51 | - public function setMethods(array $aMethods): void |
|
| 51 | +public function setMethods(array $aMethods): void |
|
| 52 | +{ |
|
| 53 | +foreach(['base', 'only', 'except'] as $sKey) |
|
| 54 | +{ |
|
| 55 | +foreach($aMethods[$sKey] as $sMethod) |
|
| 56 | +{ |
|
| 57 | + if(!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 52 | 58 | { |
| 53 | - foreach(['base', 'only', 'except'] as $sKey) |
|
| 54 | - { |
|
| 55 | - foreach($aMethods[$sKey] as $sMethod) |
|
| 56 | - { |
|
| 57 | - if(!is_string($sMethod) || !$this->validateMethod($sMethod)) |
|
| 58 | - { |
|
| 59 | - throw new SetupException("'$sMethod' is not a valid method name."); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - $this->aMethods = $aMethods; |
|
| 59 | + throw new SetupException("'$sMethod' is not a valid method name."); |
|
| 64 | 60 | } |
| 61 | +} |
|
| 62 | +} |
|
| 63 | +$this->aMethods = $aMethods; |
|
| 64 | +} |
|
| 65 | 65 | |
| 66 | - /** |
|
| 66 | +/** |
|
| 67 | 67 | * @inheritDoc |
| 68 | 68 | */ |
| 69 | - public function encode(string $sVarName): array |
|
| 70 | - { |
|
| 71 | - $sMethods = addslashes(json_encode($this->aMethods)); |
|
| 72 | - return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"]; |
|
| 73 | - } |
|
| 69 | +public function encode(string $sVarName): array |
|
| 70 | +{ |
|
| 71 | +$sMethods = addslashes(json_encode($this->aMethods)); |
|
| 72 | +return ["{$sVarName}->setMethods(json_decode(\"$sMethods\", true));"]; |
|
| 73 | +} |
|
| 74 | 74 | } |
@@ -26,41 +26,41 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class ExportAnnotation extends AbstractAnnotation |
| 28 | 28 | { |
| 29 | - /** |
|
| 29 | +/** |
|
| 30 | 30 | * @var array |
| 31 | 31 | */ |
| 32 | - private $aMethods = []; |
|
| 32 | +private $aMethods = []; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | +/** |
|
| 35 | 35 | * @inheritDoc |
| 36 | 36 | */ |
| 37 | - public static function parseAnnotation($value) |
|
| 38 | - { |
|
| 39 | - $aParams = json_decode($value, true); |
|
| 40 | - return is_array($aParams) ? $aParams : []; |
|
| 41 | - } |
|
| 37 | +public static function parseAnnotation($value) |
|
| 38 | +{ |
|
| 39 | +$aParams = json_decode($value, true); |
|
| 40 | +return is_array($aParams) ? $aParams : []; |
|
| 41 | +} |
|
| 42 | 42 | |
| 43 | - /** |
|
| 43 | +/** |
|
| 44 | 44 | * @inheritDoc |
| 45 | 45 | * @throws AnnotationException |
| 46 | 46 | */ |
| 47 | - public function initAnnotation(array $properties) |
|
| 48 | - { |
|
| 49 | - foreach(['base', 'only', 'except'] as $key) |
|
| 50 | - { |
|
| 51 | - if(isset($properties[$key]) && is_array($properties[$key]) && |
|
| 52 | - count($properties[$key]) > 0) |
|
| 53 | - { |
|
| 54 | - $this->aMethods[$key] = $properties[$key]; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 47 | +public function initAnnotation(array $properties) |
|
| 48 | +{ |
|
| 49 | +foreach(['base', 'only', 'except'] as $key) |
|
| 50 | +{ |
|
| 51 | +if(isset($properties[$key]) && is_array($properties[$key]) && |
|
| 52 | + count($properties[$key]) > 0) |
|
| 53 | +{ |
|
| 54 | + $this->aMethods[$key] = $properties[$key]; |
|
| 55 | +} |
|
| 56 | +} |
|
| 57 | +} |
|
| 58 | 58 | |
| 59 | - /** |
|
| 59 | +/** |
|
| 60 | 60 | * @inheritDoc |
| 61 | 61 | */ |
| 62 | - public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 63 | - { |
|
| 64 | - $xMetadata->export($sMethod)->setMethods($this->aMethods); |
|
| 65 | - } |
|
| 62 | +public function saveValue(Metadata $xMetadata, string $sMethod = '*'): void |
|
| 63 | +{ |
|
| 64 | +$xMetadata->export($sMethod)->setMethods($this->aMethods); |
|
| 65 | +} |
|
| 66 | 66 | } |
@@ -14,346 +14,346 @@ |
||
| 14 | 14 | |
| 15 | 15 | class ExtendAnnotationTest extends TestCase |
| 16 | 16 | { |
| 17 | - use AnnotationTrait; |
|
| 17 | +use AnnotationTrait; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 19 | +/** |
|
| 20 | 20 | * @var string |
| 21 | 21 | */ |
| 22 | - protected $sCacheDir; |
|
| 22 | +protected $sCacheDir; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @throws SetupException |
| 26 | 26 | */ |
| 27 | - public function setUp(): void |
|
| 28 | - { |
|
| 29 | - $this->sCacheDir = __DIR__ . '/../tmp'; |
|
| 30 | - @mkdir($this->sCacheDir); |
|
| 27 | +public function setUp(): void |
|
| 28 | +{ |
|
| 29 | +$this->sCacheDir = __DIR__ . '/../tmp'; |
|
| 30 | +@mkdir($this->sCacheDir); |
|
| 31 | 31 | |
| 32 | - jaxon()->di()->getPluginManager()->registerPlugins(); |
|
| 33 | - _register(); |
|
| 32 | +jaxon()->di()->getPluginManager()->registerPlugins(); |
|
| 33 | +_register(); |
|
| 34 | 34 | |
| 35 | - jaxon()->di()->val('jaxon_annotations_cache_dir', $this->sCacheDir); |
|
| 36 | - } |
|
| 35 | +jaxon()->di()->val('jaxon_annotations_cache_dir', $this->sCacheDir); |
|
| 36 | +} |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | +/** |
|
| 39 | 39 | * @throws SetupException |
| 40 | 40 | */ |
| 41 | - public function tearDown(): void |
|
| 42 | - { |
|
| 43 | - jaxon()->reset(); |
|
| 44 | - parent::tearDown(); |
|
| 45 | - |
|
| 46 | - // Delete the temp dir and all its content |
|
| 47 | - $aFiles = scandir($this->sCacheDir); |
|
| 48 | - foreach ($aFiles as $sFile) |
|
| 49 | - { |
|
| 50 | - if($sFile !== '.' && $sFile !== '..') |
|
| 51 | - { |
|
| 52 | - @unlink($this->sCacheDir . DIRECTORY_SEPARATOR . $sFile); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - @rmdir($this->sCacheDir); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 41 | +public function tearDown(): void |
|
| 42 | +{ |
|
| 43 | +jaxon()->reset(); |
|
| 44 | +parent::tearDown(); |
|
| 45 | + |
|
| 46 | +// Delete the temp dir and all its content |
|
| 47 | +$aFiles = scandir($this->sCacheDir); |
|
| 48 | +foreach ($aFiles as $sFile) |
|
| 49 | +{ |
|
| 50 | +if($sFile !== '.' && $sFile !== '..') |
|
| 51 | +{ |
|
| 52 | + @unlink($this->sCacheDir . DIRECTORY_SEPARATOR . $sFile); |
|
| 53 | +} |
|
| 54 | +} |
|
| 55 | +@rmdir($this->sCacheDir); |
|
| 56 | +} |
|
| 57 | + |
|
| 58 | +/** |
|
| 59 | 59 | * @throws SetupException |
| 60 | 60 | */ |
| 61 | - public function testUploadAndExcludeAnnotation() |
|
| 62 | - { |
|
| 63 | - $xMetadata = $this->getAttributes(ExtendAnnotated::class, ['saveFiles', 'doNot']); |
|
| 64 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 65 | - $aProperties = $xMetadata->getProperties(); |
|
| 66 | - $aProtected = $xMetadata->getProtectedMethods(); |
|
| 61 | +public function testUploadAndExcludeAnnotation() |
|
| 62 | +{ |
|
| 63 | +$xMetadata = $this->getAttributes(ExtendAnnotated::class, ['saveFiles', 'doNot']); |
|
| 64 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 65 | +$aProperties = $xMetadata->getProperties(); |
|
| 66 | +$aProtected = $xMetadata->getProtectedMethods(); |
|
| 67 | 67 | |
| 68 | - $this->assertFalse($bExcluded); |
|
| 68 | +$this->assertFalse($bExcluded); |
|
| 69 | 69 | |
| 70 | - $this->assertCount(1, $aProperties); |
|
| 71 | - $this->assertArrayHasKey('saveFiles', $aProperties); |
|
| 72 | - $this->assertCount(1, $aProperties['saveFiles']); |
|
| 73 | - $this->assertEquals("'user-files'", $aProperties['saveFiles']['upload']); |
|
| 70 | +$this->assertCount(1, $aProperties); |
|
| 71 | +$this->assertArrayHasKey('saveFiles', $aProperties); |
|
| 72 | +$this->assertCount(1, $aProperties['saveFiles']); |
|
| 73 | +$this->assertEquals("'user-files'", $aProperties['saveFiles']['upload']); |
|
| 74 | 74 | |
| 75 | - $this->assertCount(1, $aProtected); |
|
| 76 | - $this->assertEquals('doNot', $aProtected[0]); |
|
| 77 | - } |
|
| 75 | +$this->assertCount(1, $aProtected); |
|
| 76 | +$this->assertEquals('doNot', $aProtected[0]); |
|
| 77 | +} |
|
| 78 | 78 | |
| 79 | - /** |
|
| 79 | +/** |
|
| 80 | 80 | * @throws SetupException |
| 81 | 81 | */ |
| 82 | - public function testDatabagAnnotation() |
|
| 83 | - { |
|
| 84 | - $xMetadata = $this->getAttributes(ExtendAnnotated::class, ['withBags']); |
|
| 85 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 86 | - $aProperties = $xMetadata->getProperties(); |
|
| 87 | - |
|
| 88 | - $this->assertFalse($bExcluded); |
|
| 89 | - |
|
| 90 | - $this->assertCount(1, $aProperties); |
|
| 91 | - $this->assertArrayHasKey('withBags', $aProperties); |
|
| 92 | - $this->assertCount(1, $aProperties['withBags']); |
|
| 93 | - $this->assertCount(2, $aProperties['withBags']['bags']); |
|
| 94 | - $this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
| 95 | - $this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 82 | +public function testDatabagAnnotation() |
|
| 83 | +{ |
|
| 84 | +$xMetadata = $this->getAttributes(ExtendAnnotated::class, ['withBags']); |
|
| 85 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 86 | +$aProperties = $xMetadata->getProperties(); |
|
| 87 | + |
|
| 88 | +$this->assertFalse($bExcluded); |
|
| 89 | + |
|
| 90 | +$this->assertCount(1, $aProperties); |
|
| 91 | +$this->assertArrayHasKey('withBags', $aProperties); |
|
| 92 | +$this->assertCount(1, $aProperties['withBags']); |
|
| 93 | +$this->assertCount(2, $aProperties['withBags']['bags']); |
|
| 94 | +$this->assertEquals('user.name', $aProperties['withBags']['bags'][0]); |
|
| 95 | +$this->assertEquals('page.number', $aProperties['withBags']['bags'][1]); |
|
| 96 | +} |
|
| 97 | + |
|
| 98 | +/** |
|
| 99 | 99 | * @throws SetupException |
| 100 | 100 | */ |
| 101 | - public function testServerCallbacksAnnotation() |
|
| 102 | - { |
|
| 103 | - $xMetadata = $this->getAttributes(ExtendAnnotated::class, |
|
| 104 | - ['cbSingle', 'cbMultiple', 'cbParams']); |
|
| 105 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 106 | - $aProperties = $xMetadata->getProperties(); |
|
| 107 | - |
|
| 108 | - $this->assertFalse($bExcluded); |
|
| 109 | - |
|
| 110 | - $this->assertCount(3, $aProperties); |
|
| 111 | - $this->assertArrayHasKey('cbSingle', $aProperties); |
|
| 112 | - $this->assertArrayHasKey('cbMultiple', $aProperties); |
|
| 113 | - $this->assertArrayHasKey('cbParams', $aProperties); |
|
| 114 | - |
|
| 115 | - $this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
| 116 | - $this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
| 117 | - $this->assertCount(2, $aProperties['cbParams']['__before']); |
|
| 118 | - $this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
| 119 | - $this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
| 120 | - $this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
| 121 | - $this->assertArrayHasKey('funcBefore1', $aProperties['cbParams']['__before']); |
|
| 122 | - $this->assertArrayHasKey('funcBefore2', $aProperties['cbParams']['__before']); |
|
| 123 | - $this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
| 124 | - $this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
| 125 | - $this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
| 126 | - $this->assertIsArray($aProperties['cbParams']['__before']['funcBefore1']); |
|
| 127 | - $this->assertIsArray($aProperties['cbParams']['__before']['funcBefore2']); |
|
| 128 | - |
|
| 129 | - $this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
| 130 | - $this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
| 131 | - $this->assertCount(1, $aProperties['cbParams']['__after']); |
|
| 132 | - $this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
| 133 | - $this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
| 134 | - $this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
| 135 | - $this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
| 136 | - $this->assertArrayHasKey('funcAfter1', $aProperties['cbParams']['__after']); |
|
| 137 | - $this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
| 138 | - $this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
| 139 | - $this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
| 140 | - $this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
| 141 | - $this->assertIsArray($aProperties['cbParams']['__after']['funcAfter1']); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 101 | +public function testServerCallbacksAnnotation() |
|
| 102 | +{ |
|
| 103 | +$xMetadata = $this->getAttributes(ExtendAnnotated::class, |
|
| 104 | +['cbSingle', 'cbMultiple', 'cbParams']); |
|
| 105 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 106 | +$aProperties = $xMetadata->getProperties(); |
|
| 107 | + |
|
| 108 | +$this->assertFalse($bExcluded); |
|
| 109 | + |
|
| 110 | +$this->assertCount(3, $aProperties); |
|
| 111 | +$this->assertArrayHasKey('cbSingle', $aProperties); |
|
| 112 | +$this->assertArrayHasKey('cbMultiple', $aProperties); |
|
| 113 | +$this->assertArrayHasKey('cbParams', $aProperties); |
|
| 114 | + |
|
| 115 | +$this->assertCount(1, $aProperties['cbSingle']['__before']); |
|
| 116 | +$this->assertCount(2, $aProperties['cbMultiple']['__before']); |
|
| 117 | +$this->assertCount(2, $aProperties['cbParams']['__before']); |
|
| 118 | +$this->assertArrayHasKey('funcBefore', $aProperties['cbSingle']['__before']); |
|
| 119 | +$this->assertArrayHasKey('funcBefore1', $aProperties['cbMultiple']['__before']); |
|
| 120 | +$this->assertArrayHasKey('funcBefore2', $aProperties['cbMultiple']['__before']); |
|
| 121 | +$this->assertArrayHasKey('funcBefore1', $aProperties['cbParams']['__before']); |
|
| 122 | +$this->assertArrayHasKey('funcBefore2', $aProperties['cbParams']['__before']); |
|
| 123 | +$this->assertIsArray($aProperties['cbSingle']['__before']['funcBefore']); |
|
| 124 | +$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore1']); |
|
| 125 | +$this->assertIsArray($aProperties['cbMultiple']['__before']['funcBefore2']); |
|
| 126 | +$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore1']); |
|
| 127 | +$this->assertIsArray($aProperties['cbParams']['__before']['funcBefore2']); |
|
| 128 | + |
|
| 129 | +$this->assertCount(1, $aProperties['cbSingle']['__after']); |
|
| 130 | +$this->assertCount(3, $aProperties['cbMultiple']['__after']); |
|
| 131 | +$this->assertCount(1, $aProperties['cbParams']['__after']); |
|
| 132 | +$this->assertArrayHasKey('funcAfter', $aProperties['cbSingle']['__after']); |
|
| 133 | +$this->assertArrayHasKey('funcAfter1', $aProperties['cbMultiple']['__after']); |
|
| 134 | +$this->assertArrayHasKey('funcAfter2', $aProperties['cbMultiple']['__after']); |
|
| 135 | +$this->assertArrayHasKey('funcAfter3', $aProperties['cbMultiple']['__after']); |
|
| 136 | +$this->assertArrayHasKey('funcAfter1', $aProperties['cbParams']['__after']); |
|
| 137 | +$this->assertIsArray($aProperties['cbSingle']['__after']['funcAfter']); |
|
| 138 | +$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter1']); |
|
| 139 | +$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter2']); |
|
| 140 | +$this->assertIsArray($aProperties['cbMultiple']['__after']['funcAfter3']); |
|
| 141 | +$this->assertIsArray($aProperties['cbParams']['__after']['funcAfter1']); |
|
| 142 | +} |
|
| 143 | + |
|
| 144 | +/** |
|
| 145 | 145 | * @throws SetupException |
| 146 | 146 | */ |
| 147 | - public function testContainerAnnotation() |
|
| 148 | - { |
|
| 149 | - $xMetadata = $this->getAttributes(ExtendAnnotated::class, ['di1', 'di2']); |
|
| 150 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 151 | - $aProperties = $xMetadata->getProperties(); |
|
| 152 | - |
|
| 153 | - $this->assertFalse($bExcluded); |
|
| 154 | - |
|
| 155 | - $this->assertCount(2, $aProperties); |
|
| 156 | - $this->assertArrayHasKey('di1', $aProperties); |
|
| 157 | - $this->assertArrayHasKey('di2', $aProperties); |
|
| 158 | - $this->assertCount(2, $aProperties['di1']['__di']); |
|
| 159 | - $this->assertCount(2, $aProperties['di2']['__di']); |
|
| 160 | - $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['di1']['__di']['colorService']); |
|
| 161 | - $this->assertEquals('Jaxon\Annotations\Tests\App\Ajax\FontService', $aProperties['di1']['__di']['fontService']); |
|
| 162 | - $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['di2']['__di']['colorService']); |
|
| 163 | - $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['di2']['__di']['textService']); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 147 | +public function testContainerAnnotation() |
|
| 148 | +{ |
|
| 149 | +$xMetadata = $this->getAttributes(ExtendAnnotated::class, ['di1', 'di2']); |
|
| 150 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 151 | +$aProperties = $xMetadata->getProperties(); |
|
| 152 | + |
|
| 153 | +$this->assertFalse($bExcluded); |
|
| 154 | + |
|
| 155 | +$this->assertCount(2, $aProperties); |
|
| 156 | +$this->assertArrayHasKey('di1', $aProperties); |
|
| 157 | +$this->assertArrayHasKey('di2', $aProperties); |
|
| 158 | +$this->assertCount(2, $aProperties['di1']['__di']); |
|
| 159 | +$this->assertCount(2, $aProperties['di2']['__di']); |
|
| 160 | +$this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['di1']['__di']['colorService']); |
|
| 161 | +$this->assertEquals('Jaxon\Annotations\Tests\App\Ajax\FontService', $aProperties['di1']['__di']['fontService']); |
|
| 162 | +$this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['di2']['__di']['colorService']); |
|
| 163 | +$this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['di2']['__di']['textService']); |
|
| 164 | +} |
|
| 165 | + |
|
| 166 | +/** |
|
| 167 | 167 | * @throws SetupException |
| 168 | 168 | */ |
| 169 | - public function testClassAnnotation() |
|
| 170 | - { |
|
| 171 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 172 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 173 | - $aProperties = $xMetadata->getProperties(); |
|
| 174 | - |
|
| 175 | - $this->assertFalse($bExcluded); |
|
| 176 | - |
|
| 177 | - $this->assertCount(1, $aProperties); |
|
| 178 | - $this->assertArrayHasKey('*', $aProperties); |
|
| 179 | - $this->assertCount(5, $aProperties['*']); |
|
| 180 | - $this->assertArrayHasKey('bags', $aProperties['*']); |
|
| 181 | - $this->assertArrayHasKey('callback', $aProperties['*']); |
|
| 182 | - $this->assertArrayHasKey('__before', $aProperties['*']); |
|
| 183 | - $this->assertArrayHasKey('__after', $aProperties['*']); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 169 | +public function testClassAnnotation() |
|
| 170 | +{ |
|
| 171 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 172 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 173 | +$aProperties = $xMetadata->getProperties(); |
|
| 174 | + |
|
| 175 | +$this->assertFalse($bExcluded); |
|
| 176 | + |
|
| 177 | +$this->assertCount(1, $aProperties); |
|
| 178 | +$this->assertArrayHasKey('*', $aProperties); |
|
| 179 | +$this->assertCount(5, $aProperties['*']); |
|
| 180 | +$this->assertArrayHasKey('bags', $aProperties['*']); |
|
| 181 | +$this->assertArrayHasKey('callback', $aProperties['*']); |
|
| 182 | +$this->assertArrayHasKey('__before', $aProperties['*']); |
|
| 183 | +$this->assertArrayHasKey('__after', $aProperties['*']); |
|
| 184 | +} |
|
| 185 | + |
|
| 186 | +/** |
|
| 187 | 187 | * @throws SetupException |
| 188 | 188 | */ |
| 189 | - public function testClassBagsAnnotation() |
|
| 190 | - { |
|
| 191 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 192 | - $aProperties = $xMetadata->getProperties(); |
|
| 189 | +public function testClassBagsAnnotation() |
|
| 190 | +{ |
|
| 191 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 192 | +$aProperties = $xMetadata->getProperties(); |
|
| 193 | 193 | |
| 194 | - $this->assertCount(2, $aProperties['*']['bags']); |
|
| 195 | - $this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
| 196 | - $this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
| 197 | - } |
|
| 194 | +$this->assertCount(2, $aProperties['*']['bags']); |
|
| 195 | +$this->assertEquals('user.name', $aProperties['*']['bags'][0]); |
|
| 196 | +$this->assertEquals('page.number', $aProperties['*']['bags'][1]); |
|
| 197 | +} |
|
| 198 | 198 | |
| 199 | - /** |
|
| 199 | +/** |
|
| 200 | 200 | * @throws SetupException |
| 201 | 201 | */ |
| 202 | - public function testClassCallbackAnnotation() |
|
| 203 | - { |
|
| 204 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 205 | - $aProperties = $xMetadata->getProperties(); |
|
| 202 | +public function testClassCallbackAnnotation() |
|
| 203 | +{ |
|
| 204 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 205 | +$aProperties = $xMetadata->getProperties(); |
|
| 206 | 206 | |
| 207 | - $this->assertIsArray($aProperties['*']['callback']); |
|
| 208 | - $this->assertEquals('jaxon.callback.global', $aProperties['*']['callback'][0]); |
|
| 209 | - } |
|
| 207 | +$this->assertIsArray($aProperties['*']['callback']); |
|
| 208 | +$this->assertEquals('jaxon.callback.global', $aProperties['*']['callback'][0]); |
|
| 209 | +} |
|
| 210 | 210 | |
| 211 | - /** |
|
| 211 | +/** |
|
| 212 | 212 | * @throws SetupException |
| 213 | 213 | */ |
| 214 | - public function testClassBeforeAnnotation() |
|
| 215 | - { |
|
| 216 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 217 | - $aProperties = $xMetadata->getProperties(); |
|
| 218 | - |
|
| 219 | - $this->assertCount(2, $aProperties['*']['__before']); |
|
| 220 | - $this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
| 221 | - $this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
| 222 | - $this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
| 223 | - $this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 214 | +public function testClassBeforeAnnotation() |
|
| 215 | +{ |
|
| 216 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 217 | +$aProperties = $xMetadata->getProperties(); |
|
| 218 | + |
|
| 219 | +$this->assertCount(2, $aProperties['*']['__before']); |
|
| 220 | +$this->assertArrayHasKey('funcBefore1', $aProperties['*']['__before']); |
|
| 221 | +$this->assertArrayHasKey('funcBefore2', $aProperties['*']['__before']); |
|
| 222 | +$this->assertIsArray($aProperties['*']['__before']['funcBefore1']); |
|
| 223 | +$this->assertIsArray($aProperties['*']['__before']['funcBefore2']); |
|
| 224 | +} |
|
| 225 | + |
|
| 226 | +/** |
|
| 227 | 227 | * @throws SetupException |
| 228 | 228 | */ |
| 229 | - public function testClassAfterAnnotation() |
|
| 230 | - { |
|
| 231 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 232 | - $aProperties = $xMetadata->getProperties(); |
|
| 233 | - |
|
| 234 | - $this->assertCount(3, $aProperties['*']['__after']); |
|
| 235 | - $this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
| 236 | - $this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
| 237 | - $this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
| 238 | - $this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
| 239 | - $this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
| 240 | - $this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 229 | +public function testClassAfterAnnotation() |
|
| 230 | +{ |
|
| 231 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 232 | +$aProperties = $xMetadata->getProperties(); |
|
| 233 | + |
|
| 234 | +$this->assertCount(3, $aProperties['*']['__after']); |
|
| 235 | +$this->assertArrayHasKey('funcAfter1', $aProperties['*']['__after']); |
|
| 236 | +$this->assertArrayHasKey('funcAfter2', $aProperties['*']['__after']); |
|
| 237 | +$this->assertArrayHasKey('funcAfter3', $aProperties['*']['__after']); |
|
| 238 | +$this->assertIsArray($aProperties['*']['__after']['funcAfter1']); |
|
| 239 | +$this->assertIsArray($aProperties['*']['__after']['funcAfter2']); |
|
| 240 | +$this->assertIsArray($aProperties['*']['__after']['funcAfter3']); |
|
| 241 | +} |
|
| 242 | + |
|
| 243 | +/** |
|
| 244 | 244 | * @throws SetupException |
| 245 | 245 | */ |
| 246 | - public function testClassDiAnnotation() |
|
| 247 | - { |
|
| 248 | - $xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 249 | - $aProperties = $xMetadata->getProperties(); |
|
| 250 | - |
|
| 251 | - $this->assertCount(3, $aProperties['*']['__di']); |
|
| 252 | - $this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
| 253 | - $this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
| 254 | - $this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
| 255 | - $this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
| 256 | - $this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
| 257 | - $this->assertEquals('Jaxon\Annotations\Tests\App\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 246 | +public function testClassDiAnnotation() |
|
| 247 | +{ |
|
| 248 | +$xMetadata = $this->getAttributes(ExtendClassAnnotated::class, []); |
|
| 249 | +$aProperties = $xMetadata->getProperties(); |
|
| 250 | + |
|
| 251 | +$this->assertCount(3, $aProperties['*']['__di']); |
|
| 252 | +$this->assertArrayHasKey('colorService', $aProperties['*']['__di']); |
|
| 253 | +$this->assertArrayHasKey('textService', $aProperties['*']['__di']); |
|
| 254 | +$this->assertArrayHasKey('fontService', $aProperties['*']['__di']); |
|
| 255 | +$this->assertEquals('Jaxon\Annotations\Tests\Service\ColorService', $aProperties['*']['__di']['colorService']); |
|
| 256 | +$this->assertEquals('Jaxon\Annotations\Tests\Service\TextService', $aProperties['*']['__di']['textService']); |
|
| 257 | +$this->assertEquals('Jaxon\Annotations\Tests\App\Ajax\FontService', $aProperties['*']['__di']['fontService']); |
|
| 258 | +} |
|
| 259 | + |
|
| 260 | +/** |
|
| 261 | 261 | * @throws SetupException |
| 262 | 262 | */ |
| 263 | - public function testClassExcludeAnnotation() |
|
| 264 | - { |
|
| 265 | - $xMetadata = $this->getAttributes(ClassExcluded::class, |
|
| 266 | - ['doNot', 'withBags', 'cbSingle']); |
|
| 267 | - $bExcluded = $xMetadata->isExcluded(); |
|
| 268 | - $aProperties = $xMetadata->getProperties(); |
|
| 269 | - $aProtected = $xMetadata->getProtectedMethods(); |
|
| 270 | - |
|
| 271 | - $this->assertTrue($bExcluded); |
|
| 272 | - $this->assertEmpty($aProperties); |
|
| 273 | - $this->assertEmpty($aProtected); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - public function testExcludeAnnotationError() |
|
| 277 | - { |
|
| 278 | - $this->expectException(SetupException::class); |
|
| 279 | - $this->getAttributes(ExtendAnnotated::class, ['doNotError']); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - public function testDatabagAnnotationError() |
|
| 283 | - { |
|
| 284 | - $this->expectException(SetupException::class); |
|
| 285 | - $this->getAttributes(ExtendAnnotated::class, ['withBagsError']); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - public function testUploadAnnotationWrongName() |
|
| 289 | - { |
|
| 290 | - $this->expectException(SetupException::class); |
|
| 291 | - $this->getAttributes(ExtendAnnotated::class, ['saveFilesWrongName']); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - public function testUploadAnnotationMultiple() |
|
| 295 | - { |
|
| 296 | - $this->expectException(SetupException::class); |
|
| 297 | - $this->getAttributes(ExtendAnnotated::class, ['saveFilesMultiple']); |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - public function testCallbacksBeforeAnnotationNoCall() |
|
| 301 | - { |
|
| 302 | - $this->expectException(SetupException::class); |
|
| 303 | - $this->getAttributes(ExtendAnnotated::class, ['cbBeforeNoCall']); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - public function testCallbacksBeforeAnnotationUnknownAttr() |
|
| 307 | - { |
|
| 308 | - $this->expectException(SetupException::class); |
|
| 309 | - $this->getAttributes(ExtendAnnotated::class, ['cbBeforeUnknownAttr']); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - public function testCallbacksBeforeAnnotationWrongAttrType() |
|
| 313 | - { |
|
| 314 | - $this->expectException(SetupException::class); |
|
| 315 | - $this->getAttributes(ExtendAnnotated::class, ['cbBeforeWrongAttrType']); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - public function testCallbacksAfterAnnotationNoCall() |
|
| 319 | - { |
|
| 320 | - $this->expectException(SetupException::class); |
|
| 321 | - $this->getAttributes(ExtendAnnotated::class, ['cbAfterNoCall']); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - public function testCallbacksAfterAnnotationUnknownAttr() |
|
| 325 | - { |
|
| 326 | - $this->expectException(SetupException::class); |
|
| 327 | - $this->getAttributes(ExtendAnnotated::class, ['cbAfterUnknownAttr']); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - public function testCallbacksAfterAnnotationWrongAttrType() |
|
| 331 | - { |
|
| 332 | - $this->expectException(SetupException::class); |
|
| 333 | - $this->getAttributes(ExtendAnnotated::class, ['cbAfterWrongAttrType']); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - public function testContainerAnnotationUnknownAttr() |
|
| 337 | - { |
|
| 338 | - $this->expectException(SetupException::class); |
|
| 339 | - $this->getAttributes(ExtendAnnotated::class, ['diUnknownAttr']); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - public function testContainerAnnotationWrongAttrType() |
|
| 343 | - { |
|
| 344 | - $this->expectException(SetupException::class); |
|
| 345 | - $this->getAttributes(ExtendAnnotated::class, ['diWrongAttrType']); |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - public function testContainerAnnotationWrongClassType() |
|
| 349 | - { |
|
| 350 | - $this->expectException(SetupException::class); |
|
| 351 | - $this->getAttributes(ExtendAnnotated::class, ['diWrongClassType']); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - public function testContainerAnnotationWrongVarCount() |
|
| 355 | - { |
|
| 356 | - $this->expectException(SetupException::class); |
|
| 357 | - $this->getAttributes(ExtendAnnotated::class, ['diWrongVarCount']); |
|
| 358 | - } |
|
| 263 | +public function testClassExcludeAnnotation() |
|
| 264 | +{ |
|
| 265 | +$xMetadata = $this->getAttributes(ClassExcluded::class, |
|
| 266 | +['doNot', 'withBags', 'cbSingle']); |
|
| 267 | +$bExcluded = $xMetadata->isExcluded(); |
|
| 268 | +$aProperties = $xMetadata->getProperties(); |
|
| 269 | +$aProtected = $xMetadata->getProtectedMethods(); |
|
| 270 | + |
|
| 271 | +$this->assertTrue($bExcluded); |
|
| 272 | +$this->assertEmpty($aProperties); |
|
| 273 | +$this->assertEmpty($aProtected); |
|
| 274 | +} |
|
| 275 | + |
|
| 276 | +public function testExcludeAnnotationError() |
|
| 277 | +{ |
|
| 278 | +$this->expectException(SetupException::class); |
|
| 279 | +$this->getAttributes(ExtendAnnotated::class, ['doNotError']); |
|
| 280 | +} |
|
| 281 | + |
|
| 282 | +public function testDatabagAnnotationError() |
|
| 283 | +{ |
|
| 284 | +$this->expectException(SetupException::class); |
|
| 285 | +$this->getAttributes(ExtendAnnotated::class, ['withBagsError']); |
|
| 286 | +} |
|
| 287 | + |
|
| 288 | +public function testUploadAnnotationWrongName() |
|
| 289 | +{ |
|
| 290 | +$this->expectException(SetupException::class); |
|
| 291 | +$this->getAttributes(ExtendAnnotated::class, ['saveFilesWrongName']); |
|
| 292 | +} |
|
| 293 | + |
|
| 294 | +public function testUploadAnnotationMultiple() |
|
| 295 | +{ |
|
| 296 | +$this->expectException(SetupException::class); |
|
| 297 | +$this->getAttributes(ExtendAnnotated::class, ['saveFilesMultiple']); |
|
| 298 | +} |
|
| 299 | + |
|
| 300 | +public function testCallbacksBeforeAnnotationNoCall() |
|
| 301 | +{ |
|
| 302 | +$this->expectException(SetupException::class); |
|
| 303 | +$this->getAttributes(ExtendAnnotated::class, ['cbBeforeNoCall']); |
|
| 304 | +} |
|
| 305 | + |
|
| 306 | +public function testCallbacksBeforeAnnotationUnknownAttr() |
|
| 307 | +{ |
|
| 308 | +$this->expectException(SetupException::class); |
|
| 309 | +$this->getAttributes(ExtendAnnotated::class, ['cbBeforeUnknownAttr']); |
|
| 310 | +} |
|
| 311 | + |
|
| 312 | +public function testCallbacksBeforeAnnotationWrongAttrType() |
|
| 313 | +{ |
|
| 314 | +$this->expectException(SetupException::class); |
|
| 315 | +$this->getAttributes(ExtendAnnotated::class, ['cbBeforeWrongAttrType']); |
|
| 316 | +} |
|
| 317 | + |
|
| 318 | +public function testCallbacksAfterAnnotationNoCall() |
|
| 319 | +{ |
|
| 320 | +$this->expectException(SetupException::class); |
|
| 321 | +$this->getAttributes(ExtendAnnotated::class, ['cbAfterNoCall']); |
|
| 322 | +} |
|
| 323 | + |
|
| 324 | +public function testCallbacksAfterAnnotationUnknownAttr() |
|
| 325 | +{ |
|
| 326 | +$this->expectException(SetupException::class); |
|
| 327 | +$this->getAttributes(ExtendAnnotated::class, ['cbAfterUnknownAttr']); |
|
| 328 | +} |
|
| 329 | + |
|
| 330 | +public function testCallbacksAfterAnnotationWrongAttrType() |
|
| 331 | +{ |
|
| 332 | +$this->expectException(SetupException::class); |
|
| 333 | +$this->getAttributes(ExtendAnnotated::class, ['cbAfterWrongAttrType']); |
|
| 334 | +} |
|
| 335 | + |
|
| 336 | +public function testContainerAnnotationUnknownAttr() |
|
| 337 | +{ |
|
| 338 | +$this->expectException(SetupException::class); |
|
| 339 | +$this->getAttributes(ExtendAnnotated::class, ['diUnknownAttr']); |
|
| 340 | +} |
|
| 341 | + |
|
| 342 | +public function testContainerAnnotationWrongAttrType() |
|
| 343 | +{ |
|
| 344 | +$this->expectException(SetupException::class); |
|
| 345 | +$this->getAttributes(ExtendAnnotated::class, ['diWrongAttrType']); |
|
| 346 | +} |
|
| 347 | + |
|
| 348 | +public function testContainerAnnotationWrongClassType() |
|
| 349 | +{ |
|
| 350 | +$this->expectException(SetupException::class); |
|
| 351 | +$this->getAttributes(ExtendAnnotated::class, ['diWrongClassType']); |
|
| 352 | +} |
|
| 353 | + |
|
| 354 | +public function testContainerAnnotationWrongVarCount() |
|
| 355 | +{ |
|
| 356 | +$this->expectException(SetupException::class); |
|
| 357 | +$this->getAttributes(ExtendAnnotated::class, ['diWrongVarCount']); |
|
| 358 | +} |
|
| 359 | 359 | } |
@@ -7,176 +7,176 @@ |
||
| 7 | 7 | |
| 8 | 8 | class ExtendAnnotated extends FuncComponent |
| 9 | 9 | { |
| 10 | - /** |
|
| 10 | +/** |
|
| 11 | 11 | * @exclude |
| 12 | 12 | */ |
| 13 | - public function doNot() |
|
| 14 | - { |
|
| 15 | - } |
|
| 13 | +public function doNot() |
|
| 14 | +{ |
|
| 15 | +} |
|
| 16 | 16 | |
| 17 | - /** |
|
| 17 | +/** |
|
| 18 | 18 | * @exclude(true) |
| 19 | 19 | */ |
| 20 | - public function doNotBool() |
|
| 21 | - { |
|
| 22 | - } |
|
| 20 | +public function doNotBool() |
|
| 21 | +{ |
|
| 22 | +} |
|
| 23 | 23 | |
| 24 | - /** |
|
| 24 | +/** |
|
| 25 | 25 | * @exclude('Me') |
| 26 | 26 | */ |
| 27 | - public function doNotError() |
|
| 28 | - { |
|
| 29 | - } |
|
| 27 | +public function doNotError() |
|
| 28 | +{ |
|
| 29 | +} |
|
| 30 | 30 | |
| 31 | - /** |
|
| 31 | +/** |
|
| 32 | 32 | * @databag('name' => 'user.name') |
| 33 | 33 | * @databag('name' => 'page.number') |
| 34 | 34 | */ |
| 35 | - public function withBags() |
|
| 36 | - { |
|
| 37 | - } |
|
| 35 | +public function withBags() |
|
| 36 | +{ |
|
| 37 | +} |
|
| 38 | 38 | |
| 39 | - /** |
|
| 39 | +/** |
|
| 40 | 40 | * @databag('mane' => 'user.name') |
| 41 | 41 | * @databag('mane' => 'page.number') |
| 42 | 42 | */ |
| 43 | - public function withBagsError() |
|
| 44 | - { |
|
| 45 | - } |
|
| 43 | +public function withBagsError() |
|
| 44 | +{ |
|
| 45 | +} |
|
| 46 | 46 | |
| 47 | - /** |
|
| 47 | +/** |
|
| 48 | 48 | * @upload('field' => 'user-files') |
| 49 | 49 | */ |
| 50 | - public function saveFiles() |
|
| 51 | - { |
|
| 52 | - } |
|
| 50 | +public function saveFiles() |
|
| 51 | +{ |
|
| 52 | +} |
|
| 53 | 53 | |
| 54 | - /** |
|
| 54 | +/** |
|
| 55 | 55 | * @upload('name' => 'user-files') |
| 56 | 56 | */ |
| 57 | - public function saveFilesWrongName() |
|
| 58 | - { |
|
| 59 | - } |
|
| 57 | +public function saveFilesWrongName() |
|
| 58 | +{ |
|
| 59 | +} |
|
| 60 | 60 | |
| 61 | - /** |
|
| 61 | +/** |
|
| 62 | 62 | * @upload('field' => 'user-file1') |
| 63 | 63 | * @upload('field' => 'user-file2') |
| 64 | 64 | */ |
| 65 | - public function saveFilesMultiple() |
|
| 66 | - { |
|
| 67 | - } |
|
| 65 | +public function saveFilesMultiple() |
|
| 66 | +{ |
|
| 67 | +} |
|
| 68 | 68 | |
| 69 | - /** |
|
| 69 | +/** |
|
| 70 | 70 | * @before('call' => 'funcBefore') |
| 71 | 71 | * @after('call' => 'funcAfter') |
| 72 | 72 | */ |
| 73 | - public function cbSingle() |
|
| 74 | - { |
|
| 75 | - } |
|
| 73 | +public function cbSingle() |
|
| 74 | +{ |
|
| 75 | +} |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | +/** |
|
| 78 | 78 | * @before('call' => 'funcBefore1') |
| 79 | 79 | * @before('call' => 'funcBefore2') |
| 80 | 80 | * @after('call' => 'funcAfter1') |
| 81 | 81 | * @after('call' => 'funcAfter2') |
| 82 | 82 | * @after('call' => 'funcAfter3') |
| 83 | 83 | */ |
| 84 | - public function cbMultiple() |
|
| 85 | - { |
|
| 86 | - } |
|
| 84 | +public function cbMultiple() |
|
| 85 | +{ |
|
| 86 | +} |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | +/** |
|
| 89 | 89 | * @before('call' => 'funcBefore1', 'with' => ['param1']) |
| 90 | 90 | * @before('call' => 'funcBefore2', 'with' => ['param1', 'param2']) |
| 91 | 91 | * @after('call' => 'funcAfter1', 'with' => ['param1', 'param2']) |
| 92 | 92 | */ |
| 93 | - public function cbParams() |
|
| 94 | - { |
|
| 95 | - } |
|
| 93 | +public function cbParams() |
|
| 94 | +{ |
|
| 95 | +} |
|
| 96 | 96 | |
| 97 | - /** |
|
| 97 | +/** |
|
| 98 | 98 | * @di('attr' => 'colorService', 'class' => 'ColorService') |
| 99 | 99 | * @di('attr' => 'fontService', 'class' => 'FontService') |
| 100 | 100 | */ |
| 101 | - public function di1() |
|
| 102 | - { |
|
| 103 | - } |
|
| 101 | +public function di1() |
|
| 102 | +{ |
|
| 103 | +} |
|
| 104 | 104 | |
| 105 | - /** |
|
| 105 | +/** |
|
| 106 | 106 | * @di('attr' => 'colorService', 'class' => 'ColorService') |
| 107 | 107 | * @di('attr' => 'textService', 'class' => '\Jaxon\Annotations\Tests\Service\TextService') |
| 108 | 108 | */ |
| 109 | - public function di2() |
|
| 110 | - { |
|
| 111 | - } |
|
| 109 | +public function di2() |
|
| 110 | +{ |
|
| 111 | +} |
|
| 112 | 112 | |
| 113 | - /** |
|
| 113 | +/** |
|
| 114 | 114 | * @before('name' => 'funcBefore', 'with' => ['param1']) |
| 115 | 115 | */ |
| 116 | - public function cbBeforeNoCall() |
|
| 117 | - { |
|
| 118 | - } |
|
| 116 | +public function cbBeforeNoCall() |
|
| 117 | +{ |
|
| 118 | +} |
|
| 119 | 119 | |
| 120 | - /** |
|
| 120 | +/** |
|
| 121 | 121 | * @before('call' => 'funcBefore', 'params' => ['param1']) |
| 122 | 122 | */ |
| 123 | - public function cbBeforeUnknownAttr() |
|
| 124 | - { |
|
| 125 | - } |
|
| 123 | +public function cbBeforeUnknownAttr() |
|
| 124 | +{ |
|
| 125 | +} |
|
| 126 | 126 | |
| 127 | - /** |
|
| 127 | +/** |
|
| 128 | 128 | * @before('call' => 'funcBefore', 'with' => 'param1') |
| 129 | 129 | */ |
| 130 | - public function cbBeforeWrongAttrType() |
|
| 131 | - { |
|
| 132 | - } |
|
| 130 | +public function cbBeforeWrongAttrType() |
|
| 131 | +{ |
|
| 132 | +} |
|
| 133 | 133 | |
| 134 | - /** |
|
| 134 | +/** |
|
| 135 | 135 | * @after('name' => 'funcAfter', 'with' => ['param1']) |
| 136 | 136 | */ |
| 137 | - public function cbAfterNoCall() |
|
| 138 | - { |
|
| 139 | - } |
|
| 137 | +public function cbAfterNoCall() |
|
| 138 | +{ |
|
| 139 | +} |
|
| 140 | 140 | |
| 141 | - /** |
|
| 141 | +/** |
|
| 142 | 142 | * @after('call' => 'funcAfter', 'params' => ['param1']) |
| 143 | 143 | */ |
| 144 | - public function cbAfterUnknownAttr() |
|
| 145 | - { |
|
| 146 | - } |
|
| 144 | +public function cbAfterUnknownAttr() |
|
| 145 | +{ |
|
| 146 | +} |
|
| 147 | 147 | |
| 148 | - /** |
|
| 148 | +/** |
|
| 149 | 149 | * @after('call' => 'funcAfter', 'with' => true) |
| 150 | 150 | */ |
| 151 | - public function cbAfterWrongAttrType() |
|
| 152 | - { |
|
| 153 | - } |
|
| 151 | +public function cbAfterWrongAttrType() |
|
| 152 | +{ |
|
| 153 | +} |
|
| 154 | 154 | |
| 155 | - /** |
|
| 155 | +/** |
|
| 156 | 156 | * @di('attr' => 'attr', 'params' => '') |
| 157 | 157 | */ |
| 158 | - public function diUnknownAttr() |
|
| 159 | - { |
|
| 160 | - } |
|
| 158 | +public function diUnknownAttr() |
|
| 159 | +{ |
|
| 160 | +} |
|
| 161 | 161 | |
| 162 | - /** |
|
| 162 | +/** |
|
| 163 | 163 | * @di('attr' => [], 'class' => 'ClassName') |
| 164 | 164 | */ |
| 165 | - public function diWrongAttrType() |
|
| 166 | - { |
|
| 167 | - } |
|
| 165 | +public function diWrongAttrType() |
|
| 166 | +{ |
|
| 167 | +} |
|
| 168 | 168 | |
| 169 | - /** |
|
| 169 | +/** |
|
| 170 | 170 | * @di('attr' => 'attr', 'class' => true) |
| 171 | 171 | */ |
| 172 | - public function diWrongClassType() |
|
| 173 | - { |
|
| 174 | - } |
|
| 172 | +public function diWrongClassType() |
|
| 173 | +{ |
|
| 174 | +} |
|
| 175 | 175 | |
| 176 | - /** |
|
| 176 | +/** |
|
| 177 | 177 | * @di('attr' => 'attr', 'class' => 'ClassName', 'name' => 'di') |
| 178 | 178 | */ |
| 179 | - public function diWrongVarCount() |
|
| 180 | - { |
|
| 181 | - } |
|
| 179 | +public function diWrongVarCount() |
|
| 180 | +{ |
|
| 181 | +} |
|
| 182 | 182 | } |