Permalink
Browse files

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
  • Loading branch information...
1 parent f88f9c2 commit 21c0a85079e3e1b5ee475bd6654512079fe5df68 @bufferoverflow bufferoverflow committed Sep 5, 2012
Showing with 7,064 additions and 4,675 deletions.
  1. +221 −254 compiler/cpp/src/generate/t_php_generator.cc
  2. +52 −19 lib/php/Makefile.am
  3. +6 −16 lib/php/README
  4. +19 −7 lib/php/README.apache
  5. +367 −0 lib/php/lib/Thrift/Base/TBase.php
  6. +223 −0 lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php
  7. +69 −0 lib/php/lib/Thrift/Exception/TApplicationException.php
  8. +369 −0 lib/php/lib/Thrift/Exception/TException.php
  9. +48 −0 lib/php/lib/Thrift/Exception/TProtocolException.php
  10. +41 −0 lib/php/lib/Thrift/Exception/TTransportException.php
  11. +43 −0 lib/php/lib/Thrift/Factory/TBinaryProtocolFactory.php
  12. +39 −0 lib/php/lib/Thrift/Factory/TCompactProtocolFactory.php
  13. +41 −0 lib/php/lib/Thrift/Factory/TJSONProtocolFactory.php
  14. +35 −0 lib/php/lib/Thrift/Factory/TProtocolFactory.php
  15. +63 −0 lib/php/lib/Thrift/Factory/TStringFuncFactory.php
  16. +16 −0 lib/php/lib/Thrift/Factory/TTransportFactory.php
  17. +39 −0 lib/php/lib/Thrift/Protocol/JSON/BaseContext.php
  18. +52 −0 lib/php/lib/Thrift/Protocol/JSON/ListContext.php
  19. +54 −0 lib/php/lib/Thrift/Protocol/JSON/LookaheadReader.php
  20. +60 −0 lib/php/lib/Thrift/Protocol/JSON/PairContext.php
  21. +396 −0 lib/php/lib/Thrift/Protocol/TBinaryProtocol.php
  22. +47 −0 lib/php/lib/Thrift/Protocol/TBinaryProtocolAccelerated.php
  23. +669 −0 lib/php/lib/Thrift/Protocol/TCompactProtocol.php
  24. +694 −0 lib/php/lib/Thrift/Protocol/TJSONProtocol.php
  25. +346 −0 lib/php/lib/Thrift/Protocol/TProtocol.php
  26. +73 −0 lib/php/lib/Thrift/Serializer/TBinarySerializer.php
  27. +119 −0 lib/php/lib/Thrift/Server/TForkingServer.php
  28. +101 −0 lib/php/lib/Thrift/Server/TServer.php
  29. +98 −0 lib/php/lib/Thrift/Server/TServerSocket.php
  30. +54 −0 lib/php/lib/Thrift/Server/TServerTransport.php
  31. +57 −0 lib/php/lib/Thrift/Server/TSimpleServer.php
  32. +38 −0 lib/php/lib/Thrift/StringFunc/Core.php
  33. +45 −0 lib/php/lib/Thrift/StringFunc/Mbstring.php
  34. +27 −0 lib/php/lib/Thrift/StringFunc/TStringFunc.php
  35. +165 −0 lib/php/lib/Thrift/Transport/TBufferedTransport.php
  36. +183 −0 lib/php/lib/Thrift/Transport/TFramedTransport.php
  37. +205 −0 lib/php/lib/Thrift/Transport/THttpClient.php
  38. +87 −0 lib/php/lib/Thrift/Transport/TMemoryBuffer.php
  39. +50 −0 lib/php/lib/Thrift/Transport/TNullTransport.php
  40. +114 −0 lib/php/lib/Thrift/Transport/TPhpStream.php
  41. +326 −0 lib/php/lib/Thrift/Transport/TSocket.php
  42. +295 −0 lib/php/lib/Thrift/Transport/TSocketPool.php
  43. +93 −0 lib/php/lib/Thrift/Transport/TTransport.php
  44. +33 −0 lib/php/lib/Thrift/Type/TMessageType.php
  45. +46 −0 lib/php/lib/Thrift/Type/TType.php
  46. +0 −429 lib/php/src/protocol/TBinaryProtocol.php
  47. +0 −70 lib/php/src/protocol/TBinarySerializer.php
  48. +0 −678 lib/php/src/protocol/TCompactProtocol.php
  49. +0 −808 lib/php/src/protocol/TJSONProtocol.php
  50. +0 −376 lib/php/src/protocol/TProtocol.php
  51. +0 −114 lib/php/src/server/TForkingServer.php
  52. +0 −95 lib/php/src/server/TServer.php
  53. +0 −54 lib/php/src/server/TSimpleServer.php
  54. +0 −161 lib/php/src/transport/TBufferedTransport.php
  55. +0 −179 lib/php/src/transport/TFramedTransport.php
  56. +0 −200 lib/php/src/transport/THttpClient.php
  57. +0 −82 lib/php/src/transport/TMemoryBuffer.php
  58. +0 −46 lib/php/src/transport/TNullTransport.php
  59. +0 −109 lib/php/src/transport/TPhpStream.php
  60. +0 −96 lib/php/src/transport/TServerSocket.php
  61. +0 −50 lib/php/src/transport/TServerTransport.php
  62. +0 −320 lib/php/src/transport/TSocket.php
  63. +0 −294 lib/php/src/transport/TSocketPool.php
  64. +0 −106 lib/php/src/transport/TTransport.php
  65. +0 −12 lib/php/src/transport/TTransportFactory.php
  66. +4 −4 lib/php/test/Makefile.am
  67. +192 −0 lib/php/test/Test/Thrift/Fixtures.php
  68. +561 −0 lib/php/test/Test/Thrift/Protocol/TestTJSONProtocol.php
  69. +31 −35 test/php/TestClient.php
  70. +27 −28 tutorial/php/PhpClient.php
  71. +31 −33 tutorial/php/PhpServer.php

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -34,29 +34,62 @@ phpmoduledir = `php-config --extension-dir`
phpmodule_SCRIPTS = src/ext/thrift_protocol/modules/thrift_protocol.so
endif
-phpdir = $(PHP_PREFIX)
-php_DATA = \
- src/autoload.php \
- src/Thrift.php
+phpdir = $(PHP_PREFIX)/Thrift
-phpprotocoldir = $(phpdir)/protocol
+phpbasedir = $(phpdir)/Base
+phpbase_DATA = \
+ lib/Thrift/Base/TBase.php
+
+phpexceptiondir = $(phpdir)/Exception
+phpexception_DATA = \
+ lib/Thrift/Exception/TApplicationException.php \
+ lib/Thrift/Exception/TException.php \
+ lib/Thrift/Exception/TProtocolException.php \
+ lib/Thrift/Exception/TTransportException.php
+
+phpfactorydir = $(phpdir)/Factory
+phpfactory_DATA = \
+ lib/Thrift/Factory/TBinaryProtocolFactory.php \
+ lib/Thrift/Factory/TCompactProtocolFactory.php \
+ lib/Thrift/Factory/TJSONProtocolFactory.php \
+ lib/Thrift/Factory/TProtocolFactory.php \
+ lib/Thrift/Factory/TTransportFactory.php
+
+phpprotocoldir = $(phpdir)/Protocol
phpprotocol_DATA = \
- src/protocol/TBinaryProtocol.php \
- src/protocol/TBinarySerializer.php \
- src/protocol/TProtocol.php \
- src/protocol/TJSONProtocol.php
+ lib/Thrift/Protocol/TBinaryProtocolAccelerated.php \
+ lib/Thrift/Protocol/TBinaryProtocol.php \
+ lib/Thrift/Protocol/TCompactProtocol.php \
+ lib/Thrift/Protocol/TJSONProtocol.php \
+ lib/Thrift/Protocol/TProtocol.php
-phptransportdir = $(phpdir)/transport
+phpprotocoljsondir = $(phpprotocoldir)/JSON
+phpprotocoljson_DATA = \
+ lib/Thrift/Protocol/JSON/BaseContext.php \
+ lib/Thrift/Protocol/JSON/ListContext.php \
+ lib/Thrift/Protocol/JSON/LookaheadReader.php \
+ lib/Thrift/Protocol/JSON/PairContext.php
+
+phpserializerdir = $(phpdir)/Serializer
+phpserializer_DATA = \
+ lib/Thrift/Serializer/TBinarySerializer.php
+
+phptransportdir = $(phpdir)/Transport
phptransport_DATA = \
- src/transport/TBufferedTransport.php \
- src/transport/TFramedTransport.php \
- src/transport/THttpClient.php \
- src/transport/TMemoryBuffer.php \
- src/transport/TNullTransport.php \
- src/transport/TPhpStream.php \
- src/transport/TSocket.php \
- src/transport/TSocketPool.php \
- src/transport/TTransport.php
+ lib/Thrift/Transport/TBufferedTransport.php \
+ lib/Thrift/Transport/TFramedTransport.php \
+ lib/Thrift/Transport/THttpClient.php \
+ lib/Thrift/Transport/TMemoryBuffer.php \
+ lib/Thrift/Transport/TNullTransport.php \
+ lib/Thrift/Transport/TPhpStream.php \
+ lib/Thrift/Transport/TSocket.php \
+ lib/Thrift/Transport/TSocketPool.php \
+ lib/Thrift/Transport/TTransport.php
+
+phptypedir = $(phpdir)/Type
+phptype_DATA = \
+ lib/Thrift/Type/TMessageType.php \
+ lib/Thrift/Type/TType.php
EXTRA_DIST = src thrift_protocol.ini README.apache
View
@@ -29,24 +29,14 @@ 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/src into your PHP codebase
-#2) Set $GLOBALS['THRIFT_ROOT'] to the path you installed Thrift
-#3) include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
+#1) Copy all of thrift/lib/php/lib into your PHP codebase
+#2) Configure Symfony Autoloader (or whatever you usually use)
-Note that #3 must be done before including any other Thrift files.
-If you do not do #2, Thrift.php will set this global for you, but it will be
-done using dirname(__FILE__), which is less efficient than providing the static
-string yourself.
+After thaht, you have to manually include the Thrift package
+created by the compiler:
-When you generate a Thrift package using the compiler, it makes an assumption
-about where your generated code will live. If your file is "MyPackage.thrift",
-the generated files must be installed into:
-
-$GLOBALS['THRIFT_ROOT'].'/packages/MyPackage/';
-
-This allows the code generator to compile your code without any extra flags
-for the target directory names while still allowing your include paths to
-be absolute (if you have an absolute THRIFT_ROOT).
+require_once 'packages/Service/Service.php';
+require_once 'packages/Service/Types.php';
Dependencies
============
View
@@ -32,17 +32,29 @@ Sample Code
<?php
+namespace MyNamespace;
+
/**
- * Example of how to build a Thrift server in Apache/PHP
- *
+ * Include path
+ */
+$THRIFT_ROOT = '/your/thrift/root/lib';
+
+/**
+ * Init Autloader
*/
+require_once $THRIFT_ROOT . '/Thrift/ClassLoader/ThriftClassLoader.php';
-$GLOBALS['THRIFT_ROOT'] = '/your/thrift/root';
+$loader = new ThriftClassLoader();
+$loader->registerNamespace('Thrift', $THRIFT_ROOT);
+$loader->registerDefinition('Thrift', $THRIFT_ROOT . '/packages');
+$loader->register();
-include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
-include_once $GLOBALS['THRIFT_ROOT'].'/packages/Service/Service.php';
-include_once $GLOBALS['THRIFT_ROOT'].'/transport/TPhpStream.php';
-include_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
+use Thrift\Transport\TPhpStream;
+use Thrift\Protocol\TBinaryProtocol;
+
+/**
+ * Example of how to build a Thrift server in Apache/PHP
+ */
class ServiceHandler implements ServiceIf {
// Implement your interface and methods here
Oops, something went wrong.

0 comments on commit 21c0a85

Please sign in to comment.