Completed
Push — master ( 33b38e...1faa07 )
by
unknown
465:40 queued 403:16
created

ar_loader::inputStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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 21
		public static function getLoader() {
30 21
			global $AR;
31 21
			if ($AR->request && isset($AR->request['loader'])) {
32
				return $AR->request['loader'];
33
			} else {
34 21
				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 18
		public static function getvar( $name = null, $method = null ) {
64 18
			$loader = self::getLoader();
65 18
			return $loader->getvar( $name, $method );
66
		}
67
68
		public static function inputStream() {
69
			return new ar_content_filesFile(fopen("php://input", "r"));
70
		}
71
72
		public static function outputStream() {
73
			return new ar_content_filesFile(fopen('php://output','w'));
74
		}
75
76
		public static function makeURL( $path = '', $nls = '', $session = true, $https = null, $keephost = null ) {
77
			$loader = self::getLoader();
78
			if (!isset($keephost)) {
79
				$keephost = self::$makeLocalURL;
80 3
			}
81 3
			return $loader->makeURL( $path, $nls, $session, $https, $keephost );
82 3
		}
83 3
84 3
		public static function session() {
85 3
			if (!self::$session) {
86
				self::$session = new ar_loaderSession();
87
			}
88
			return self::$session;
89
		}
90
91
	}
92
93
	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...
94
		// 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...
95
		// loader should control only how to get and set the session id
96
97
		public static function id() {
98
			global $ARCurrent;
99
100
			if ($ARCurrent->session) {
101
				return $ARCurrent->session->id;
102
			} else {
103
				return 0;
104
			}
105
		}
106
107
		public static function getvar( $name ) {
108
			global $ARCurrent;
109
110
			if ($ARCurrent->session) {
111
				return $ARCurrent->session->get($name);
112
			} else {
113
				return false;
114
			}
115
		}
116
117
		public static function putvar( $name, $value ) {
118
			global $ARCurrent;
119
120
			if ($ARCurrent->session) {
121
				return $ARCurrent->session->put($name, $value);
122
			} else {
123
				return false;
124
			}
125
 		}
126
127
		public static function start() {
128
			global $ARCurrent;
129
130
			ldStartSession(0);
131
			return $ARCurrent->session->id;
132
		}
133
134
		public static function kill() {
135
		    global $ARCurrent;
136
137
			if ($ARCurrent->session) {
138
				$ARCurrent->session->kill();
139
				unset($ARCurrent->session);
140
			}
141
		}
142
143
	}
144