Completed
Push — master ( 2f7d3a...843240 )
by Robbert
16s
created

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