From 699e1ba205696993372a19d419d7b2b8c1c8abf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Bati=C4=87?= Date: Tue, 3 Jun 2014 11:31:23 +0200 Subject: [PATCH] Fixed the bug with cached class methods. When get_class_methods(__CLASS__) was changed to get_class_methods($this), derived classes got a method list from the first instantiated MessageFactory, which could be the parent or a sibling class, so this is fixed now. --- src/Message/MessageFactory.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Message/MessageFactory.php b/src/Message/MessageFactory.php index e024fd3a..c0fde6aa 100644 --- a/src/Message/MessageFactory.php +++ b/src/Message/MessageFactory.php @@ -28,6 +28,9 @@ class MessageFactory implements MessageFactoryInterface /** @var Redirect */ private $redirectPlugin; + /** @var array */ + protected static $classMethods = []; + public function __construct() { $this->errorPlugin = new HttpError(); @@ -152,11 +155,18 @@ class MessageFactory implements MessageFactoryInterface static $configMap = ['connect_timeout' => 1, 'timeout' => 1, 'verify' => 1, 'ssl_key' => 1, 'cert' => 1, 'proxy' => 1, 'debug' => 1, 'save_to' => 1, 'stream' => 1, 'expect' => 1]; - static $methods; - if (!$methods) { - $methods = array_flip(get_class_methods($this)); + + // Take the class of the instance, not the parent + $selfClass = get_class($this); + + // Check if we already took it's class methods and had them saved + if (!isset(self::$classMethods[$selfClass])) { + self::$classMethods[$selfClass] = array_flip(get_class_methods($this)); } + // Take class methods of this particular instance + $methods = self::$classMethods[$selfClass]; + // Iterate over each key value pair and attempt to apply a config using // double dispatch. $config = $request->getConfig();