ModuleView   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A displayModuleContent() 0 31 3
1
<?php
2
3
namespace Epesi\Core\System\Modules;
4
5
use atk4\ui\View;
6
7
abstract class ModuleView extends View
8
{
9
	use Concerns\HasModule;
10
	use Concerns\HasLinks;
11
	use Concerns\HasAssetsAccess;
12
	use Concerns\HasAccessControl;
13
	use Concerns\HasLocation;
14
	use Concerns\HasVariables;
15
	use Concerns\Notifies;
16
	
17
	/**
18
	 * Generates content in the layout using defined module method based on profided arguments / properties
19
	 * 
20
	 * @param string $method
21
	 * @param string $args
22
	 */
23
	final public function displayModuleContent($method, $args)
24
	{
25
		// if method not callbale abort to 'not found'
26
		if (! is_callable([$this, $method])) abort(404);
27
		
28
		// if user has no access abort 'no access'
29
		if (! $this->access()) abort(401);
30
		
31
		$args = $this->decodeArgs($args);
32
33
		// filter for entries with numeric keys use values as method arguments
34
		$argsNumeric = array_filter($args, function($key) {
35
			return is_numeric($key);
36
		}, ARRAY_FILTER_USE_KEY);
37
		
38
		$argsAssoc = array_diff_key($args, $argsNumeric);
39
		
40
		// set the associative array keys as view properties
41
		$this->setDefaults($argsAssoc);
42
		
43
		ksort($argsNumeric);
44
		
45
		// method can add seeds to the module seed
46
		// the content echoed in the method is assigned to the module view content region
47
		ob_start();
48
		$this->{$method}(...$argsNumeric);
49
		$content = ob_get_clean();
50
		
51
		$this->set('Content', $content);
52
		
53
		return $this;
54
	}
55
}
56