Passed
Push — master ( 4954b5...87483c )
by Georgi
03:11
created

SystemController::view()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
c 0
b 0
f 0
nc 6
nop 4
dl 0
loc 25
rs 9.8333
1
<?php
2
3
namespace Epesi\Core\Controllers;
4
5
use Illuminate\Routing\Controller;
6
use Epesi\Core\System\SystemCore;
7
use Epesi\Core\App as Epesi;
8
use Epesi\Core\System\Integration\Modules\ModuleManager;
9
use Epesi\Core\Layout\LayoutView;
10
11
class SystemController extends Controller
12
{
13
    public function index()
14
    {
15
    	return SystemCore::isInstalled()? redirect('home'): redirect('install');
16
    }
17
    
18
    public function install(Epesi $epesi)
19
    {
20
    	// make sure the installation information is fresh
21
    	ModuleManager::clearCache();
22
    	
23
    	if (SystemCore::isInstalled()) return redirect('home');
24
    	
25
    	$epesi->title = config('epesi.app.title') . ' > ' . __('Installation');
26
    	
27
    	$epesi->initLayout('Centered');
28
    	
29
    	$epesi->layout->set('logo', url('logo'));
30
    	$epesi->layout->template->setHTML('copyright', config('epesi.app.copyright'));
31
    	
32
    	$epesi->add(new \Epesi\Core\System\SystemInstallWizard());
33
    	
34
    	return $epesi->response();
35
    }
36
    
37
    public function home()
38
    {
39
    	return redirect(SystemCore::isInstalled()? \Epesi\Core\HomePage\HomePageSettings::getUserHomePagePath(): 'install');
40
    }
41
    
42
    public function logo()
43
    {
44
    	$meta = \Epesi\Core\System\Logo\LogoSettings::getLogoMeta();
45
    	
46
    	return response($meta['contents'], 200, ['Content-type' => $meta['mime']])->setMaxAge(604800)->setPublic();
47
    }
48
    
49
    public function view(Epesi $epesi, $module, $method = 'body', $args = [])
50
    {
51
    	$epesi->initLayout(new LayoutView());
0 ignored issues
show
Bug introduced by
new Epesi\Core\Layout\LayoutView() of type Epesi\Core\Layout\LayoutView is incompatible with the type array|atk4\ui\Layout\Generic|string expected by parameter $seed of atk4\ui\App::initLayout(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
    	$epesi->initLayout(/** @scrutinizer ignore-type */ new LayoutView());
Loading history...
52
    	
53
    	$alias = explode(':', $module);
54
    	
55
    	$moduleAlias = $alias[0];
56
    	$viewAlias = $alias[1]?? null;
57
    	
58
    	$view = null;
59
    	if ($module = ModuleManager::getClass($moduleAlias, true)) {
60
    		$viewClass = $module::view($viewAlias);
61
62
    		if (class_exists($viewClass)) {
63
    			$view = new $viewClass();
64
    		}
65
    	}
66
67
    	if (! $view) abort(404);
68
    	
69
    	$epesi->add($view)->displayModuleContent($method, $args);
70
    	
71
    	$epesi->setLocation($view->location());
72
    	
73
    	return $epesi->response();
74
    }
75
}
76