summaryrefslogtreecommitdiff
path: root/lib/php
diff options
context:
space:
mode:
authorRobert Lu <robberphex@gmail.com>2018-01-17 19:40:39 +0800
committerDuru Can Celasun <dcelasun@apache.org>2018-03-15 11:05:30 +0100
commit68707d92192ffc82a98488e4cdd1033e20cdf3a5 (patch)
treec93baf0c5d2a81ec5546d831cf02363ba25eced1 /lib/php
parente58f75daa8a4e5efec4ff434d9427a05973e86fe (diff)
downloadthrift-68707d92192ffc82a98488e4cdd1033e20cdf3a5.tar.gz
THRIFT-4474: Use PSR-4 autoloader by default
Client: php This closes #1479
Diffstat (limited to 'lib/php')
-rw-r--r--lib/php/README.md33
-rw-r--r--lib/php/test/JsonSerialize/JsonSerializeTest.php9
-rwxr-xr-xlib/php/test/Makefile.am4
-rw-r--r--lib/php/test/Protocol/BinarySerializerTest.php9
-rw-r--r--lib/php/test/Protocol/TJSONProtocolTest.php9
-rw-r--r--lib/php/test/Protocol/TSimpleJSONProtocolTest.php10
-rw-r--r--lib/php/test/Validator/ValidatorTest.php9
-rw-r--r--lib/php/test/Validator/ValidatorTestOop.php7
8 files changed, 46 insertions, 44 deletions
diff --git a/lib/php/README.md b/lib/php/README.md
index c24ee2c0c..7170104df 100644
--- a/lib/php/README.md
+++ b/lib/php/README.md
@@ -1,7 +1,6 @@
Thrift PHP Software Library
-License
-=======
+# License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -20,8 +19,7 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-Using Thrift with PHP
-=====================
+# Using Thrift with PHP
Thrift requires PHP 5. Thrift makes as few assumptions about your PHP
environment as possible while trying to make some more advanced PHP
@@ -29,25 +27,34 @@ features (i.e. APC cacheing using asbolute path URLs) as simple as possible.
To use Thrift in your PHP codebase, take the following steps:
-#1) Copy all of thrift/lib/php/lib into your PHP codebase
-#2) Configure Symfony Autoloader (or whatever you usually use)
+1. Copy all of thrift/lib/php/lib into your PHP codebase
+2. Configure Symfony Autoloader (or whatever you usually use)
After that, you have to manually include the Thrift package
created by the compiler:
+```
require_once 'packages/Service/Service.php';
require_once 'packages/Service/Types.php';
+```
-Dependencies
-============
+# Dependencies
PHP_INT_SIZE
- This built-in signals whether your architecture is 32 or 64 bit and is
- used by the TBinaryProtocol to properly use pack() and unpack() to
- serialize data.
+ This built-in signals whether your architecture is 32 or 64 bit and is
+ used by the TBinaryProtocol to properly use pack() and unpack() to
+ serialize data.
apc_fetch(), apc_store()
- APC cache is used by the TSocketPool class. If you do not have APC installed,
- Thrift will fill in null stub function definitions.
+ APC cache is used by the TSocketPool class. If you do not have APC installed,
+ Thrift will fill in null stub function definitions.
+
+# Breaking Changes
+
+## 0.12.0
+
+1. [PSR-4](https://www.php-fig.org/psr/psr-4/) loader is now the default. If you want to use class maps instead, use `-gen php:classmap`.
+
+2. If using PSR-4, use `$thriftClassLoader->registerNamespace('namespace', '<path>')` instead of `$thriftClassLoader->registerDefinition('namespace', '<path>')`.
diff --git a/lib/php/test/JsonSerialize/JsonSerializeTest.php b/lib/php/test/JsonSerialize/JsonSerializeTest.php
index 8c6459560..c6686525f 100644
--- a/lib/php/test/JsonSerialize/JsonSerializeTest.php
+++ b/lib/php/test/JsonSerialize/JsonSerializeTest.php
@@ -22,9 +22,8 @@ namespace Test\Thrift\JsonSerialize;
use PHPUnit\Framework\TestCase;
use stdClass;
-use Thrift\ClassLoader\ThriftClassLoader;
-require_once __DIR__ . '/../../../../vendor/autoload.php';
+require __DIR__ . '/../../../../vendor/autoload.php';
/**
* @runTestsInSeparateProcesses
@@ -36,9 +35,9 @@ class JsonSerializeTest extends TestCase
if (version_compare(phpversion(), '5.4', '<')) {
$this->markTestSkipped('Requires PHP 5.4 or newer!');
}
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages/phpjs');
- $loader->register();
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/phpjs');
}
public function testEmptyStruct()
diff --git a/lib/php/test/Makefile.am b/lib/php/test/Makefile.am
index 5c86e3564..482468826 100755
--- a/lib/php/test/Makefile.am
+++ b/lib/php/test/Makefile.am
@@ -20,8 +20,8 @@
PHPUNIT=php $(top_srcdir)/vendor/bin/phpunit
stubs: ../../../test/ThriftTest.thrift TestValidators.thrift
- mkdir -p ./packages
- $(THRIFT) --gen php -r --out ./packages ../../../test/ThriftTest.thrift
+ mkdir -p ./packages/php
+ $(THRIFT) --gen php -r --out ./packages/php ../../../test/ThriftTest.thrift
mkdir -p ./packages/phpv
mkdir -p ./packages/phpvo
mkdir -p ./packages/phpjs
diff --git a/lib/php/test/Protocol/BinarySerializerTest.php b/lib/php/test/Protocol/BinarySerializerTest.php
index 7e8728012..71b0bb506 100644
--- a/lib/php/test/Protocol/BinarySerializerTest.php
+++ b/lib/php/test/Protocol/BinarySerializerTest.php
@@ -24,10 +24,9 @@
namespace Test\Thrift\Protocol;
use PHPUnit\Framework\TestCase;
-use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Serializer\TBinarySerializer;
-require_once __DIR__ . '/../../../../vendor/autoload.php';
+require __DIR__ . '/../../../../vendor/autoload.php';
/***
* This test suite depends on running the compiler against the
@@ -42,9 +41,9 @@ class BinarySerializerTest extends TestCase
{
public function setUp()
{
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages');
- $loader->register();
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/php');
}
/**
diff --git a/lib/php/test/Protocol/TJSONProtocolTest.php b/lib/php/test/Protocol/TJSONProtocolTest.php
index bab4389a0..bf0ecce42 100644
--- a/lib/php/test/Protocol/TJSONProtocolTest.php
+++ b/lib/php/test/Protocol/TJSONProtocolTest.php
@@ -25,11 +25,10 @@ namespace Test\Thrift\Protocol;
use PHPUnit\Framework\TestCase;
use Test\Thrift\Fixtures;
-use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Protocol\TJSONProtocol;
use Thrift\Transport\TMemoryBuffer;
-require_once __DIR__ . '/../../../../vendor/autoload.php';
+require __DIR__ . '/../../../../vendor/autoload.php';
/***
* This test suite depends on running the compiler against the
@@ -47,9 +46,9 @@ class TJSONProtocolTest extends TestCase
public static function setUpBeforeClass()
{
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages');
- $loader->register();
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/php');
Fixtures::populateTestArgs();
TJSONProtocolFixtures::populateTestArgsJSON();
diff --git a/lib/php/test/Protocol/TSimpleJSONProtocolTest.php b/lib/php/test/Protocol/TSimpleJSONProtocolTest.php
index ec6432147..e4a13736e 100644
--- a/lib/php/test/Protocol/TSimpleJSONProtocolTest.php
+++ b/lib/php/test/Protocol/TSimpleJSONProtocolTest.php
@@ -25,11 +25,10 @@ namespace Test\Thrift\Protocol;
use PHPUnit\Framework\TestCase;
use Test\Thrift\Fixtures;
-use Thrift\ClassLoader\ThriftClassLoader;
use Thrift\Protocol\TSimpleJSONProtocol;
use Thrift\Transport\TMemoryBuffer;
-require_once __DIR__ . '/../../../../vendor/autoload.php';
+require __DIR__ . '/../../../../vendor/autoload.php';
/***
* This test suite depends on running the compiler against the
@@ -47,9 +46,10 @@ class TSimpleJSONProtocolTest extends TestCase
public static function setUpBeforeClass()
{
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages');
- $loader->register();
+
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/php');
Fixtures::populateTestArgs();
TSimpleJSONProtocolFixtures::populateTestArgsSimpleJSON();
diff --git a/lib/php/test/Validator/ValidatorTest.php b/lib/php/test/Validator/ValidatorTest.php
index ace3075de..fa6c7a9f7 100644
--- a/lib/php/test/Validator/ValidatorTest.php
+++ b/lib/php/test/Validator/ValidatorTest.php
@@ -20,7 +20,7 @@
namespace Test\Thrift;
-require_once __DIR__ . '/../../../../vendor/autoload.php';
+require __DIR__ . '/../../../../vendor/autoload.php';
use Thrift\ClassLoader\ThriftClassLoader;
@@ -34,9 +34,8 @@ class ValidatorTest extends BaseValidatorTest
{
public function setUp()
{
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages/phpv');
- $loader->registerDefinition('TestValidators', __DIR__ . '/../packages/phpv');
- $loader->register();
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/phpv');
}
}
diff --git a/lib/php/test/Validator/ValidatorTestOop.php b/lib/php/test/Validator/ValidatorTestOop.php
index 5a8e3bfb9..93bca4d0c 100644
--- a/lib/php/test/Validator/ValidatorTestOop.php
+++ b/lib/php/test/Validator/ValidatorTestOop.php
@@ -34,9 +34,8 @@ class ValidatorTestOop extends BaseValidatorTest
{
public function setUp()
{
- $loader = new ThriftClassLoader();
- $loader->registerDefinition('ThriftTest', __DIR__ . '/../packages/phpvo');
- $loader->registerDefinition('TestValidators', __DIR__ . '/../packages/phpvo');
- $loader->register();
+ /** @var \Composer\Autoload\ClassLoader $loader */
+ $loader = require __DIR__ . '/../../../../vendor/autoload.php';
+ $loader->addPsr4('', __DIR__ . '/../packages/phpvo');
}
}