Completed
Push — master ( 89c3fb...acf74b )
by Auke
15:57
created

ar_loader::getLoader()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4286
cc 3
eloc 6
nc 2
nop 0
crap 3.072
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 6 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
	ar_pinp::allow('ar_loader');
4
	ar_pinp::allow('ar_loaderSession');
5
6
	class ar_loader extends arBase {
7
8
		static public $makeLocalURL = null;
9
		static public $session = null;
10
11
		public static function configure( $option, $value ) {
12
			switch ($option) {
13
				case 'makeLocalURL' :
0 ignored issues
show
Coding Style introduced by
There must be no space before the colon in a CASE statement

As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.

switch ($selector) {
    case "A": //right
        doSomething();
        break;
    case "B" : //wrong
        doSomethingElse();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
14
					self::$makeLocalURL = $value;
15
				break;
16
			}
17
		}
18
19
		public function __set( $name, $value ) {
20
			ar_loader::configure( $name, $value );
21
		}
22
23
		public function __get( $name ) {
24
			if ( isset( ar_loader::${$name} ) ) {
25
				return ar_loader::${$name};
26
			}
27
		}
28
29 28
		public static function getLoader() {
30 28
			global $AR;
31 28
			if ($AR->request && isset($AR->request['loader'])) {
32
				return $AR->request['loader'];
33
			} else {
34 28
				return new ar_core_loader_http();
35
			}
36
		}
37
38
		public static function header( $header ) {
39
			$loader = self::getLoader();
40
			return $loader->header( $header );
41
		}
42
43
		public static function redirect( $url ) {
44
			$loader = self::getLoader();
45
			return $loader->redirect( $url );
46
		}
47
48
		public static function content( $contentType, $size = 0 ) {
49
			$loader = self::getLoader();
50
			return $loader->content( $contentType, $size );
51
		}
52
53
		public static function cache($expires = 0, $modified = false ) {
54
			$loader = self::getLoader();
55
			return $loader->cache( $expires, $modified );
56
		}
57
58
		public static function disableCache() {
59
			$loader = self::getLoader();
60
			return $loader->disableCache();
61
		}
62
63 24
		public static function getvar( $name = null, $method = null ) {
64 24
			$loader = self::getLoader();
65 24
			return $loader->getvar( $name, $method );
66
		}
67
68 4
		public static function makeURL( $path = '', $nls = '', $session = true, $https = null, $keephost = null ) {
69 4
			$loader = self::getLoader();
70 4
			if (!isset($keephost)) {
71 4
				$keephost = self::$makeLocalURL;
72 4
			}
73 4
			return $loader->makeURL( $path, $nls, $session, $https, $keephost );
74
		}
75
76
		public static function session() {
77
			if (!self::$session) {
78
				self::$session = new ar_loaderSession();
79
			}
80
			return self::$session;
81
		}
82
83
	}
84
85
	class ar_loaderSession extends arBase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
86
		// FIXME: merge ar_session and ar_loaderSession in some way
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task "merge ar_session and ar_loaderSession in some way"
Loading history...
87
		// loader should control only how to get and set the session id
88
89
		public static function id() {
90
			global $ARCurrent;
91
92
			if ($ARCurrent->session) {
93
				return $ARCurrent->session->id;
94
			} else {
95
				return 0;
96
			}
97
		}
98
99
		public static function getvar( $name ) {
100
			global $ARCurrent;
101
102
			if ($ARCurrent->session) {
103
				return $ARCurrent->session->get($name);
104
			} else {
105
				return false;
106
			}
107
		}
108
109
		public static function putvar( $name, $value ) {
110
			global $ARCurrent;
111
112
			if ($ARCurrent->session) {
113
				return $ARCurrent->session->put($name, $value);
114
			} else {
115
				return false;
116
			}
117
 		}
118
119
		public static function start() {
120
			global $ARCurrent;
121
122
			ldStartSession(0);
123
			return $ARCurrent->session->id;
124
		}
125
126
		public static function kill() {
127
		    global $ARCurrent;
128
129
			if ($ARCurrent->session) {
130
				$ARCurrent->session->kill();
131
				unset($ARCurrent->session);
132
			}
133
		}
134
135
	}
136