THRIFT-1615 PHP Namespace (was Thrift for Symfony 2)
Patch: Xavier HAUSHERR


git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1381323 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/php/TestClient.php b/test/php/TestClient.php
index 009137b..4df498c 100755
--- a/test/php/TestClient.php
+++ b/test/php/TestClient.php
@@ -1,4 +1,23 @@
 <?php
+
+namespace test\php;
+
+require_once __DIR__.'/../../lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php';
+
+use Thrift\ClassLoader\ThriftClassLoader;
+
+if (!isset($GEN_DIR)) {
+  $GEN_DIR = 'gen-php';
+}
+if (!isset($MODE)) {
+  $MODE = 'normal';
+}
+
+$loader = new ThriftClassLoader();
+$loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
+$loader->registerDefinition('ThriftTest', $GEN_DIR);
+$loader->register();
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements. See the NOTICE file
@@ -18,40 +37,17 @@
  * under the License.
  */
 
-if (!isset($GEN_DIR)) {
-  $GEN_DIR = 'gen-php';
-}
-if (!isset($MODE)) {
-  $MODE = 'normal';
-}
-
-/** Set the Thrift root */
-$GLOBALS['THRIFT_ROOT'] = '../../lib/php/src';
-
 /** Include the Thrift base */
-require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
-
 /** Include the binary protocol */
-require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
+use Thrift\Protocol\TBinaryProtocol;
 
 /** Include the socket layer */
-require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocketPool.php';
+use Thrift\Transport\TSocket;
+use Thrift\Transport\TSocketPool;
 
 /** Include the socket layer */
-require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
-require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
-
-echo '==============================='."\n";
-echo ' SAFE TO IGNORE THESE IN TEST'."\n";
-echo '==============================='."\n";
-
-/** Include the generated code */
-require_once $GEN_DIR.'/ThriftTest/ThriftTest.php';
-require_once $GEN_DIR.'/ThriftTest/ThriftTest_types.php';
-
-echo '==============================='."\n";
-echo ' END OF SAFE ERRORS SECTION'."\n";
-echo '==============================='."\n\n";
+use Thrift\Transport\TFramedTransport;
+use Thrift\Transport\TBufferedTransport;
 
 $host = 'localhost';
 $port = 9090;
@@ -72,17 +68,17 @@
 
 if ($MODE == 'inline') {
   $transport = $socket;
-  $testClient = new ThriftTest_ThriftTestClient($transport);
+  $testClient = new \ThriftTest\ThriftTestClient($transport);
 } else if ($MODE == 'framed') {
   $framedSocket = new TFramedTransport($socket);
   $transport = $framedSocket;
   $protocol = new TBinaryProtocol($transport);
-  $testClient = new ThriftTest_ThriftTestClient($protocol);
+  $testClient = new \ThriftTest\ThriftTestClient($protocol);
 } else {
   $bufferedSocket = new TBufferedTransport($socket, 1024, 1024);
   $transport = $bufferedSocket;
   $protocol = new TBinaryProtocol($transport);
-  $testClient = new ThriftTest_ThriftTestClient($protocol);
+  $testClient = new \ThriftTest\ThriftTestClient($protocol);
 }
 
 $transport->open();
@@ -135,7 +131,7 @@
  * STRUCT TEST
  */
 print_r("testStruct({\"Zero\", 1, -3, -5})");
-$out = new ThriftTest_Xtruct();
+$out = new \ThriftTest\Xtruct();
 $out->string_thing = "Zero";
 $out->byte_thing = 1;
 $out->i32_thing = -3;
@@ -150,7 +146,7 @@
  * NESTED STRUCT TEST
  */
 print_r("testNest({1, {\"Zero\", 1, -3, -5}), 5}");
-$out2 = new ThriftTest_Xtruct2();
+$out2 = new \ThriftTest\Xtruct2();
 $out2->byte_thing = 1;
 $out2->struct_thing = $out;
 $out2->i32_thing = 5;
@@ -305,9 +301,9 @@
 /**
  * INSANITY TEST
  */
-$insane = new ThriftTest_Insanity();
+$insane = new \ThriftTest\Insanity();
 $insane->userMap[ThriftTest_Numberz::FIVE] = 5000;
-$truck = new ThriftTest_Xtruct();
+$truck = new \ThriftTest\Xtruct();
 $truck->string_thing = "Truck";
 $truck->byte_thing = 8;
 $truck->i32_thing = 8;