summaryrefslogtreecommitdiffstats
path: root/admin/survey/minify/lib/Minify/Env.php
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-01-11 12:35:47 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2022-01-11 12:35:47 +0100
commit19985dbb8c0aa66dc4bf7905abc1148de909097d (patch)
tree2cd5a5d20d7e80fc2a51adf60d838d8a2c40999e /admin/survey/minify/lib/Minify/Env.php
download1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.gz
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.bz2
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.lz
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.xz
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.tar.zst
1ka-19985dbb8c0aa66dc4bf7905abc1148de909097d.zip
Diffstat (limited to 'admin/survey/minify/lib/Minify/Env.php')
-rw-r--r--admin/survey/minify/lib/Minify/Env.php127
1 files changed, 127 insertions, 0 deletions
diff --git a/admin/survey/minify/lib/Minify/Env.php b/admin/survey/minify/lib/Minify/Env.php
new file mode 100644
index 0000000..3bc78f7
--- /dev/null
+++ b/admin/survey/minify/lib/Minify/Env.php
@@ -0,0 +1,127 @@
+<?php
+
+class Minify_Env
+{
+
+ /**
+ * @return string
+ */
+ public function getDocRoot()
+ {
+ return $this->server['DOCUMENT_ROOT'];
+ }
+
+ /**
+ * @return string
+ */
+ public function getRequestUri()
+ {
+ return $this->server['REQUEST_URI'];
+ }
+
+ public function __construct($options = array())
+ {
+ $options = array_merge(array(
+ 'server' => $_SERVER,
+ 'get' => $_GET,
+ 'post' => $_POST,
+ 'cookie' => $_COOKIE,
+ ), $options);
+
+ $this->server = $options['server'];
+ if (empty($this->server['DOCUMENT_ROOT'])) {
+ $this->server['DOCUMENT_ROOT'] = $this->computeDocRoot($options['server']);
+ } else {
+ $this->server['DOCUMENT_ROOT'] = rtrim($this->server['DOCUMENT_ROOT'], '/\\');
+ }
+
+ $this->server['DOCUMENT_ROOT'] = $this->normalizePath($this->server['DOCUMENT_ROOT']);
+ $this->get = $options['get'];
+ $this->post = $options['post'];
+ $this->cookie = $options['cookie'];
+ }
+
+ public function server($key = null)
+ {
+ if (null === $key) {
+ return $this->server;
+ }
+
+ return isset($this->server[$key]) ? $this->server[$key] : null;
+ }
+
+ public function cookie($key = null, $default = null)
+ {
+ if (null === $key) {
+ return $this->cookie;
+ }
+
+ return isset($this->cookie[$key]) ? $this->cookie[$key] : $default;
+ }
+
+ public function get($key = null, $default = null)
+ {
+ if (null === $key) {
+ return $this->get;
+ }
+
+ return isset($this->get[$key]) ? $this->get[$key] : $default;
+ }
+
+ public function post($key = null, $default = null)
+ {
+ if (null === $key) {
+ return $this->post;
+ }
+
+ return isset($this->post[$key]) ? $this->post[$key] : $default;
+ }
+
+ /**
+ * turn windows-style slashes into unix-style,
+ * remove trailing slash
+ * and lowercase drive letter
+ *
+ * @param string $path absolute path
+ *
+ * @return string
+ */
+ public function normalizePath($path)
+ {
+ $realpath = realpath($path);
+ if ($realpath) {
+ $path = $realpath;
+ }
+
+ $path = str_replace('\\', '/', $path);
+ $path = rtrim($path, '/');
+ if (substr($path, 1, 1) === ':') {
+ $path = lcfirst($path);
+ }
+
+ return $path;
+ }
+
+ protected $server;
+ protected $get;
+ protected $post;
+ protected $cookie;
+
+ /**
+ * Compute $_SERVER['DOCUMENT_ROOT'] for IIS using SCRIPT_FILENAME and SCRIPT_NAME.
+ *
+ * @param array $server
+ * @return string
+ */
+ protected function computeDocRoot(array $server)
+ {
+ if (isset($server['SERVER_SOFTWARE']) && 0 !== strpos($server['SERVER_SOFTWARE'], 'Microsoft-IIS/')) {
+ throw new InvalidArgumentException('DOCUMENT_ROOT is not provided and could not be computed');
+ }
+
+ $substrLength = strlen($server['SCRIPT_FILENAME']) - strlen($server['SCRIPT_NAME']);
+ $docRoot = substr($server['SCRIPT_FILENAME'], 0, $substrLength);
+
+ return rtrim($docRoot, '\\');
+ }
+}