From 6487206e99a6e221b3cd1c85d556002b677eec25 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 12:10:14 +0300 Subject: [PATCH 01/18] Added Unicode json_encoding patch --- .gitignore | 1 + Test/Basic/UnicodeTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .gitignore create mode 100644 Test/Basic/UnicodeTest.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8fe4fa --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.project diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php new file mode 100644 index 0000000..f1116a0 --- /dev/null +++ b/Test/Basic/UnicodeTest.php @@ -0,0 +1,26 @@ +simulateCall('/test/' + $test_string, 'get'); + $this->assertEquals('{ + "status": 200, + "data": "' + $test_string + '" +}', $response); + } + + public function testUnicode() + { + $restService = Server::create('/', new MyRoutes) + ->setClient('RestService\\InternalClient') + ->collectRoutes(); + + $this->assertEncoding($restService, 'test'); + } +} \ No newline at end of file From b0636eb01e88120ec1a937327e27e77e8d5af6b7 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 12:26:34 +0300 Subject: [PATCH 02/18] Added Unicode json_encoding patch --- .gitignore | 34 +++++++++++++++++++++++++++++++++- Test/Basic/UnicodeTest.php | 2 +- Test/Controller/MyRoutes.php | 10 ++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d8fe4fa..bff5440 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,33 @@ -/.project + + + + +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php index f1116a0..85b240d 100644 --- a/Test/Basic/UnicodeTest.php +++ b/Test/Basic/UnicodeTest.php @@ -8,7 +8,7 @@ class UnicodeTest extends \PHPUnit_Framework_TestCase { private function assertEncoding($restService, $test_string){ - $response = $restService->simulateCall('/test/' + $test_string, 'get'); + $response = $restService->simulateCall('/test/echo?test_string=' + rawurlencode($test_string), 'get'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index ed3e3ec..6f3001e 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -57,4 +57,14 @@ public function getTest() return 'test'; } + /** + * @param string $test_string + * @url test/echo + * @return string + */ + public function getEcho($test_string) + { + return $test_string; + } + } From a8b33f46d90f35f5e49aa59c87a1f3577f87fdb3 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 12:42:35 +0300 Subject: [PATCH 03/18] Added Unicode json_encoding patch --- Test/Basic/UnicodeTest.php | 6 +++--- Test/Controller/MyRoutes.php | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php index 85b240d..adc3688 100644 --- a/Test/Basic/UnicodeTest.php +++ b/Test/Basic/UnicodeTest.php @@ -7,8 +7,8 @@ class UnicodeTest extends \PHPUnit_Framework_TestCase { - private function assertEncoding($restService, $test_string){ - $response = $restService->simulateCall('/test/echo?test_string=' + rawurlencode($test_string), 'get'); + private function assertEcho($restService, $test_string){ + $response = $restService->simulateCall('/echo?test_string=' + rawurlencode($test_string), 'get'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" @@ -21,6 +21,6 @@ public function testUnicode() ->setClient('RestService\\InternalClient') ->collectRoutes(); - $this->assertEncoding($restService, 'test'); + $this->assertEcho($restService, 'test'); } } \ No newline at end of file diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index 6f3001e..b731898 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -59,7 +59,6 @@ public function getTest() /** * @param string $test_string - * @url test/echo * @return string */ public function getEcho($test_string) From 96f9811c452126734e5878628d20fd5a55923bb6 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 14:20:51 +0300 Subject: [PATCH 04/18] Added Unicode json_encoding patch --- Test/Basic/UnicodeTest.php | 22 +++++++++++++++------- Test/Controller/MyRoutes.php | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php index adc3688..6b84b5c 100644 --- a/Test/Basic/UnicodeTest.php +++ b/Test/Basic/UnicodeTest.php @@ -7,8 +7,20 @@ class UnicodeTest extends \PHPUnit_Framework_TestCase { - private function assertEcho($restService, $test_string){ - $response = $restService->simulateCall('/echo?test_string=' + rawurlencode($test_string), 'get'); + /** + * @var Server + */ + private $restService; + + public function setUp() + { + $this->restService = Server::create('/', new MyRoutes) + ->setClient('RestService\\InternalClient') + ->collectRoutes(); + } + + private function assertEcho($test_string){ + $response = $this->restService->simulateCall('/echo?test_string=' + rawurlencode($test_string), 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" @@ -17,10 +29,6 @@ private function assertEcho($restService, $test_string){ public function testUnicode() { - $restService = Server::create('/', new MyRoutes) - ->setClient('RestService\\InternalClient') - ->collectRoutes(); - - $this->assertEcho($restService, 'test'); + $this->assertEcho('test'); } } \ No newline at end of file diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index b731898..5580616 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -61,7 +61,7 @@ public function getTest() * @param string $test_string * @return string */ - public function getEcho($test_string) + public function postEcho($test_string) { return $test_string; } From a3c766fe55a142a223098ed0909871e7e2d55741 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 14:25:59 +0300 Subject: [PATCH 05/18] Added Unicode json_encoding patch --- Test/Basic/UnicodeTest.php | 2 +- Test/Controller/MyRoutes.php | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php index 6b84b5c..e1e5d70 100644 --- a/Test/Basic/UnicodeTest.php +++ b/Test/Basic/UnicodeTest.php @@ -20,7 +20,7 @@ public function setUp() } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo?test_string=' + rawurlencode($test_string), 'post'); + $response = $this->restService->simulateCall('/echo/' + rawurlencode($test_string), 'get'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index 5580616..c96a15a 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -58,12 +58,13 @@ public function getTest() } /** - * @param string $test_string + * @param string $text + * @url echo/(.*) * @return string */ - public function postEcho($test_string) + public function getEcho($text) { - return $test_string; + return $text; } } From d750f52bf30262b3d3e75b5d2e2157cf541bf2d8 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 14:34:28 +0300 Subject: [PATCH 06/18] Added Unicode json_encoding patch --- Test/Basic/UnicodeTest.php | 2 +- Test/Controller/MyRoutes.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Basic/UnicodeTest.php b/Test/Basic/UnicodeTest.php index e1e5d70..b9ae53d 100644 --- a/Test/Basic/UnicodeTest.php +++ b/Test/Basic/UnicodeTest.php @@ -20,7 +20,7 @@ public function setUp() } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo/' + rawurlencode($test_string), 'get'); + $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'get'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index c96a15a..b98d3c4 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -59,7 +59,7 @@ public function getTest() /** * @param string $text - * @url echo/(.*) + * @url echo * @return string */ public function getEcho($text) From 73cf012fdda117fb957d479fc676afbf4e2212c2 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 14:38:47 +0300 Subject: [PATCH 07/18] Added Unicode json_encoding patch --- Test/{Basic => Synthetic}/UnicodeTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Test/{Basic => Synthetic}/UnicodeTest.php (100%) diff --git a/Test/Basic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php similarity index 100% rename from Test/Basic/UnicodeTest.php rename to Test/Synthetic/UnicodeTest.php From 96c5cd5cd8b6dfaf0c2b4c9c785961758bd514a8 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 14:51:58 +0300 Subject: [PATCH 08/18] Added Unicode json_encoding patch --- Test/Controller/MyRoutes.php | 1 - Test/Synthetic/UnicodeTest.php | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index b98d3c4..37d550a 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -59,7 +59,6 @@ public function getTest() /** * @param string $text - * @url echo * @return string */ public function getEcho($text) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index b9ae53d..2df8569 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -29,6 +29,20 @@ private function assertEcho($test_string){ public function testUnicode() { - $this->assertEcho('test'); + $this->assertEcho('Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon'); + $this->assertEcho('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); + $this->assertEcho('Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο'); + $this->assertEcho('El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.'); + $this->assertEcho('Le cœur déçu mais l\'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.'); + $this->assertEcho('D\'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh'); + $this->assertEcho('Árvíztűrő tükörfúrógép'); + $this->assertEcho('Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa'); + $this->assertEcho('いろはにほへとちりぬるを わかよたれそつねならむ うゐのおくやまけふこえて あさきゆめみしゑひもせす'); + $this->assertEcho('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン'); + $this->assertEcho('דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה'); + $this->assertEcho('Pchnąć w tę łódź jeża lub ośm skrzyń fig'); + $this->assertEcho('В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!'); + $this->assertEcho('๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ'); + $this->assertEcho('Pijamalı hasta, yağız şoföre çabucak güvendi'); } } \ No newline at end of file From dfe773dea5a6869da19dfc3d16d1f4a71d53c51d Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 17:56:36 +0300 Subject: [PATCH 09/18] Added Unicode json_encoding patch --- Test/Controller/MyRoutes.php | 2 +- Test/Synthetic/UnicodeTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index 37d550a..664ed18 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -61,7 +61,7 @@ public function getTest() * @param string $text * @return string */ - public function getEcho($text) + public function postEcho($text) { return $text; } diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 2df8569..2d64af5 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -20,7 +20,8 @@ public function setUp() } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'get'); +// $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); + $response = $this->restService->simulateCall('/echo', 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" From f9f52d960e90d446a0995d65dbe9f8257927f6dd Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 17:59:34 +0300 Subject: [PATCH 10/18] Added Unicode json_encoding patch --- Test/Synthetic/UnicodeTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 2d64af5..de59fcd 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -20,8 +20,7 @@ public function setUp() } private function assertEcho($test_string){ -// $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); - $response = $this->restService->simulateCall('/echo', 'post'); + $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" From ad25c4fc4099170b8e4bcc2995b8e1ede204a105 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:02:10 +0300 Subject: [PATCH 11/18] Added Unicode json_encoding patch --- Test/Controller/MyRoutes.php | 1 + Test/Synthetic/UnicodeTest.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index 664ed18..3d86347 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -59,6 +59,7 @@ public function getTest() /** * @param string $text + * @url test/test * @return string */ public function postEcho($text) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index de59fcd..5dafb78 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -20,7 +20,7 @@ public function setUp() } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); + $response = $this->restService->simulateCall('/echo/test?text=' + rawurlencode($test_string), 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" From d23b81acbfd5e9a4f775731bca570a6559a4556f Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:10:29 +0300 Subject: [PATCH 12/18] Added Unicode json_encoding patch --- Test/Controller/MyRoutes.php | 1 - Test/Synthetic/UnicodeTest.php | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Test/Controller/MyRoutes.php b/Test/Controller/MyRoutes.php index 3d86347..664ed18 100644 --- a/Test/Controller/MyRoutes.php +++ b/Test/Controller/MyRoutes.php @@ -59,7 +59,6 @@ public function getTest() /** * @param string $text - * @url test/test * @return string */ public function postEcho($text) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 5dafb78..bdaf72a 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -16,11 +16,11 @@ public function setUp() { $this->restService = Server::create('/', new MyRoutes) ->setClient('RestService\\InternalClient') - ->collectRoutes(); + ->addPostRoute('echo', 'postEcho'); } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo/test?text=' + rawurlencode($test_string), 'post'); + $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" From 69f600d195f911f3fb91089bfb89f43d68666e02 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:15:30 +0300 Subject: [PATCH 13/18] Added Unicode json_encoding patch --- Test/Synthetic/UnicodeTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index bdaf72a..0f4ddbc 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -20,7 +20,8 @@ public function setUp() } private function assertEcho($test_string){ - $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); +// $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); + $response = $this->restService->simulateCall('/echo?text=test', 'post'); $this->assertEquals('{ "status": 200, "data": "' + $test_string + '" From 3a43619437ea05ad9dfd9e2bc3822b4978d99538 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:21:46 +0300 Subject: [PATCH 14/18] Added Unicode json_encoding patch --- Test/Synthetic/UnicodeTest.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 0f4ddbc..9356915 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -20,12 +20,11 @@ public function setUp() } private function assertEcho($test_string){ -// $response = $this->restService->simulateCall('/echo?text=' + rawurlencode($test_string), 'post'); - $response = $this->restService->simulateCall('/echo?text=test', 'post'); - $this->assertEquals('{ - "status": 200, - "data": "' + $test_string + '" -}', $response); + $response = $this->restService->simulateCall("/echo?text=$test_string", 'post'); + $this->assertEquals("{ + \"status\": 200, + \"data\": \"$test_string\" +}", $response); } public function testUnicode() From cfba0f8f38253b0c44d355d3d387bf38d37df61b Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:28:42 +0300 Subject: [PATCH 15/18] Added Unicode json_encoding patch --- Test/Synthetic/UnicodeTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 9356915..6c7153a 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -16,7 +16,7 @@ public function setUp() { $this->restService = Server::create('/', new MyRoutes) ->setClient('RestService\\InternalClient') - ->addPostRoute('echo', 'postEcho'); + ->collectRoutes(); } private function assertEcho($test_string){ @@ -29,7 +29,8 @@ private function assertEcho($test_string){ public function testUnicode() { - $this->assertEcho('Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon'); + $this->assertEcho('В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!'); + $this->assertEcho('Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon'); $this->assertEcho('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); $this->assertEcho('Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο'); $this->assertEcho('El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.'); @@ -41,7 +42,6 @@ public function testUnicode() $this->assertEcho('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン'); $this->assertEcho('דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה'); $this->assertEcho('Pchnąć w tę łódź jeża lub ośm skrzyń fig'); - $this->assertEcho('В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!'); $this->assertEcho('๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ'); $this->assertEcho('Pijamalı hasta, yağız şoföre çabucak güvendi'); } From 26d795cc0de597ab466da76388e464aeb7fab36e Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:49:55 +0300 Subject: [PATCH 16/18] Added Unicode json_encoding patch --- RestService/Client.php | 23 ++++++++++++++++++++++- Test/Synthetic/UnicodeTest.php | 30 +++++++++++++++--------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/RestService/Client.php b/RestService/Client.php index feaa63a..d97c46b 100644 --- a/RestService/Client.php +++ b/RestService/Client.php @@ -237,6 +237,27 @@ public function asJSON($pMessage) return $result; } + static function prepareUTF8($matches){ + return json_decode('"'.$matches[1].'"'); + } + + /** + * Format data to JSON + * + * @param string $data The original data to process. + * @return string JSON string. + */ + public function jsonEncode($data) + { + if (defined('JSON_UNESCAPED_UNICODE')) { + return json_encode($data, JSON_UNESCAPED_UNICODE); + }else{ + return preg_replace_callback('/((\\\u[01-9a-fA-F]{4})+)/', '\\Client\\prepareUTF8', + json_encode($data) + ); + } + } + /** * Indents a flat JSON string to make it more human-readable. * @@ -248,7 +269,7 @@ public function asJSON($pMessage) */ public function jsonFormat($json) { - if (!is_string($json)) $json = json_encode($json); + if (!is_string($json)) $json = $this->jsonEncode($json); $result = ''; $pos = 0; diff --git a/Test/Synthetic/UnicodeTest.php b/Test/Synthetic/UnicodeTest.php index 6c7153a..01abd4e 100644 --- a/Test/Synthetic/UnicodeTest.php +++ b/Test/Synthetic/UnicodeTest.php @@ -29,20 +29,20 @@ private function assertEcho($test_string){ public function testUnicode() { - $this->assertEcho('В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!'); - $this->assertEcho('Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon'); - $this->assertEcho('Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); - $this->assertEcho('Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο'); - $this->assertEcho('El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.'); - $this->assertEcho('Le cœur déçu mais l\'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.'); - $this->assertEcho('D\'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh'); - $this->assertEcho('Árvíztűrő tükörfúrógép'); - $this->assertEcho('Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa'); - $this->assertEcho('いろはにほへとちりぬるを わかよたれそつねならむ うゐのおくやまけふこえて あさきゆめみしゑひもせす'); - $this->assertEcho('イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン'); - $this->assertEcho('דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה'); - $this->assertEcho('Pchnąć w tę łódź jeża lub ośm skrzyń fig'); - $this->assertEcho('๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ'); - $this->assertEcho('Pijamalı hasta, yağız şoföre çabucak güvendi'); + $this->assertEcho('ru: В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!'); + $this->assertEcho('da: Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen Wolther spillede på xylofon'); + $this->assertEcho('de: Falsches Üben von Xylophonmusik quält jeden größeren Zwerg'); + $this->assertEcho('el: Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο'); + $this->assertEcho('es: El pingüino Wenceslao hizo kilómetros bajo exhaustiva lluvia y frío, añoraba a su querido cachorro.'); + $this->assertEcho('fr: Le cœur déçu mais l\'âme plutôt naïve, Louÿs rêva de crapaüter en canoë au delà des îles, près du mälström où brûlent les novæ.'); + $this->assertEcho('ga: D\'fhuascail Íosa, Úrmhac na hÓighe Beannaithe, pór Éava agus Ádhaimh'); + $this->assertEcho('hu: Árvíztűrő tükörfúrógép'); + $this->assertEcho('is: Kæmi ný öxi hér ykist þjófum nú bæði víl og ádrepa'); + $this->assertEcho('jp1: いろはにほへとちりぬるを わかよたれそつねならむ うゐのおくやまけふこえて あさきゆめみしゑひもせす'); + $this->assertEcho('jp2: イロハニホヘト チリヌルヲ ワカヨタレソ ツネナラム ウヰノオクヤマ ケフコエテ アサキユメミシ ヱヒモセスン'); + $this->assertEcho('iw: דג סקרן שט בים מאוכזב ולפתע מצא לו חברה איך הקליטה'); + $this->assertEcho('pl: Pchnąć w tę łódź jeża lub ośm skrzyń fig'); + $this->assertEcho('th: ๏ เป็นมนุษย์สุดประเสริฐเลิศคุณค่า กว่าบรรดาฝูงสัตว์เดรัจฉาน จงฝ่าฟันพัฒนาวิชาการ อย่าล้างผลาญฤๅเข่นฆ่าบีฑาใคร ไม่ถือโทษโกรธแช่งซัดฮึดฮัดด่า หัดอภัยเหมือนกีฬาอัชฌาสัย ปฏิบัติประพฤติกฎกำหนดใจ พูดจาให้จ๊ะๆ จ๋าๆ น่าฟังเอย ฯ'); + $this->assertEcho('tr: Pijamalı hasta, yağız şoföre çabucak güvendi'); } } \ No newline at end of file From e368d31fad5246ebea92d08b8988cde2f32337d4 Mon Sep 17 00:00:00 2001 From: Limych Date: Tue, 13 Oct 2015 18:52:23 +0300 Subject: [PATCH 17/18] Added Unicode json_encoding patch --- RestService/Client.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RestService/Client.php b/RestService/Client.php index d97c46b..1dd031e 100644 --- a/RestService/Client.php +++ b/RestService/Client.php @@ -237,7 +237,7 @@ public function asJSON($pMessage) return $result; } - static function prepareUTF8($matches){ + function prepareUTF8($matches){ return json_decode('"'.$matches[1].'"'); } @@ -252,8 +252,8 @@ public function jsonEncode($data) if (defined('JSON_UNESCAPED_UNICODE')) { return json_encode($data, JSON_UNESCAPED_UNICODE); }else{ - return preg_replace_callback('/((\\\u[01-9a-fA-F]{4})+)/', '\\Client\\prepareUTF8', - json_encode($data) + return preg_replace_callback('/((\\\u[01-9a-fA-F]{4})+)/', + array($this, 'prepareUTF8'), json_encode($data) ); } } From 1a781dae0d4478c8b0c7b6981a8b56e951530b78 Mon Sep 17 00:00:00 2001 From: Limych Date: Wed, 28 Oct 2015 20:20:49 +0300 Subject: [PATCH 18/18] Added automatic data compression if it supported by PHP and client. --- RestService/Client.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/RestService/Client.php b/RestService/Client.php index 1dd031e..4bb1da3 100644 --- a/RestService/Client.php +++ b/RestService/Client.php @@ -120,6 +120,23 @@ public function getController() return $this->controller; } + /** + * @param string $out + */ + protected function output($out){ + if( !ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ){ + header('Vary: Accept-Encoding'); // Handle proxies + if( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') ){ + header('Content-Encoding: deflate'); + $out = gzdeflate($out, 3); + } elseif( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ){ + header('Content-Encoding: gzip'); + $out = gzencode($out, 3); + } + } + echo $out; + } + /** * Sends the actual response. * @@ -145,7 +162,7 @@ public function sendResponse($pHttpCode = '200', $pMessage) $pMessage = array_reverse($pMessage, true); $method = $this->getOutputFormatMethod($this->getOutputFormat()); - echo $this->$method($pMessage); + self::output($this->$method($pMessage)); exit; }