PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / mrclay / minify / lib / Minify / Env.php

Env.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at vendor/mrclay/minify/lib/Minify/Env.php

128 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Minify_Env
4 {
5
6 /**
7 * @return string
8 */
9 public function getDocRoot()
10 {
11 return $this->server['DOCUMENT_ROOT'];
12 }
13
14 /**
15 * @return string
16 */
17 public function getRequestUri()
18 {
19 return $this->server['REQUEST_URI'];
20 }
21
22 public function __construct($options = array())
23 {
24 $options = array_merge(array(
25 'server' => $_SERVER,
26 'get' => $_GET,
27 'post' => $_POST,
28 'cookie' => $_COOKIE,
29 ), $options);
30
31 $this->server = $options['server'];
32 if (empty($this->server['DOCUMENT_ROOT'])) {
33 $this->server['DOCUMENT_ROOT'] = $this->computeDocRoot($options['server']);
34 } else {
35 $this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\');
36 }
37
38 $this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']);
39 $this->get = $options['get'];
40 $this->post = $options['post'];
41 $this->cookie = $options['cookie'];
42 }
43
44 public function server($key = null)
45 {
46 if (null === $key) {
47 return $this->server;
48 }
49
50 return isset($this->server[$key]) ? $this->server[$key] : null;
51 }
52
53 public function cookie($key = null, $default = null)
54 {
55 if (null === $key) {
56 return $this->cookie;
57 }
58
59 return isset($this->cookie[$key]) ? $this->cookie[$key] : $default;
60 }
61
62 public function get($key = null, $default = null)
63 {
64 if (null === $key) {
65 return $this->get;
66 }
67
68 return isset($this->get[$key]) ? $this->get[$key] : $default;
69 }
70
71 public function post($key = null, $default = null)
72 {
73 if (null === $key) {
74 return $this->post;
75 }
76
77 return isset($this->post[$key]) ? $this->post[$key] : $default;
78 }
79
80 /**
81 * turn windows-style slashes into unix-style,
82 * remove trailing slash
83 * and lowercase drive letter
84 *
85 * @param string $path absolute path
86 *
87 * @return string
88 */
89 public function normalizePath($path)
90 {
91 $realpath = realpath($path);
92 if ($realpath) {
93 $path = $realpath;
94 }
95
96 $path = str_replace('\\', '/', $path);
97 $path = rtrim($path, '/');
98 if (substr($path, 1, 1) === ':') {
99 $path = lcfirst($path);
100 }
101
102 return $path;
103 }
104
105 protected $server;
106 protected $get;
107 protected $post;
108 protected $cookie;
109
110 /**
111 * Compute $_SERVER['DOCUMENT_ROOT'] for IIS using SCRIPT_FILENAME and SCRIPT_NAME.
112 *
113 * @param array $server
114 * @return string
115 */
116 protected function computeDocRoot(array $server)
117 {
118 if (isset($server['SERVER_SOFTWARE']) && 0 !== strpos($server['SERVER_SOFTWARE'], 'Microsoft-IIS/')) {
119 throw new InvalidArgumentException('DOCUMENT_ROOT is not provided and could not be computed');
120 }
121
122 $substrLength = strlen($server['SCRIPT_FILENAME']) - strlen($server['SCRIPT_NAME']);
123 $docRoot = substr($server['SCRIPT_FILENAME'], 0, $substrLength);
124
125 return rtrim($docRoot, '\\');
126 }
127 }
128