From fb6b837fa3bb4cfd1090360f4d3d07aeb14f67a7 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Fri, 30 Jan 2015 11:45:31 +0100 Subject: [PATCH] Compression Method Name updated --- composer.lock | 10 +++++----- lib/Compression/CompressionManager.php | 10 +++------- lib/Compression/Deflate.php | 7 +++---- lib/Compression/GZip.php | 7 +++---- lib/Compression/ZLib.php | 7 +++---- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/composer.lock b/composer.lock index e85da913..c8c6d87d 100644 --- a/composer.lock +++ b/composer.lock @@ -116,16 +116,16 @@ }, { "name": "spomky-labs/jose-interface", - "version": "v0.0.2", + "version": "v0.0.3", "source": { "type": "git", "url": "https://github.com/Spomky-Labs/jose-interface.git", - "reference": "cd0daf936d4221ea40ac71a9b6db11f3bf3c4ab3" + "reference": "6dbc6667e148423b52a34a0ba9c5bf6d95b520ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Spomky-Labs/jose-interface/zipball/cd0daf936d4221ea40ac71a9b6db11f3bf3c4ab3", - "reference": "cd0daf936d4221ea40ac71a9b6db11f3bf3c4ab3", + "url": "https://api.github.com/repos/Spomky-Labs/jose-interface/zipball/6dbc6667e148423b52a34a0ba9c5bf6d95b520ec", + "reference": "6dbc6667e148423b52a34a0ba9c5bf6d95b520ec", "shasum": "" }, "require": { @@ -169,7 +169,7 @@ "jwa", "jwt" ], - "time": "2015-01-29 21:32:49" + "time": "2015-01-30 10:41:37" }, { "name": "spomky-labs/pbkdf2", diff --git a/lib/Compression/CompressionManager.php b/lib/Compression/CompressionManager.php index 31b1086c..c483920c 100644 --- a/lib/Compression/CompressionManager.php +++ b/lib/Compression/CompressionManager.php @@ -21,21 +21,17 @@ class CompressionManager implements CompressionManagerInterface */ public function addCompressionAlgorithm(CompressionInterface $compression_algorithm) { - $this->compression_algorithms[] = $compression_algorithm; + $this->compression_algorithms[$compression_algorithm->getMethodName()] = $compression_algorithm; return $this; } /** * @param string $name - * @return mixed + * @return CompressionInterface|null */ public function getCompressionAlgorithm($name) { - foreach ($this->compression_algorithms as $algorithm) { - if ($algorithm->isMethodSupported($name)) { - return $algorithm; - } - } + return array_key_exists($name, $this->compression_algorithms)?$this->compression_algorithms[$name]:null; } } diff --git a/lib/Compression/Deflate.php b/lib/Compression/Deflate.php index 75b77ae7..c1f8afa0 100644 --- a/lib/Compression/Deflate.php +++ b/lib/Compression/Deflate.php @@ -36,12 +36,11 @@ public function getCompressionLevel() } /** - * @param string $method - * @return bool + * @return string */ - public function isMethodSupported($method) + public function getMethodName() { - return 'DEF' === $method; + return 'DEF'; } /** diff --git a/lib/Compression/GZip.php b/lib/Compression/GZip.php index f06cefe2..09ae6280 100644 --- a/lib/Compression/GZip.php +++ b/lib/Compression/GZip.php @@ -36,12 +36,11 @@ public function getCompressionLevel() } /** - * @param string $method - * @return bool + * @return string */ - public function isMethodSupported($method) + public function getMethodName() { - return 'GZ' === $method; + return 'GZ'; } /** diff --git a/lib/Compression/ZLib.php b/lib/Compression/ZLib.php index 60580f62..bc680785 100644 --- a/lib/Compression/ZLib.php +++ b/lib/Compression/ZLib.php @@ -36,12 +36,11 @@ public function getCompressionLevel() } /** - * @param string $method - * @return bool + * @return string */ - public function isMethodSupported($method) + public function getMethodName() { - return 'ZLIB' === $method; + return 'ZLIB'; } /**