From 868224bcfe628f1cac96c8a6870e310db3d97125 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 10 Sep 2020 09:17:55 -0400 Subject: [PATCH] Add $config->serverProtocol runtime property --- wire/core/Config.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/wire/core/Config.php b/wire/core/Config.php index 59de713d..985316b0 100644 --- a/wire/core/Config.php +++ b/wire/core/Config.php @@ -154,6 +154,7 @@ * @property bool $internal This is automatically set to FALSE when PW is externally bootstrapped. #pw-group-runtime * @property bool $external This is automatically set to TRUE when PW is externally bootstrapped. #pw-internal * @property bool $cli This is automatically set to TRUE when PW is booted as a command line (non HTTP) script. #pw-group-runtime + * @property string $serverProtocol Current server protocol, one of: HTTP/1.1, HTTP/1.0, HTTP/2, or HTTP/2.0. #pw-group-runtime #since 3.0.166 * @property string $versionName This is automatically populated with the current PW version name (i.e. 2.5.0 dev) #pw-group-runtime * @property int $inputfieldColumnWidthSpacing Used by some admin themes to commmunicate to InputfieldWrapper at runtime. #pw-internal * @property array InputfieldWrapper Settings specific to InputfieldWrapper class #pw-internal @@ -193,6 +194,22 @@ class Config extends WireData { */ const debugVerbose = 2; + /** + * Get config property + * + * @param string $key + * @return string|array|int|bool|object|callable|null + * + */ + public function get($key) { + $value = parent::get($key); + if($value === null) { + // runtime properties + if($key === 'serverProtocol') $value = $this->serverProtocol(); + } + return $value; + } + /** * Get URL for requested resource or module * @@ -648,6 +665,21 @@ class Config extends WireData { if(!ctype_digit("$date")) $date = strtotime($date); return $this->installed < $date; } + + /** + * Get current server protocol (for example: "HTTP/1.1") + * + * This can be accessed by property `$config->serverProtocol` + * + * @return string + * @since 3.0.166 + * + */ + protected function serverProtocol() { + $protos = array('HTTP/1.1', 'HTTP/1.0', 'HTTP/2', 'HTTP/2.0'); + $proto = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; + return $protos[(int) array_search($proto, $protos, true)]; + } /** * Set the current ProcessWire instance for this object (PW 3.0)