From 4010eb58143a48199b406b95e8a09370c0190461 Mon Sep 17 00:00:00 2001 From: maks feltrin Date: Mon, 30 May 2016 20:39:04 +0200 Subject: [PATCH] move valid protocol versions to a class static var Just a matter of taste: i think it looks uglier as a static function var. In this way it's also available to all Message(s) --- Slim/Http/Message.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Slim/Http/Message.php b/Slim/Http/Message.php index d0e832d69..1596c8d50 100644 --- a/Slim/Http/Message.php +++ b/Slim/Http/Message.php @@ -31,6 +31,17 @@ abstract class Message implements MessageInterface */ protected $protocolVersion = '1.1'; + /** + * A map of valid protocol versions + * + * @var array + */ + protected static $validProtocolVersions = [ + '1.0' => true, + '1.1' => true, + '2.0' => true, + ]; + /** * Headers * @@ -86,13 +97,11 @@ public function getProtocolVersion() */ public function withProtocolVersion($version) { - static $valid = [ - '1.0' => true, - '1.1' => true, - '2.0' => true, - ]; - if (!isset($valid[$version])) { - throw new InvalidArgumentException('Invalid HTTP version. Must be one of: 1.0, 1.1, 2.0'); + if (!isset(self::$validProtocolVersions[$version])) { + throw new InvalidArgumentException( + 'Invalid HTTP version. Must be one of: ' + . implode(', ', array_keys(self::$validProtocolVersions)) + ); } $clone = clone $this; $clone->protocolVersion = $version;