Test Failed
Push — master ( 8f2167...5d2217 )
by Georgi
08:27
created

ModuleView   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A displayModuleContent() 0 26 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
	 * @var \Epesi\Core\App
19
	 */
20
	public $app;
21
	
22
	/**
23
	 * Generates content in the layout using defined module method based on profided arguments / properties
24
	 * 
25
	 * @param string $method
26
	 * @param string $args
27
	 */
28
	final public function displayModuleContent($method, $args) {
29
		// if method not callbale abort to 'not found'
30
		if (! is_callable([$this, $method])) abort(404);
31
		
32
		// if user has no access abort 'no access'
33
		if (! $this->access()) abort(401);
34
		
35
		$args = $this->decodeArgs($args);
36
		
37
		// set the associative array keys as view properties
38
		$this->setDefaults($args);
39
		
40
		// filter for entries with numeric keys use values as method arguments
41
		$args = array_filter($args, function($key) {
42
			return is_numeric($key);
43
		}, ARRAY_FILTER_USE_KEY);
44
		
45
		ksort($args);
46
		
47
		// method can add seeds to the module seed
48
		// the content echoed in the method is assigned to the module view content region
49
		ob_start();
50
		$this->{$method}(...$args);
51
		$content = ob_get_clean();
52
		
53
		$this->set('Content', $content);
54
	}
55
}
56