Kaynağa Gözat

Delegating all setEncoding() calls to the Zend_XmlRpc_Value::setEncoding()

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19566 44c647ce-9c0f-0410-b52a-842ac1e357ba
lars 16 yıl önce
ebeveyn
işleme
e1cc2ef615

+ 1 - 0
library/Zend/XmlRpc/Fault.php

@@ -168,6 +168,7 @@ class Zend_XmlRpc_Fault
     public function setEncoding($encoding)
     {
         $this->_encoding = $encoding;
+        Zend_XmlRpc_Value::setEncoding($encoding);
         return $this;
     }
 

+ 1 - 0
library/Zend/XmlRpc/Request.php

@@ -116,6 +116,7 @@ class Zend_XmlRpc_Request
     public function setEncoding($encoding)
     {
         $this->_encoding = $encoding;
+        Zend_XmlRpc_Value::setEncoding($encoding);
         return $this;
     }
 

+ 1 - 0
library/Zend/XmlRpc/Response.php

@@ -89,6 +89,7 @@ class Zend_XmlRpc_Response
     public function setEncoding($encoding)
     {
         $this->_encoding = $encoding;
+        Zend_XmlRpc_Value::setEncoding($encoding);
         return $this;
     }
 

+ 1 - 0
library/Zend/XmlRpc/Server.php

@@ -386,6 +386,7 @@ class Zend_XmlRpc_Server extends Zend_Server_Abstract
     public function setEncoding($encoding)
     {
         $this->_encoding = $encoding;
+        Zend_XmlRpc_Value::setEncoding($encoding);
         return $this;
     }
 

+ 24 - 0
library/Zend/XmlRpc/Value.php

@@ -97,6 +97,11 @@ abstract class Zend_XmlRpc_Value
         return $this->_type;
     }
 
+    /**
+     * Get XML generator instance
+     *
+     * @return Zend_XmlRpc_Generator_Abstract
+     */
     public static function getGenerator()
     {
         if (!self::$_generator) {
@@ -107,12 +112,31 @@ abstract class Zend_XmlRpc_Value
         return self::$_generator;
     }
 
+    /**
+     * Sets XML generator instance
+     *
+     * @param Zend_XmlRpc_Generator_Abstract $generator
+     * @return void
+     */
     public static function setGenerator(Zend_XmlRpc_Generator_Abstract $generator)
     {
         self::$_generator = $generator;
     }
 
     /**
+     * Changes the encoding of the generator
+     *
+     * @param string $encoding
+     * @return void
+     */
+    public static function setEncoding($encoding)
+    {
+        $generator = self::getGenerator();
+        $newGenerator = new $generator($encoding);
+        self::setGenerator($newGenerator);
+    }
+
+    /**
      * Return the value of this object, convert the XML-RPC native value into a PHP variable
      *
      * @return mixed

+ 2 - 0
tests/Zend/XmlRpc/FaultTest.php

@@ -272,8 +272,10 @@ class Zend_XmlRpc_FaultTest extends PHPUnit_Framework_TestCase
     public function testSetGetEncoding()
     {
         $this->assertEquals('UTF-8', $this->_fault->getEncoding());
+        $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding());
         $this->_fault->setEncoding('ISO-8859-1');
         $this->assertEquals('ISO-8859-1', $this->_fault->getEncoding());
+        $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding());
     }
 
     public function testUnknownErrorIsUsedIfUnknownErrorCodeEndEmptyMessageIsPassed()

+ 3 - 1
tests/Zend/XmlRpc/RequestTest.php

@@ -343,7 +343,9 @@ class Zend_XmlRpc_RequestTest extends PHPUnit_Framework_TestCase
     public function testSetGetEncoding()
     {
         $this->assertEquals('UTF-8', $this->_request->getEncoding());
-        $this->_request->setEncoding('ISO-8859-1');
+        $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding());
+        $this->assertSame($this->_request, $this->_request->setEncoding('ISO-8859-1'));
         $this->assertEquals('ISO-8859-1', $this->_request->getEncoding());
+        $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding());
     }
 }

+ 3 - 1
tests/Zend/XmlRpc/ResponseTest.php

@@ -208,8 +208,10 @@ EOD;
     public function testSetGetEncoding()
     {
         $this->assertEquals('UTF-8', $this->_response->getEncoding());
-        $this->_response->setEncoding('ISO-8859-1');
+        $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding());
+        $this->assertSame($this->_response, $this->_response->setEncoding('ISO-8859-1'));
         $this->assertEquals('ISO-8859-1', $this->_response->getEncoding());
+        $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding());
     }
 
     public function testLoadXmlThrowsExceptionWithMissingNodes()

+ 3 - 1
tests/Zend/XmlRpc/ServerTest.php

@@ -416,8 +416,10 @@ class Zend_XmlRpc_ServerTest extends PHPUnit_Framework_TestCase
     public function testGetSetEncoding()
     {
         $this->assertEquals('UTF-8', $this->_server->getEncoding());
-        $this->_server->setEncoding('ISO-8859-1');
+        $this->assertEquals('UTF-8', Zend_XmlRpc_Value::getGenerator()->getEncoding());
+        $this->assertSame($this->_server, $this->_server->setEncoding('ISO-8859-1'));
         $this->assertEquals('ISO-8859-1', $this->_server->getEncoding());
+        $this->assertEquals('ISO-8859-1', Zend_XmlRpc_Value::getGenerator()->getEncoding());
     }
 
     /**

+ 13 - 0
tests/Zend/XmlRpc/ValueTest.php

@@ -733,6 +733,19 @@ class Zend_XmlRpc_ValueTest extends PHPUnit_Framework_TestCase
         $this->assertSame('foobar', $o2->getProperty());
     }
 
+    public function testChangingExceptionResetsGeneratorObject()
+    {
+        $generator = Zend_XmlRpc_Value::getGenerator();
+        Zend_XmlRpc_Value::setEncoding('UTF-8');
+        $this->assertNotSame($generator, Zend_XmlRpc_Value::getGenerator());
+        $this->assertEquals($generator, Zend_XmlRpc_Value::getGenerator());
+
+        $generator = Zend_XmlRpc_Value::getGenerator();
+        Zend_XmlRpc_Value::setEncoding('ISO-8859-1');
+        $this->assertNotSame($generator, Zend_XmlRpc_Value::getGenerator());
+        $this->assertNotEquals($generator, Zend_XmlRpc_Value::getGenerator());
+    }
+
     // Exceptions
 
     public function testFactoryThrowsWhenInvalidTypeSpecified()