THRIFT-3046: Allow PSR4 class loading for generated classes (PHP)

Allow test to be used with psr4 autoloading

This closes #1010
diff --git a/test/php/Makefile.am b/test/php/Makefile.am
index 11974da..7c4347f 100755
--- a/test/php/Makefile.am
+++ b/test/php/Makefile.am
@@ -22,13 +22,15 @@
 stubs: ../ThriftTest.thrift
 	$(THRIFT) --gen php ../ThriftTest.thrift
 	$(THRIFT) --gen php:inlined ../ThriftTest.thrift
+	$(MKDIR_P) gen-php-psr4
+	$(THRIFT) -out gen-php-psr4 --gen php:psr4 ../ThriftTest.thrift
 
 precross: stubs
 
 check: stubs
 
 clean-local:
-	$(RM) -r gen-php gen-phpi
+	$(RM) -r gen-php gen-phpi gen-php-psr4
 
 client: stubs
 	php TestClient.php
diff --git a/test/php/TestClient.php b/test/php/TestClient.php
index 946334d..2443ee0 100755
--- a/test/php/TestClient.php
+++ b/test/php/TestClient.php
@@ -15,7 +15,11 @@
 
 $loader = new ThriftClassLoader();
 $loader->registerNamespace('Thrift', __DIR__ . '/../../lib/php/lib');
-$loader->registerDefinition('ThriftTest', $GEN_DIR);
+if ($GEN_DIR === 'gen-php-psr4') {
+  $loader->registerNamespace('ThriftTest', $GEN_DIR);
+} else {
+  $loader->registerDefinition('ThriftTest', $GEN_DIR);
+}
 $loader->register();
 
 /*
diff --git a/test/php/TestPsr4.php b/test/php/TestPsr4.php
new file mode 100644
index 0000000..d30bf1c
--- /dev/null
+++ b/test/php/TestPsr4.php
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+<?php
+$GEN_DIR = 'gen-php-psr4';
+include_once('TestClient.php');
+?>