1
|
|
|
<?php |
|
|
|
|
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' : |
|
|
|
|
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 { |
|
|
|
|
98
|
|
|
// FIXME: merge ar_session and ar_loaderSession in some way |
|
|
|
|
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
|
|
|
|
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.