Passed
Push — master ( 289cbe...3ce129 )
by Anton
03:29
created

Basic::getLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Extend
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Extend\Utils\Extension {
11
12
	use Modules\Extend, Cookie, Request;
13
14
	abstract class Basic extends Extend\Utils\Extension {
15
16
		/**
17
		 * Get a loader object
18
		 */
19
20
		public static function getLoader(string $section, bool $load_all = true) : Extend\Utils\Loader\Basic {
21
22
			return new static::$loader_class($section, $load_all);
23
		}
24
25
		/**
26
		 * Initialize the extensions list
27
		 */
28
29
		public static function init(string $section) {
30
31
			static::$loader = new static::$loader_class($section, false);
32
33
			# Throw error if no extensions found
34
35
			if (false === static::$loader->get('name')) throw new static::$exception_class;
36
37
			# Activate user defined extension
38
39
			if (static::$selectable[static::$loader->getSection()]) {
40
41
				$name = static::$name; $param = static::$param[static::$loader->getSection()];
42
43
				if (static::$loader->activate(Request::get($name)) || static::$loader->activate(Cookie::get($param)))
44
45
					Cookie::set($param, static::$loader->get('name'), static::$cookie_expires);
46
			}
47
		}
48
	}
49
}
50