auser-poolparty 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/bin/cloud-compile +6 -1
- data/config/jeweler.rb +1 -3
- data/lib/cloud_providers/cloud_provider_instance.rb +11 -1
- data/lib/dependency_resolvers/chef/resources/chef_recipe.rb +51 -0
- data/lib/dependency_resolvers/chef.rb +12 -3
- data/lib/mixins/callbacks.rb +6 -2
- data/lib/poolparty/plugins/apache2/passenger_site.rb +2 -2
- data/test/fixtures/chef/recipes/sudo/attributes/sudoers.rb +30 -0
- data/test/fixtures/chef/recipes/sudo/recipes/default.rb +33 -0
- data/test/fixtures/chef/recipes/sudo/templates/default/sudoers.erb +22 -0
- data/test/lib/dependency_resolvers/chef/resources/chef_recipe_test.rb +21 -0
- data/test/lib/dependency_resolvers/chef_test.rb +8 -1
- data/vendor/gems/thrift/CHANGELOG +1 -0
- data/vendor/gems/thrift/Makefile.am +25 -6
- data/vendor/gems/thrift/Manifest +81 -0
- data/vendor/gems/thrift/README +17 -111
- data/vendor/gems/thrift/Rakefile +104 -0
- data/vendor/gems/thrift/{lib/hs/Setup.lhs → benchmark/Benchmark.thrift} +5 -4
- data/vendor/gems/thrift/benchmark/benchmark.rb +271 -0
- data/vendor/gems/thrift/benchmark/client.rb +74 -0
- data/vendor/gems/thrift/benchmark/server.rb +82 -0
- data/vendor/gems/thrift/benchmark/thin_server.rb +44 -0
- data/vendor/gems/thrift/ext/binary_protocol_accelerated.c +474 -0
- data/vendor/gems/thrift/{lib/cocoa/src/protocol/TProtocolException.m → ext/binary_protocol_accelerated.h} +1 -4
- data/vendor/gems/thrift/ext/compact_protocol.c +665 -0
- data/vendor/gems/thrift/{lib/cocoa/src/protocol/TProtocolException.h → ext/compact_protocol.h} +1 -6
- data/vendor/gems/thrift/ext/constants.h +95 -0
- data/vendor/gems/thrift/{contrib/fb303/Makefile.am → ext/extconf.rb} +8 -13
- data/vendor/gems/thrift/{compiler/cpp/src/platform.h → ext/macros.h} +18 -13
- data/vendor/gems/thrift/ext/memory_buffer.c +76 -0
- data/vendor/gems/thrift/{lib/csharp/src/Protocol/TMessageType.cs → ext/memory_buffer.h} +2 -13
- data/vendor/gems/thrift/ext/protocol.c +185 -0
- data/vendor/gems/thrift/{lib/csharp/src/TProcessor.cs → ext/protocol.h} +2 -11
- data/vendor/gems/thrift/ext/struct.c +606 -0
- data/vendor/gems/thrift/ext/struct.h +67 -0
- data/vendor/gems/thrift/ext/thrift_native.c +194 -0
- data/vendor/gems/thrift/lib/thrift/client.rb +62 -0
- data/vendor/gems/thrift/{contrib/fb303/py/fb303_scripts/__init__.py → lib/thrift/core_ext/fixnum.rb} +13 -4
- data/vendor/gems/thrift/{contrib/fb303/global_footer.mk → lib/thrift/core_ext.rb} +4 -2
- data/vendor/gems/thrift/lib/thrift/exceptions.rb +82 -0
- data/vendor/gems/thrift/lib/thrift/processor.rb +57 -0
- data/vendor/gems/thrift/lib/thrift/protocol/base_protocol.rb +290 -0
- data/vendor/gems/thrift/lib/thrift/protocol/binary_protocol.rb +225 -0
- data/vendor/gems/thrift/{cleanup.sh → lib/thrift/protocol/binary_protocol_accelerated.rb} +19 -42
- data/vendor/gems/thrift/lib/thrift/protocol/compact_protocol.rb +422 -0
- data/vendor/gems/thrift/lib/thrift/serializer/deserializer.rb +33 -0
- data/vendor/gems/thrift/{bootstrap.sh → lib/thrift/serializer/serializer.rb} +17 -18
- data/vendor/gems/thrift/lib/thrift/server/base_server.rb +31 -0
- data/vendor/gems/thrift/lib/thrift/server/mongrel_http_server.rb +58 -0
- data/vendor/gems/thrift/lib/thrift/server/nonblocking_server.rb +296 -0
- data/vendor/gems/thrift/lib/thrift/server/simple_server.rb +43 -0
- data/vendor/gems/thrift/lib/thrift/server/thread_pool_server.rb +75 -0
- data/vendor/gems/thrift/lib/thrift/server/threaded_server.rb +47 -0
- data/vendor/gems/thrift/lib/thrift/struct.rb +298 -0
- data/vendor/gems/thrift/{contrib/fb303/bootstrap.sh → lib/thrift/thrift_native.rb} +5 -7
- data/vendor/gems/thrift/lib/{erl/Makefile → thrift/transport/base_server_transport.rb} +20 -20
- data/vendor/gems/thrift/lib/thrift/transport/base_transport.rb +70 -0
- data/vendor/gems/thrift/lib/thrift/transport/buffered_transport.rb +77 -0
- data/vendor/gems/thrift/lib/thrift/transport/framed_transport.rb +90 -0
- data/vendor/gems/thrift/lib/thrift/transport/http_client_transport.rb +45 -0
- data/vendor/gems/thrift/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/vendor/gems/thrift/lib/thrift/transport/memory_buffer_transport.rb +96 -0
- data/vendor/gems/thrift/lib/thrift/transport/server_socket.rb +63 -0
- data/vendor/gems/thrift/lib/thrift/transport/socket.rb +136 -0
- data/vendor/gems/thrift/lib/{java/Makefile.am → thrift/transport/unix_server_socket.rb} +39 -17
- data/vendor/gems/thrift/{contrib/fb303/global_header.mk → lib/thrift/transport/unix_socket.rb} +23 -21
- data/vendor/gems/thrift/lib/thrift/types.rb +101 -0
- data/vendor/gems/thrift/lib/thrift.rb +59 -0
- data/vendor/gems/thrift/script/proto_benchmark.rb +121 -0
- data/vendor/gems/thrift/{lib/Makefile.am → script/read_struct.rb} +24 -36
- data/vendor/gems/thrift/{contrib/fb303/py/setup.py → script/write_struct.rb} +8 -5
- data/vendor/gems/thrift/setup.rb +1585 -0
- data/vendor/gems/thrift/spec/ThriftSpec.thrift +84 -0
- data/vendor/gems/thrift/spec/base_protocol_spec.rb +160 -0
- data/vendor/gems/thrift/spec/base_transport_spec.rb +351 -0
- data/vendor/gems/thrift/{contrib/fb303/py/Makefile.am → spec/binary_protocol_accelerated_spec.rb} +22 -25
- data/vendor/gems/thrift/spec/binary_protocol_spec.rb +63 -0
- data/vendor/gems/thrift/spec/binary_protocol_spec_shared.rb +375 -0
- data/vendor/gems/thrift/spec/client_spec.rb +100 -0
- data/vendor/gems/thrift/spec/compact_protocol_spec.rb +117 -0
- data/vendor/gems/thrift/spec/exception_spec.rb +142 -0
- data/vendor/gems/thrift/spec/http_client_spec.rb +49 -0
- data/vendor/gems/thrift/spec/mongrel_http_server_spec.rb +117 -0
- data/vendor/gems/thrift/spec/nonblocking_server_spec.rb +265 -0
- data/vendor/gems/thrift/spec/processor_spec.rb +83 -0
- data/vendor/gems/thrift/spec/serializer_spec.rb +69 -0
- data/vendor/gems/thrift/spec/server_socket_spec.rb +80 -0
- data/vendor/gems/thrift/spec/server_spec.rb +160 -0
- data/vendor/gems/thrift/spec/socket_spec.rb +61 -0
- data/vendor/gems/thrift/spec/socket_spec_shared.rb +104 -0
- data/vendor/gems/thrift/spec/spec_helper.rb +60 -0
- data/vendor/gems/thrift/spec/struct_spec.rb +252 -0
- data/vendor/gems/thrift/spec/types_spec.rb +116 -0
- data/vendor/gems/thrift/spec/unix_socket_spec.rb +108 -0
- data/vendor/gems/trollop/FAQ.txt +84 -0
- data/vendor/gems/trollop/History.txt +101 -0
- data/vendor/gems/trollop/Manifest.txt +7 -0
- data/vendor/gems/trollop/README.txt +40 -0
- data/vendor/gems/trollop/Rakefile +36 -0
- data/vendor/gems/trollop/lib/trollop.rb +739 -0
- data/vendor/gems/trollop/release-script.txt +13 -0
- data/vendor/gems/trollop/test/test_trollop.rb +1048 -0
- data/vendor/gems/trollop/www/index.html +172 -0
- metadata +123 -347
- data/vendor/gems/thrift/CHANGES +0 -35
- data/vendor/gems/thrift/CONTRIBUTORS +0 -77
- data/vendor/gems/thrift/DISCLAIMER +0 -6
- data/vendor/gems/thrift/LICENSE +0 -202
- data/vendor/gems/thrift/NEWS +0 -79
- data/vendor/gems/thrift/NOTICE +0 -26
- data/vendor/gems/thrift/aclocal/ax_boost_base.m4 +0 -198
- data/vendor/gems/thrift/aclocal/ax_javac_and_java.m4 +0 -107
- data/vendor/gems/thrift/aclocal/ax_lib_event.m4 +0 -194
- data/vendor/gems/thrift/aclocal/ax_lib_zlib.m4 +0 -173
- data/vendor/gems/thrift/aclocal/ax_signed_right_shift.m4 +0 -127
- data/vendor/gems/thrift/aclocal/ax_thrift_internal.m4 +0 -39
- data/vendor/gems/thrift/compiler/cpp/Makefile.am +0 -136
- data/vendor/gems/thrift/compiler/cpp/README +0 -39
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_cocoa_generator.cc +0 -2331
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_cpp_generator.cc +0 -3003
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_csharp_generator.cc +0 -1700
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_erl_generator.cc +0 -932
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.cc +0 -173
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_generator.h +0 -321
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_hs_generator.cc +0 -1445
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_html_generator.cc +0 -637
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_java_generator.cc +0 -3069
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_ocaml_generator.cc +0 -1673
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_oop_generator.h +0 -77
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_perl_generator.cc +0 -1812
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_php_generator.cc +0 -2281
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_py_generator.cc +0 -2310
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_rb_generator.cc +0 -1114
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_st_generator.cc +0 -1071
- data/vendor/gems/thrift/compiler/cpp/src/generate/t_xsd_generator.cc +0 -354
- data/vendor/gems/thrift/compiler/cpp/src/globals.h +0 -117
- data/vendor/gems/thrift/compiler/cpp/src/main.cc +0 -1207
- data/vendor/gems/thrift/compiler/cpp/src/main.h +0 -103
- data/vendor/gems/thrift/compiler/cpp/src/md5.c +0 -381
- data/vendor/gems/thrift/compiler/cpp/src/md5.h +0 -91
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_base_type.h +0 -137
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_const.h +0 -59
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_const_value.h +0 -121
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_container.h +0 -56
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_doc.h +0 -51
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum.h +0 -59
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_enum_value.h +0 -64
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_field.h +0 -150
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_function.h +0 -93
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_list.h +0 -56
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_map.h +0 -64
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_program.h +0 -223
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_scope.h +0 -86
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_service.h +0 -68
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_set.h +0 -55
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_struct.h +0 -127
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_type.h +0 -176
- data/vendor/gems/thrift/compiler/cpp/src/parse/t_typedef.h +0 -70
- data/vendor/gems/thrift/compiler/cpp/src/thriftl.ll +0 -303
- data/vendor/gems/thrift/compiler/cpp/src/thrifty.yy +0 -1140
- data/vendor/gems/thrift/configure.ac +0 -255
- data/vendor/gems/thrift/contrib/fb303/LICENSE +0 -16
- data/vendor/gems/thrift/contrib/fb303/README +0 -37
- data/vendor/gems/thrift/contrib/fb303/acinclude.m4 +0 -258
- data/vendor/gems/thrift/contrib/fb303/aclocal/ax_boost_base.m4 +0 -198
- data/vendor/gems/thrift/contrib/fb303/configure.ac +0 -115
- data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.cpp +0 -124
- data/vendor/gems/thrift/contrib/fb303/cpp/FacebookBase.h +0 -103
- data/vendor/gems/thrift/contrib/fb303/cpp/Makefile.am +0 -84
- data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.cpp +0 -481
- data/vendor/gems/thrift/contrib/fb303/cpp/ServiceTracker.h +0 -215
- data/vendor/gems/thrift/contrib/fb303/if/fb303.thrift +0 -112
- data/vendor/gems/thrift/contrib/fb303/java/FacebookBase.java +0 -103
- data/vendor/gems/thrift/contrib/fb303/java/build.xml +0 -84
- data/vendor/gems/thrift/contrib/fb303/php/FacebookBase.php +0 -89
- data/vendor/gems/thrift/contrib/fb303/py/fb303/FacebookBase.py +0 -82
- data/vendor/gems/thrift/contrib/fb303/py/fb303_scripts/fb303_simple_mgmt.py +0 -195
- data/vendor/gems/thrift/contrib/thrift.el +0 -126
- data/vendor/gems/thrift/contrib/thrift.spec +0 -206
- data/vendor/gems/thrift/contrib/thrift.vim +0 -91
- data/vendor/gems/thrift/contrib/thrift_dump.cpp +0 -91
- data/vendor/gems/thrift/doc/lgpl-2.1.txt +0 -504
- data/vendor/gems/thrift/doc/otp-base-license.txt +0 -20
- data/vendor/gems/thrift/doc/thrift.bnf +0 -96
- data/vendor/gems/thrift/doc/thrift.tex +0 -1057
- data/vendor/gems/thrift/lib/cocoa/README +0 -21
- data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.h +0 -44
- data/vendor/gems/thrift/lib/cocoa/src/TApplicationException.m +0 -130
- data/vendor/gems/thrift/lib/cocoa/src/TException.h +0 -34
- data/vendor/gems/thrift/lib/cocoa/src/TException.m +0 -64
- data/vendor/gems/thrift/lib/cocoa/src/TProcessor.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/TProcessorFactory.h +0 -27
- data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.h +0 -27
- data/vendor/gems/thrift/lib/cocoa/src/TSharedProcessorFactory.m +0 -51
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.h +0 -51
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TBinaryProtocol.m +0 -477
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocol.h +0 -148
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolFactory.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.h +0 -29
- data/vendor/gems/thrift/lib/cocoa/src/protocol/TProtocolUtil.m +0 -104
- data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.h +0 -50
- data/vendor/gems/thrift/lib/cocoa/src/server/TSocketServer.m +0 -153
- data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.h +0 -42
- data/vendor/gems/thrift/lib/cocoa/src/transport/THTTPClient.m +0 -159
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.h +0 -35
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSFileHandleTransport.m +0 -91
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.h +0 -38
- data/vendor/gems/thrift/lib/cocoa/src/transport/TNSStreamTransport.m +0 -89
- data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.h +0 -32
- data/vendor/gems/thrift/lib/cocoa/src/transport/TSocketClient.m +0 -58
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransport.h +0 -36
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.h +0 -30
- data/vendor/gems/thrift/lib/cocoa/src/transport/TTransportException.m +0 -43
- data/vendor/gems/thrift/lib/cpp/Makefile.am +0 -158
- data/vendor/gems/thrift/lib/cpp/README +0 -67
- data/vendor/gems/thrift/lib/cpp/src/TLogging.h +0 -163
- data/vendor/gems/thrift/lib/cpp/src/TProcessor.h +0 -53
- data/vendor/gems/thrift/lib/cpp/src/TReflectionLocal.h +0 -96
- data/vendor/gems/thrift/lib/cpp/src/Thrift.cpp +0 -148
- data/vendor/gems/thrift/lib/cpp/src/Thrift.h +0 -191
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Exception.h +0 -60
- data/vendor/gems/thrift/lib/cpp/src/concurrency/FunctionRunner.h +0 -77
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.cpp +0 -137
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Monitor.h +0 -84
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.cpp +0 -160
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Mutex.h +0 -114
- data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.cpp +0 -314
- data/vendor/gems/thrift/lib/cpp/src/concurrency/PosixThreadFactory.h +0 -130
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Thread.h +0 -125
- data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.cpp +0 -493
- data/vendor/gems/thrift/lib/cpp/src/concurrency/ThreadManager.h +0 -169
- data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.cpp +0 -284
- data/vendor/gems/thrift/lib/cpp/src/concurrency/TimerManager.h +0 -122
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.cpp +0 -55
- data/vendor/gems/thrift/lib/cpp/src/concurrency/Util.h +0 -100
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/Tests.cpp +0 -155
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadFactoryTests.h +0 -354
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/ThreadManagerTests.h +0 -379
- data/vendor/gems/thrift/lib/cpp/src/concurrency/test/TimerManagerTests.h +0 -155
- data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.cpp +0 -122
- data/vendor/gems/thrift/lib/cpp/src/processor/PeekProcessor.h +0 -77
- data/vendor/gems/thrift/lib/cpp/src/processor/StatsProcessor.h +0 -264
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.cpp +0 -79
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBase64Utils.h +0 -42
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.cpp +0 -394
- data/vendor/gems/thrift/lib/cpp/src/protocol/TBinaryProtocol.h +0 -254
- data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.cpp +0 -736
- data/vendor/gems/thrift/lib/cpp/src/protocol/TCompactProtocol.h +0 -279
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.cpp +0 -346
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDebugProtocol.h +0 -225
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.cpp +0 -762
- data/vendor/gems/thrift/lib/cpp/src/protocol/TDenseProtocol.h +0 -253
- data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.cpp +0 -998
- data/vendor/gems/thrift/lib/cpp/src/protocol/TJSONProtocol.h +0 -340
- data/vendor/gems/thrift/lib/cpp/src/protocol/TOneWayProtocol.h +0 -304
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocol.h +0 -438
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolException.h +0 -104
- data/vendor/gems/thrift/lib/cpp/src/protocol/TProtocolTap.h +0 -187
- data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.cpp +0 -750
- data/vendor/gems/thrift/lib/cpp/src/server/TNonblockingServer.h +0 -435
- data/vendor/gems/thrift/lib/cpp/src/server/TServer.cpp +0 -38
- data/vendor/gems/thrift/lib/cpp/src/server/TServer.h +0 -213
- data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.cpp +0 -118
- data/vendor/gems/thrift/lib/cpp/src/server/TSimpleServer.h +0 -70
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.cpp +0 -217
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadPoolServer.h +0 -79
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.cpp +0 -243
- data/vendor/gems/thrift/lib/cpp/src/server/TThreadedServer.h +0 -74
- data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.cpp +0 -370
- data/vendor/gems/thrift/lib/cpp/src/transport/TBufferTransports.h +0 -667
- data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.cpp +0 -77
- data/vendor/gems/thrift/lib/cpp/src/transport/TFDTransport.h +0 -73
- data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.cpp +0 -953
- data/vendor/gems/thrift/lib/cpp/src/transport/TFileTransport.h +0 -442
- data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.cpp +0 -348
- data/vendor/gems/thrift/lib/cpp/src/transport/THttpClient.h +0 -111
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.cpp +0 -368
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerSocket.h +0 -76
- data/vendor/gems/thrift/lib/cpp/src/transport/TServerTransport.h +0 -92
- data/vendor/gems/thrift/lib/cpp/src/transport/TShortReadTransport.h +0 -96
- data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.cpp +0 -54
- data/vendor/gems/thrift/lib/cpp/src/transport/TSimpleFileTransport.h +0 -41
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.cpp +0 -591
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocket.h +0 -242
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.cpp +0 -235
- data/vendor/gems/thrift/lib/cpp/src/transport/TSocketPool.h +0 -191
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransport.h +0 -224
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.cpp +0 -31
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportException.h +0 -117
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.cpp +0 -178
- data/vendor/gems/thrift/lib/cpp/src/transport/TTransportUtils.h +0 -287
- data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.cpp +0 -299
- data/vendor/gems/thrift/lib/cpp/src/transport/TZlibTransport.h +0 -219
- data/vendor/gems/thrift/lib/cpp/thrift-nb.pc.in +0 -30
- data/vendor/gems/thrift/lib/cpp/thrift-z.pc.in +0 -30
- data/vendor/gems/thrift/lib/cpp/thrift.pc.in +0 -29
- data/vendor/gems/thrift/lib/csharp/Makefile.am +0 -70
- data/vendor/gems/thrift/lib/csharp/README +0 -26
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/Properties/AssemblyInfo.cs +0 -55
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftBuild.cs +0 -242
- data/vendor/gems/thrift/lib/csharp/ThriftMSBuildTask/ThriftMSBuildTask.csproj +0 -62
- data/vendor/gems/thrift/lib/csharp/src/Collections/THashSet.cs +0 -142
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TBase.cs +0 -34
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TBinaryProtocol.cs +0 -392
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TField.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TList.cs +0 -50
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TMap.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TMessage.cs +0 -58
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocol.cs +0 -87
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolException.cs +0 -61
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolFactory.cs +0 -29
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TProtocolUtil.cs +0 -94
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TSet.cs +0 -50
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TStruct.cs +0 -42
- data/vendor/gems/thrift/lib/csharp/src/Protocol/TType.cs +0 -40
- data/vendor/gems/thrift/lib/csharp/src/Server/TServer.cs +0 -135
- data/vendor/gems/thrift/lib/csharp/src/Server/TSimpleServer.cs +0 -148
- data/vendor/gems/thrift/lib/csharp/src/Server/TThreadPoolServer.cs +0 -186
- data/vendor/gems/thrift/lib/csharp/src/Server/TThreadedServer.cs +0 -234
- data/vendor/gems/thrift/lib/csharp/src/TApplicationException.cs +0 -131
- data/vendor/gems/thrift/lib/csharp/src/Thrift.csproj +0 -73
- data/vendor/gems/thrift/lib/csharp/src/Thrift.sln +0 -35
- data/vendor/gems/thrift/lib/csharp/src/Transport/TBufferedTransport.cs +0 -100
- data/vendor/gems/thrift/lib/csharp/src/Transport/TServerSocket.cs +0 -157
- data/vendor/gems/thrift/lib/csharp/src/Transport/TServerTransport.cs +0 -39
- data/vendor/gems/thrift/lib/csharp/src/Transport/TSocket.cs +0 -144
- data/vendor/gems/thrift/lib/csharp/src/Transport/TStreamTransport.cs +0 -103
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransport.cs +0 -66
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportException.cs +0 -64
- data/vendor/gems/thrift/lib/csharp/src/Transport/TTransportFactory.cs +0 -38
- data/vendor/gems/thrift/lib/erl/README +0 -56
- data/vendor/gems/thrift/lib/erl/build/beamver +0 -59
- data/vendor/gems/thrift/lib/erl/build/buildtargets.mk +0 -15
- data/vendor/gems/thrift/lib/erl/build/colors.mk +0 -24
- data/vendor/gems/thrift/lib/erl/build/docs.mk +0 -12
- data/vendor/gems/thrift/lib/erl/build/mime.types +0 -98
- data/vendor/gems/thrift/lib/erl/build/otp.mk +0 -146
- data/vendor/gems/thrift/lib/erl/build/otp_subdir.mk +0 -85
- data/vendor/gems/thrift/lib/erl/build/raw_test.mk +0 -29
- data/vendor/gems/thrift/lib/erl/include/thrift_constants.hrl +0 -54
- data/vendor/gems/thrift/lib/erl/include/thrift_protocol.hrl +0 -31
- data/vendor/gems/thrift/lib/erl/src/Makefile +0 -116
- data/vendor/gems/thrift/lib/erl/src/test_handler.erl +0 -26
- data/vendor/gems/thrift/lib/erl/src/test_service.erl +0 -29
- data/vendor/gems/thrift/lib/erl/src/thrift.app.src +0 -44
- data/vendor/gems/thrift/lib/erl/src/thrift.appup.src +0 -1
- data/vendor/gems/thrift/lib/erl/src/thrift_base64_transport.erl +0 -64
- data/vendor/gems/thrift/lib/erl/src/thrift_binary_protocol.erl +0 -325
- data/vendor/gems/thrift/lib/erl/src/thrift_buffered_transport.erl +0 -180
- data/vendor/gems/thrift/lib/erl/src/thrift_client.erl +0 -384
- data/vendor/gems/thrift/lib/erl/src/thrift_disk_log_transport.erl +0 -118
- data/vendor/gems/thrift/lib/erl/src/thrift_file_transport.erl +0 -87
- data/vendor/gems/thrift/lib/erl/src/thrift_framed_transport.erl +0 -208
- data/vendor/gems/thrift/lib/erl/src/thrift_http_transport.erl +0 -199
- data/vendor/gems/thrift/lib/erl/src/thrift_memory_buffer.erl +0 -164
- data/vendor/gems/thrift/lib/erl/src/thrift_processor.erl +0 -188
- data/vendor/gems/thrift/lib/erl/src/thrift_protocol.erl +0 -356
- data/vendor/gems/thrift/lib/erl/src/thrift_server.erl +0 -183
- data/vendor/gems/thrift/lib/erl/src/thrift_service.erl +0 -25
- data/vendor/gems/thrift/lib/erl/src/thrift_socket_server.erl +0 -249
- data/vendor/gems/thrift/lib/erl/src/thrift_socket_transport.erl +0 -119
- data/vendor/gems/thrift/lib/erl/src/thrift_transport.erl +0 -57
- data/vendor/gems/thrift/lib/erl/vsn.mk +0 -1
- data/vendor/gems/thrift/lib/hs/README +0 -82
- data/vendor/gems/thrift/lib/hs/TODO +0 -2
- data/vendor/gems/thrift/lib/hs/Thrift.cabal +0 -20
- data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol/Binary.hs +0 -147
- data/vendor/gems/thrift/lib/hs/src/Thrift/Protocol.hs +0 -191
- data/vendor/gems/thrift/lib/hs/src/Thrift/Server.hs +0 -65
- data/vendor/gems/thrift/lib/hs/src/Thrift/Transport/Handle.hs +0 -58
- data/vendor/gems/thrift/lib/hs/src/Thrift/Transport.hs +0 -60
- data/vendor/gems/thrift/lib/hs/src/Thrift.hs +0 -111
- data/vendor/gems/thrift/lib/java/README +0 -43
- data/vendor/gems/thrift/lib/java/build.xml +0 -195
- data/vendor/gems/thrift/lib/java/ivy.xml +0 -8
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/IntRangeSet.java +0 -171
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TApplicationException.java +0 -123
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBase.java +0 -66
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TBaseHelper.java +0 -102
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TByteArrayOutputStream.java +0 -46
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TDeserializer.java +0 -94
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TException.java +0 -45
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TFieldRequirementType.java +0 -30
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessor.java +0 -32
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TProcessorFactory.java +0 -39
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/TSerializer.java +0 -110
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldMetaData.java +0 -69
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/FieldValueMetaData.java +0 -42
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/ListMetaData.java +0 -29
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/MapMetaData.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/SetMetaData.java +0 -29
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/meta_data/StructMetaData.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBase64Utils.java +0 -128
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TBinaryProtocol.java +0 -331
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TCompactProtocol.java +0 -741
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TField.java +0 -48
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TJSONProtocol.java +0 -927
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TList.java +0 -38
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMap.java +0 -40
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessage.java +0 -48
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TMessageType.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocol.java +0 -146
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolException.java +0 -81
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolFactory.java +0 -30
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TProtocolUtil.java +0 -158
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSet.java +0 -42
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TSimpleJSONProtocol.java +0 -384
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TStruct.java +0 -36
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/protocol/TType.java +0 -40
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/THsHaServer.java +0 -304
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TNonblockingServer.java +0 -772
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TServer.java +0 -126
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TSimpleServer.java +0 -145
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/server/TThreadPoolServer.java +0 -271
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TFramedTransport.java +0 -126
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/THttpClient.java +0 -157
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TIOStreamTransport.java +0 -159
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TMemoryBuffer.java +0 -98
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerSocket.java +0 -160
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingServerTransport.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingSocket.java +0 -213
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TNonblockingTransport.java +0 -31
- data/vendor/gems/thrift/lib/java/src/org/apache/thrift/transport/TServerSocket.java +0 -145
|
@@ -1,2281 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
* or more contributor license agreements. See the NOTICE file
|
|
4
|
-
* distributed with this work for additional information
|
|
5
|
-
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
* to you under the Apache License, Version 2.0 (the
|
|
7
|
-
* "License"); you may not use this file except in compliance
|
|
8
|
-
* with the License. You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing,
|
|
13
|
-
* software distributed under the License is distributed on an
|
|
14
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
* KIND, either express or implied. See the License for the
|
|
16
|
-
* specific language governing permissions and limitations
|
|
17
|
-
* under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
#include <string>
|
|
21
|
-
#include <fstream>
|
|
22
|
-
#include <iostream>
|
|
23
|
-
#include <vector>
|
|
24
|
-
|
|
25
|
-
#include <stdlib.h>
|
|
26
|
-
#include <sys/stat.h>
|
|
27
|
-
#include <sstream>
|
|
28
|
-
#include "t_oop_generator.h"
|
|
29
|
-
#include "platform.h"
|
|
30
|
-
using namespace std;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* PHP code generator.
|
|
35
|
-
*
|
|
36
|
-
*/
|
|
37
|
-
class t_php_generator : public t_oop_generator {
|
|
38
|
-
public:
|
|
39
|
-
t_php_generator(
|
|
40
|
-
t_program* program,
|
|
41
|
-
const std::map<std::string, std::string>& parsed_options,
|
|
42
|
-
const std::string& option_string)
|
|
43
|
-
: t_oop_generator(program)
|
|
44
|
-
{
|
|
45
|
-
std::map<std::string, std::string>::const_iterator iter;
|
|
46
|
-
|
|
47
|
-
iter = parsed_options.find("inlined");
|
|
48
|
-
binary_inline_ = (iter != parsed_options.end());
|
|
49
|
-
|
|
50
|
-
iter = parsed_options.find("rest");
|
|
51
|
-
rest_ = (iter != parsed_options.end());
|
|
52
|
-
|
|
53
|
-
iter = parsed_options.find("server");
|
|
54
|
-
phps_ = (iter != parsed_options.end());
|
|
55
|
-
|
|
56
|
-
iter = parsed_options.find("autoload");
|
|
57
|
-
autoload_ = (iter != parsed_options.end());
|
|
58
|
-
|
|
59
|
-
iter = parsed_options.find("oop");
|
|
60
|
-
oop_ = (iter != parsed_options.end());
|
|
61
|
-
|
|
62
|
-
if (oop_ && binary_inline_) {
|
|
63
|
-
throw "oop and inlined are mutually exclusive.";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
out_dir_base_ = (binary_inline_ ? "gen-phpi" : "gen-php");
|
|
67
|
-
escape_['$'] = "\\$";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Init and close methods
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
void init_generator();
|
|
75
|
-
void close_generator();
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Program-level generation functions
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
void generate_typedef (t_typedef* ttypedef);
|
|
82
|
-
void generate_enum (t_enum* tenum);
|
|
83
|
-
void generate_const (t_const* tconst);
|
|
84
|
-
void generate_struct (t_struct* tstruct);
|
|
85
|
-
void generate_xception (t_struct* txception);
|
|
86
|
-
void generate_service (t_service* tservice);
|
|
87
|
-
|
|
88
|
-
std::string render_const_value(t_type* type, t_const_value* value);
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Structs!
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
void generate_php_struct(t_struct* tstruct, bool is_exception);
|
|
95
|
-
void generate_php_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false);
|
|
96
|
-
void _generate_php_struct_definition(std::ofstream& out, t_struct* tstruct, bool is_xception=false);
|
|
97
|
-
void generate_php_struct_reader(std::ofstream& out, t_struct* tstruct);
|
|
98
|
-
void generate_php_struct_writer(std::ofstream& out, t_struct* tstruct);
|
|
99
|
-
void generate_php_function_helpers(t_function* tfunction);
|
|
100
|
-
|
|
101
|
-
void generate_php_type_spec(std::ofstream &out, t_type* t);
|
|
102
|
-
void generate_php_struct_spec(std::ofstream &out, t_struct* tstruct);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Service-level generation functions
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
void generate_service_helpers (t_service* tservice);
|
|
109
|
-
void generate_service_interface (t_service* tservice);
|
|
110
|
-
void generate_service_rest (t_service* tservice);
|
|
111
|
-
void generate_service_client (t_service* tservice);
|
|
112
|
-
void _generate_service_client (std::ofstream &out, t_service* tservice);
|
|
113
|
-
void generate_service_processor (t_service* tservice);
|
|
114
|
-
void generate_process_function (t_service* tservice, t_function* tfunction);
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Serialization constructs
|
|
118
|
-
*/
|
|
119
|
-
|
|
120
|
-
void generate_deserialize_field (std::ofstream &out,
|
|
121
|
-
t_field* tfield,
|
|
122
|
-
std::string prefix="",
|
|
123
|
-
bool inclass=false);
|
|
124
|
-
|
|
125
|
-
void generate_deserialize_struct (std::ofstream &out,
|
|
126
|
-
t_struct* tstruct,
|
|
127
|
-
std::string prefix="");
|
|
128
|
-
|
|
129
|
-
void generate_deserialize_container (std::ofstream &out,
|
|
130
|
-
t_type* ttype,
|
|
131
|
-
std::string prefix="");
|
|
132
|
-
|
|
133
|
-
void generate_deserialize_set_element (std::ofstream &out,
|
|
134
|
-
t_set* tset,
|
|
135
|
-
std::string prefix="");
|
|
136
|
-
|
|
137
|
-
void generate_deserialize_map_element (std::ofstream &out,
|
|
138
|
-
t_map* tmap,
|
|
139
|
-
std::string prefix="");
|
|
140
|
-
|
|
141
|
-
void generate_deserialize_list_element (std::ofstream &out,
|
|
142
|
-
t_list* tlist,
|
|
143
|
-
std::string prefix="");
|
|
144
|
-
|
|
145
|
-
void generate_serialize_field (std::ofstream &out,
|
|
146
|
-
t_field* tfield,
|
|
147
|
-
std::string prefix="");
|
|
148
|
-
|
|
149
|
-
void generate_serialize_struct (std::ofstream &out,
|
|
150
|
-
t_struct* tstruct,
|
|
151
|
-
std::string prefix="");
|
|
152
|
-
|
|
153
|
-
void generate_serialize_container (std::ofstream &out,
|
|
154
|
-
t_type* ttype,
|
|
155
|
-
std::string prefix="");
|
|
156
|
-
|
|
157
|
-
void generate_serialize_map_element (std::ofstream &out,
|
|
158
|
-
t_map* tmap,
|
|
159
|
-
std::string kiter,
|
|
160
|
-
std::string viter);
|
|
161
|
-
|
|
162
|
-
void generate_serialize_set_element (std::ofstream &out,
|
|
163
|
-
t_set* tmap,
|
|
164
|
-
std::string iter);
|
|
165
|
-
|
|
166
|
-
void generate_serialize_list_element (std::ofstream &out,
|
|
167
|
-
t_list* tlist,
|
|
168
|
-
std::string iter);
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Helper rendering functions
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
std::string php_includes();
|
|
175
|
-
std::string declare_field(t_field* tfield, bool init=false, bool obj=false);
|
|
176
|
-
std::string function_signature(t_function* tfunction, std::string prefix="");
|
|
177
|
-
std::string argument_list(t_struct* tstruct);
|
|
178
|
-
std::string type_to_cast(t_type* ttype);
|
|
179
|
-
std::string type_to_enum(t_type* ttype);
|
|
180
|
-
|
|
181
|
-
std::string php_namespace(t_program* p) {
|
|
182
|
-
std::string ns = p->get_namespace("php");
|
|
183
|
-
return ns.size() ? (ns + "_") : "";
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
private:
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* File streams
|
|
190
|
-
*/
|
|
191
|
-
std::ofstream f_types_;
|
|
192
|
-
std::ofstream f_consts_;
|
|
193
|
-
std::ofstream f_helpers_;
|
|
194
|
-
std::ofstream f_service_;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Generate protocol-independent template? Or Binary inline code?
|
|
198
|
-
*/
|
|
199
|
-
bool binary_inline_;
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Generate a REST handler class
|
|
203
|
-
*/
|
|
204
|
-
bool rest_;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Generate stubs for a PHP server
|
|
208
|
-
*/
|
|
209
|
-
bool phps_;
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Generate PHP code that uses autoload
|
|
213
|
-
*/
|
|
214
|
-
bool autoload_;
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Whether to use OOP base class TBase
|
|
218
|
-
*/
|
|
219
|
-
bool oop_;
|
|
220
|
-
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Prepares for file generation by opening up the necessary file output
|
|
226
|
-
* streams.
|
|
227
|
-
*
|
|
228
|
-
* @param tprogram The program to generate
|
|
229
|
-
*/
|
|
230
|
-
void t_php_generator::init_generator() {
|
|
231
|
-
// Make output directory
|
|
232
|
-
MKDIR(get_out_dir().c_str());
|
|
233
|
-
|
|
234
|
-
// Make output file
|
|
235
|
-
string f_types_name = get_out_dir()+program_name_+"_types.php";
|
|
236
|
-
f_types_.open(f_types_name.c_str());
|
|
237
|
-
|
|
238
|
-
// Print header
|
|
239
|
-
f_types_ <<
|
|
240
|
-
"<?php" << endl <<
|
|
241
|
-
autogen_comment() <<
|
|
242
|
-
php_includes();
|
|
243
|
-
|
|
244
|
-
// Include other Thrift includes
|
|
245
|
-
const vector<t_program*>& includes = program_->get_includes();
|
|
246
|
-
for (size_t i = 0; i < includes.size(); ++i) {
|
|
247
|
-
string package = includes[i]->get_name();
|
|
248
|
-
f_types_ <<
|
|
249
|
-
"include_once $GLOBALS['THRIFT_ROOT'].'/packages/" << package << "/" << package << "_types.php';" << endl;
|
|
250
|
-
}
|
|
251
|
-
f_types_ << endl;
|
|
252
|
-
|
|
253
|
-
// Print header
|
|
254
|
-
if (!program_->get_consts().empty()) {
|
|
255
|
-
string f_consts_name = get_out_dir()+program_name_+"_constants.php";
|
|
256
|
-
f_consts_.open(f_consts_name.c_str());
|
|
257
|
-
f_consts_ <<
|
|
258
|
-
"<?php" << endl <<
|
|
259
|
-
autogen_comment() <<
|
|
260
|
-
"include_once $GLOBALS['THRIFT_ROOT'].'/packages/" + program_name_ + "/" + program_name_ + "_types.php';" << endl <<
|
|
261
|
-
endl <<
|
|
262
|
-
"$GLOBALS['" << program_name_ << "_CONSTANTS'] = array();" << endl <<
|
|
263
|
-
endl;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Prints standard php includes
|
|
269
|
-
*/
|
|
270
|
-
string t_php_generator::php_includes() {
|
|
271
|
-
return
|
|
272
|
-
string("include_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';\n\n");
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Close up (or down) some filez.
|
|
277
|
-
*/
|
|
278
|
-
void t_php_generator::close_generator() {
|
|
279
|
-
// Close types file
|
|
280
|
-
f_types_ << "?>" << endl;
|
|
281
|
-
f_types_.close();
|
|
282
|
-
|
|
283
|
-
if (!program_->get_consts().empty()) {
|
|
284
|
-
f_consts_ << "?>" << endl;
|
|
285
|
-
f_consts_.close();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Generates a typedef. This is not done in PHP, types are all implicit.
|
|
291
|
-
*
|
|
292
|
-
* @param ttypedef The type definition
|
|
293
|
-
*/
|
|
294
|
-
void t_php_generator::generate_typedef(t_typedef* ttypedef) {}
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Generates code for an enumerated type. Since define is expensive to lookup
|
|
298
|
-
* in PHP, we use a global array for this.
|
|
299
|
-
*
|
|
300
|
-
* @param tenum The enumeration
|
|
301
|
-
*/
|
|
302
|
-
void t_php_generator::generate_enum(t_enum* tenum) {
|
|
303
|
-
f_types_ <<
|
|
304
|
-
"$GLOBALS['" << php_namespace(tenum->get_program()) << "E_" << tenum->get_name() << "'] = array(" << endl;
|
|
305
|
-
|
|
306
|
-
vector<t_enum_value*> constants = tenum->get_constants();
|
|
307
|
-
vector<t_enum_value*>::iterator c_iter;
|
|
308
|
-
int value = -1;
|
|
309
|
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
|
|
310
|
-
if ((*c_iter)->has_value()) {
|
|
311
|
-
value = (*c_iter)->get_value();
|
|
312
|
-
} else {
|
|
313
|
-
++value;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
f_types_ <<
|
|
317
|
-
" '" << (*c_iter)->get_name() << "' => " << value << "," << endl;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
f_types_ <<
|
|
321
|
-
");" << endl << endl;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
// We're also doing it this way to see how it performs. It's more legible
|
|
325
|
-
// code but you can't do things like an 'extract' on it, which is a bit of
|
|
326
|
-
// a downer.
|
|
327
|
-
f_types_ <<
|
|
328
|
-
"final class " << php_namespace(tenum->get_program()) << tenum->get_name() << " {" << endl;
|
|
329
|
-
indent_up();
|
|
330
|
-
|
|
331
|
-
value = -1;
|
|
332
|
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
|
|
333
|
-
if ((*c_iter)->has_value()) {
|
|
334
|
-
value = (*c_iter)->get_value();
|
|
335
|
-
} else {
|
|
336
|
-
++value;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
indent(f_types_) <<
|
|
340
|
-
"const " << (*c_iter)->get_name() << " = " << value << ";" << endl;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
indent(f_types_) <<
|
|
344
|
-
"static public $__names = array(" << endl;
|
|
345
|
-
value = -1;
|
|
346
|
-
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
|
|
347
|
-
if ((*c_iter)->has_value()) {
|
|
348
|
-
value = (*c_iter)->get_value();
|
|
349
|
-
} else {
|
|
350
|
-
++value;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
indent(f_types_) <<
|
|
354
|
-
" " << value << " => '" << (*c_iter)->get_name() << "'," << endl;
|
|
355
|
-
}
|
|
356
|
-
indent(f_types_) <<
|
|
357
|
-
");" << endl;
|
|
358
|
-
|
|
359
|
-
indent_down();
|
|
360
|
-
f_types_ << "}" << endl << endl;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Generate a constant value
|
|
365
|
-
*/
|
|
366
|
-
void t_php_generator::generate_const(t_const* tconst) {
|
|
367
|
-
t_type* type = tconst->get_type();
|
|
368
|
-
string name = tconst->get_name();
|
|
369
|
-
t_const_value* value = tconst->get_value();
|
|
370
|
-
|
|
371
|
-
f_consts_ << "$GLOBALS['" << program_name_ << "_CONSTANTS']['" << name << "'] = ";
|
|
372
|
-
f_consts_ << render_const_value(type, value);
|
|
373
|
-
f_consts_ << ";" << endl << endl;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Prints the value of a constant with the given type. Note that type checking
|
|
378
|
-
* is NOT performed in this function as it is always run beforehand using the
|
|
379
|
-
* validate_types method in main.cc
|
|
380
|
-
*/
|
|
381
|
-
string t_php_generator::render_const_value(t_type* type, t_const_value* value) {
|
|
382
|
-
std::ostringstream out;
|
|
383
|
-
type = get_true_type(type);
|
|
384
|
-
if (type->is_base_type()) {
|
|
385
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
386
|
-
switch (tbase) {
|
|
387
|
-
case t_base_type::TYPE_STRING:
|
|
388
|
-
out << '"' << get_escaped_string(value) << '"';
|
|
389
|
-
break;
|
|
390
|
-
case t_base_type::TYPE_BOOL:
|
|
391
|
-
out << (value->get_integer() > 0 ? "true" : "false");
|
|
392
|
-
break;
|
|
393
|
-
case t_base_type::TYPE_BYTE:
|
|
394
|
-
case t_base_type::TYPE_I16:
|
|
395
|
-
case t_base_type::TYPE_I32:
|
|
396
|
-
case t_base_type::TYPE_I64:
|
|
397
|
-
out << value->get_integer();
|
|
398
|
-
break;
|
|
399
|
-
case t_base_type::TYPE_DOUBLE:
|
|
400
|
-
if (value->get_type() == t_const_value::CV_INTEGER) {
|
|
401
|
-
out << value->get_integer();
|
|
402
|
-
} else {
|
|
403
|
-
out << value->get_double();
|
|
404
|
-
}
|
|
405
|
-
break;
|
|
406
|
-
default:
|
|
407
|
-
throw "compiler error: no const of base type " + t_base_type::t_base_name(tbase);
|
|
408
|
-
}
|
|
409
|
-
} else if (type->is_enum()) {
|
|
410
|
-
indent(out) << value->get_integer();
|
|
411
|
-
} else if (type->is_struct() || type->is_xception()) {
|
|
412
|
-
out << "new " << php_namespace(type->get_program()) << type->get_name() << "(array(" << endl;
|
|
413
|
-
indent_up();
|
|
414
|
-
const vector<t_field*>& fields = ((t_struct*)type)->get_members();
|
|
415
|
-
vector<t_field*>::const_iterator f_iter;
|
|
416
|
-
const map<t_const_value*, t_const_value*>& val = value->get_map();
|
|
417
|
-
map<t_const_value*, t_const_value*>::const_iterator v_iter;
|
|
418
|
-
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
|
|
419
|
-
t_type* field_type = NULL;
|
|
420
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
421
|
-
if ((*f_iter)->get_name() == v_iter->first->get_string()) {
|
|
422
|
-
field_type = (*f_iter)->get_type();
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (field_type == NULL) {
|
|
426
|
-
throw "type error: " + type->get_name() + " has no field " + v_iter->first->get_string();
|
|
427
|
-
}
|
|
428
|
-
out << indent();
|
|
429
|
-
out << render_const_value(g_type_string, v_iter->first);
|
|
430
|
-
out << " => ";
|
|
431
|
-
out << render_const_value(field_type, v_iter->second);
|
|
432
|
-
out << endl;
|
|
433
|
-
}
|
|
434
|
-
indent_down();
|
|
435
|
-
indent(out) << "))";
|
|
436
|
-
} else if (type->is_map()) {
|
|
437
|
-
t_type* ktype = ((t_map*)type)->get_key_type();
|
|
438
|
-
t_type* vtype = ((t_map*)type)->get_val_type();
|
|
439
|
-
out << "array(" << endl;
|
|
440
|
-
indent_up();
|
|
441
|
-
const map<t_const_value*, t_const_value*>& val = value->get_map();
|
|
442
|
-
map<t_const_value*, t_const_value*>::const_iterator v_iter;
|
|
443
|
-
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
|
|
444
|
-
out << indent();
|
|
445
|
-
out << render_const_value(ktype, v_iter->first);
|
|
446
|
-
out << " => ";
|
|
447
|
-
out << render_const_value(vtype, v_iter->second);
|
|
448
|
-
out << "," << endl;
|
|
449
|
-
}
|
|
450
|
-
indent_down();
|
|
451
|
-
indent(out) << ")";
|
|
452
|
-
} else if (type->is_list() || type->is_set()) {
|
|
453
|
-
t_type* etype;
|
|
454
|
-
if (type->is_list()) {
|
|
455
|
-
etype = ((t_list*)type)->get_elem_type();
|
|
456
|
-
} else {
|
|
457
|
-
etype = ((t_set*)type)->get_elem_type();
|
|
458
|
-
}
|
|
459
|
-
out << "array(" << endl;
|
|
460
|
-
indent_up();
|
|
461
|
-
const vector<t_const_value*>& val = value->get_list();
|
|
462
|
-
vector<t_const_value*>::const_iterator v_iter;
|
|
463
|
-
for (v_iter = val.begin(); v_iter != val.end(); ++v_iter) {
|
|
464
|
-
out << indent();
|
|
465
|
-
out << render_const_value(etype, *v_iter);
|
|
466
|
-
if (type->is_set()) {
|
|
467
|
-
out << " => true";
|
|
468
|
-
}
|
|
469
|
-
out << "," << endl;
|
|
470
|
-
}
|
|
471
|
-
indent_down();
|
|
472
|
-
indent(out) << ")";
|
|
473
|
-
}
|
|
474
|
-
return out.str();
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Make a struct
|
|
479
|
-
*/
|
|
480
|
-
void t_php_generator::generate_struct(t_struct* tstruct) {
|
|
481
|
-
generate_php_struct(tstruct, false);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Generates a struct definition for a thrift exception. Basically the same
|
|
486
|
-
* as a struct but extends the Exception class.
|
|
487
|
-
*
|
|
488
|
-
* @param txception The struct definition
|
|
489
|
-
*/
|
|
490
|
-
void t_php_generator::generate_xception(t_struct* txception) {
|
|
491
|
-
generate_php_struct(txception, true);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* Structs can be normal or exceptions.
|
|
496
|
-
*/
|
|
497
|
-
void t_php_generator::generate_php_struct(t_struct* tstruct,
|
|
498
|
-
bool is_exception) {
|
|
499
|
-
generate_php_struct_definition(f_types_, tstruct, is_exception);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
void t_php_generator::generate_php_type_spec(ofstream& out,
|
|
503
|
-
t_type* t) {
|
|
504
|
-
t = get_true_type(t);
|
|
505
|
-
indent(out) << "'type' => " << type_to_enum(t) << "," << endl;
|
|
506
|
-
|
|
507
|
-
if (t->is_base_type() || t->is_enum()) {
|
|
508
|
-
// Noop, type is all we need
|
|
509
|
-
} else if (t->is_struct() || t->is_xception()) {
|
|
510
|
-
indent(out) << "'class' => '" << php_namespace(t->get_program()) << t->get_name() <<"'," << endl;
|
|
511
|
-
} else if (t->is_map()) {
|
|
512
|
-
t_type* ktype = get_true_type(((t_map*)t)->get_key_type());
|
|
513
|
-
t_type* vtype = get_true_type(((t_map*)t)->get_val_type());
|
|
514
|
-
indent(out) << "'ktype' => " << type_to_enum(ktype) << "," << endl;
|
|
515
|
-
indent(out) << "'vtype' => " << type_to_enum(vtype) << "," << endl;
|
|
516
|
-
indent(out) << "'key' => array(" << endl;
|
|
517
|
-
indent_up();
|
|
518
|
-
generate_php_type_spec(out, ktype);
|
|
519
|
-
indent_down();
|
|
520
|
-
indent(out) << ")," << endl;
|
|
521
|
-
indent(out) << "'val' => array(" << endl;
|
|
522
|
-
indent_up();
|
|
523
|
-
generate_php_type_spec(out, vtype);
|
|
524
|
-
indent(out) << ")," << endl;
|
|
525
|
-
indent_down();
|
|
526
|
-
} else if (t->is_list() || t->is_set()) {
|
|
527
|
-
t_type* etype;
|
|
528
|
-
if (t->is_list()) {
|
|
529
|
-
etype = get_true_type(((t_list*)t)->get_elem_type());
|
|
530
|
-
} else {
|
|
531
|
-
etype = get_true_type(((t_set*)t)->get_elem_type());
|
|
532
|
-
}
|
|
533
|
-
indent(out) << "'etype' => " << type_to_enum(etype) <<"," << endl;
|
|
534
|
-
indent(out) << "'elem' => array(" << endl;
|
|
535
|
-
indent_up();
|
|
536
|
-
generate_php_type_spec(out, etype);
|
|
537
|
-
indent(out) << ")," << endl;
|
|
538
|
-
indent_down();
|
|
539
|
-
} else {
|
|
540
|
-
throw "compiler error: no type for php struct spec field";
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* Generates the struct specification structure, which fully qualifies enough
|
|
547
|
-
* type information to generalize serialization routines.
|
|
548
|
-
*/
|
|
549
|
-
void t_php_generator::generate_php_struct_spec(ofstream& out,
|
|
550
|
-
t_struct* tstruct) {
|
|
551
|
-
indent(out) << "if (!isset(self::$_TSPEC)) {" << endl;
|
|
552
|
-
indent_up();
|
|
553
|
-
|
|
554
|
-
indent(out) << "self::$_TSPEC = array(" << endl;
|
|
555
|
-
indent_up();
|
|
556
|
-
|
|
557
|
-
const vector<t_field*>& members = tstruct->get_members();
|
|
558
|
-
vector<t_field*>::const_iterator m_iter;
|
|
559
|
-
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
|
560
|
-
t_type* t = get_true_type((*m_iter)->get_type());
|
|
561
|
-
indent(out) << (*m_iter)->get_key() << " => array(" << endl;
|
|
562
|
-
indent_up();
|
|
563
|
-
out <<
|
|
564
|
-
indent() << "'var' => '" << (*m_iter)->get_name() << "'," << endl;
|
|
565
|
-
generate_php_type_spec(out, t);
|
|
566
|
-
indent(out) << ")," << endl;
|
|
567
|
-
indent_down();
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
indent_down();
|
|
571
|
-
indent(out) << " );" << endl;
|
|
572
|
-
indent_down();
|
|
573
|
-
indent(out) << "}" << endl;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
void t_php_generator::generate_php_struct_definition(ofstream& out,
|
|
578
|
-
t_struct* tstruct,
|
|
579
|
-
bool is_exception) {
|
|
580
|
-
if (autoload_) {
|
|
581
|
-
// Make output file
|
|
582
|
-
ofstream autoload_out;
|
|
583
|
-
string f_struct = program_name_+"."+(tstruct->get_name())+".php";
|
|
584
|
-
string f_struct_name = get_out_dir()+f_struct;
|
|
585
|
-
autoload_out.open(f_struct_name.c_str());
|
|
586
|
-
autoload_out << "<?php" << endl;
|
|
587
|
-
_generate_php_struct_definition(autoload_out, tstruct, is_exception);
|
|
588
|
-
autoload_out << endl << "?>" << endl;
|
|
589
|
-
autoload_out.close();
|
|
590
|
-
|
|
591
|
-
f_types_ <<
|
|
592
|
-
"$GLOBALS['THRIFT_AUTOLOAD']['" << lowercase(php_namespace(tstruct->get_program()) + tstruct->get_name()) << "'] = '" << program_name_ << "/" << f_struct << "';" << endl;
|
|
593
|
-
|
|
594
|
-
} else {
|
|
595
|
-
_generate_php_struct_definition(out, tstruct, is_exception);
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Generates a struct definition for a thrift data type. This is nothing in PHP
|
|
601
|
-
* where the objects are all just associative arrays (unless of course we
|
|
602
|
-
* decide to start using objects for them...)
|
|
603
|
-
*
|
|
604
|
-
* @param tstruct The struct definition
|
|
605
|
-
*/
|
|
606
|
-
void t_php_generator::_generate_php_struct_definition(ofstream& out,
|
|
607
|
-
t_struct* tstruct,
|
|
608
|
-
bool is_exception) {
|
|
609
|
-
const vector<t_field*>& members = tstruct->get_members();
|
|
610
|
-
vector<t_field*>::const_iterator m_iter;
|
|
611
|
-
|
|
612
|
-
out <<
|
|
613
|
-
"class " << php_namespace(tstruct->get_program()) << tstruct->get_name();
|
|
614
|
-
if (is_exception) {
|
|
615
|
-
out << " extends TException";
|
|
616
|
-
} else if (oop_) {
|
|
617
|
-
out << " extends TBase";
|
|
618
|
-
}
|
|
619
|
-
out <<
|
|
620
|
-
" {" << endl;
|
|
621
|
-
indent_up();
|
|
622
|
-
|
|
623
|
-
indent(out) << "static $_TSPEC;" << endl << endl;
|
|
624
|
-
|
|
625
|
-
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
|
626
|
-
string dval = "null";
|
|
627
|
-
t_type* t = get_true_type((*m_iter)->get_type());
|
|
628
|
-
if ((*m_iter)->get_value() != NULL && !(t->is_struct() || t->is_xception())) {
|
|
629
|
-
dval = render_const_value((*m_iter)->get_type(), (*m_iter)->get_value());
|
|
630
|
-
}
|
|
631
|
-
indent(out) <<
|
|
632
|
-
"public $" << (*m_iter)->get_name() << " = " << dval << ";" << endl;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
out << endl;
|
|
636
|
-
|
|
637
|
-
// Generate constructor from array
|
|
638
|
-
string param = (members.size() > 0) ? "$vals=null" : "";
|
|
639
|
-
out <<
|
|
640
|
-
indent() << "public function __construct(" << param << ") {" << endl;
|
|
641
|
-
indent_up();
|
|
642
|
-
|
|
643
|
-
generate_php_struct_spec(out, tstruct);
|
|
644
|
-
|
|
645
|
-
if (members.size() > 0) {
|
|
646
|
-
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
|
647
|
-
t_type* t = get_true_type((*m_iter)->get_type());
|
|
648
|
-
if ((*m_iter)->get_value() != NULL && (t->is_struct() || t->is_xception())) {
|
|
649
|
-
indent(out) << "$this->" << (*m_iter)->get_name() << " = " << render_const_value(t, (*m_iter)->get_value()) << ";" << endl;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
out <<
|
|
653
|
-
indent() << "if (is_array($vals)) {" << endl;
|
|
654
|
-
indent_up();
|
|
655
|
-
if (oop_) {
|
|
656
|
-
out << indent() << "parent::__construct(self::$_TSPEC, $vals);" << endl;
|
|
657
|
-
} else {
|
|
658
|
-
for (m_iter = members.begin(); m_iter != members.end(); ++m_iter) {
|
|
659
|
-
out <<
|
|
660
|
-
indent() << "if (isset($vals['" << (*m_iter)->get_name() << "'])) {" << endl <<
|
|
661
|
-
indent() << " $this->" << (*m_iter)->get_name() << " = $vals['" << (*m_iter)->get_name() << "'];" << endl <<
|
|
662
|
-
indent() << "}" << endl;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
indent_down();
|
|
666
|
-
out <<
|
|
667
|
-
indent() << "}" << endl;
|
|
668
|
-
}
|
|
669
|
-
scope_down(out);
|
|
670
|
-
out << endl;
|
|
671
|
-
|
|
672
|
-
out <<
|
|
673
|
-
indent() << "public function getName() {" << endl <<
|
|
674
|
-
indent() << " return '" << tstruct->get_name() << "';" << endl <<
|
|
675
|
-
indent() << "}" << endl <<
|
|
676
|
-
endl;
|
|
677
|
-
|
|
678
|
-
generate_php_struct_reader(out, tstruct);
|
|
679
|
-
generate_php_struct_writer(out, tstruct);
|
|
680
|
-
|
|
681
|
-
indent_down();
|
|
682
|
-
out <<
|
|
683
|
-
indent() << "}" << endl <<
|
|
684
|
-
endl;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Generates the read() method for a struct
|
|
689
|
-
*/
|
|
690
|
-
void t_php_generator::generate_php_struct_reader(ofstream& out,
|
|
691
|
-
t_struct* tstruct) {
|
|
692
|
-
const vector<t_field*>& fields = tstruct->get_members();
|
|
693
|
-
vector<t_field*>::const_iterator f_iter;
|
|
694
|
-
|
|
695
|
-
indent(out) <<
|
|
696
|
-
"public function read($input)" << endl;
|
|
697
|
-
scope_up(out);
|
|
698
|
-
|
|
699
|
-
if (oop_) {
|
|
700
|
-
indent(out) << "return $this->_read('" << tstruct->get_name() << "', self::$_TSPEC, $input);" << endl;
|
|
701
|
-
scope_down(out);
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
out <<
|
|
706
|
-
indent() << "$xfer = 0;" << endl <<
|
|
707
|
-
indent() << "$fname = null;" << endl <<
|
|
708
|
-
indent() << "$ftype = 0;" << endl <<
|
|
709
|
-
indent() << "$fid = 0;" << endl;
|
|
710
|
-
|
|
711
|
-
// Declare stack tmp variables
|
|
712
|
-
if (!binary_inline_) {
|
|
713
|
-
indent(out) <<
|
|
714
|
-
"$xfer += $input->readStructBegin($fname);" << endl;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// Loop over reading in fields
|
|
718
|
-
indent(out) <<
|
|
719
|
-
"while (true)" << endl;
|
|
720
|
-
|
|
721
|
-
scope_up(out);
|
|
722
|
-
|
|
723
|
-
// Read beginning field marker
|
|
724
|
-
if (binary_inline_) {
|
|
725
|
-
t_field fftype(g_type_byte, "ftype");
|
|
726
|
-
t_field ffid(g_type_i16, "fid");
|
|
727
|
-
generate_deserialize_field(out, &fftype);
|
|
728
|
-
out <<
|
|
729
|
-
indent() << "if ($ftype == TType::STOP) {" << endl <<
|
|
730
|
-
indent() << " break;" << endl <<
|
|
731
|
-
indent() << "}" << endl;
|
|
732
|
-
generate_deserialize_field(out, &ffid);
|
|
733
|
-
} else {
|
|
734
|
-
indent(out) <<
|
|
735
|
-
"$xfer += $input->readFieldBegin($fname, $ftype, $fid);" << endl;
|
|
736
|
-
// Check for field STOP marker and break
|
|
737
|
-
indent(out) <<
|
|
738
|
-
"if ($ftype == TType::STOP) {" << endl;
|
|
739
|
-
indent_up();
|
|
740
|
-
indent(out) <<
|
|
741
|
-
"break;" << endl;
|
|
742
|
-
indent_down();
|
|
743
|
-
indent(out) <<
|
|
744
|
-
"}" << endl;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
// Switch statement on the field we are reading
|
|
748
|
-
indent(out) <<
|
|
749
|
-
"switch ($fid)" << endl;
|
|
750
|
-
|
|
751
|
-
scope_up(out);
|
|
752
|
-
|
|
753
|
-
// Generate deserialization code for known cases
|
|
754
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
755
|
-
indent(out) <<
|
|
756
|
-
"case " << (*f_iter)->get_key() << ":" << endl;
|
|
757
|
-
indent_up();
|
|
758
|
-
indent(out) << "if ($ftype == " << type_to_enum((*f_iter)->get_type()) << ") {" << endl;
|
|
759
|
-
indent_up();
|
|
760
|
-
generate_deserialize_field(out, *f_iter, "this->");
|
|
761
|
-
indent_down();
|
|
762
|
-
out <<
|
|
763
|
-
indent() << "} else {" << endl;
|
|
764
|
-
if (binary_inline_) {
|
|
765
|
-
indent(out) << " $xfer += TProtocol::skipBinary($input, $ftype);" << endl;
|
|
766
|
-
} else {
|
|
767
|
-
indent(out) << " $xfer += $input->skip($ftype);" << endl;
|
|
768
|
-
}
|
|
769
|
-
out <<
|
|
770
|
-
indent() << "}" << endl <<
|
|
771
|
-
indent() << "break;" << endl;
|
|
772
|
-
indent_down();
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// In the default case we skip the field
|
|
776
|
-
indent(out) << "default:" << endl;
|
|
777
|
-
if (binary_inline_) {
|
|
778
|
-
indent(out) << " $xfer += TProtocol::skipBinary($input, $ftype);" << endl;
|
|
779
|
-
} else {
|
|
780
|
-
indent(out) << " $xfer += $input->skip($ftype);" << endl;
|
|
781
|
-
}
|
|
782
|
-
indent(out) << " break;" << endl;
|
|
783
|
-
|
|
784
|
-
scope_down(out);
|
|
785
|
-
|
|
786
|
-
if (!binary_inline_) {
|
|
787
|
-
// Read field end marker
|
|
788
|
-
indent(out) <<
|
|
789
|
-
"$xfer += $input->readFieldEnd();" << endl;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
scope_down(out);
|
|
793
|
-
|
|
794
|
-
if (!binary_inline_) {
|
|
795
|
-
indent(out) <<
|
|
796
|
-
"$xfer += $input->readStructEnd();" << endl;
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
indent(out) <<
|
|
800
|
-
"return $xfer;" << endl;
|
|
801
|
-
|
|
802
|
-
indent_down();
|
|
803
|
-
out <<
|
|
804
|
-
indent() << "}" << endl <<
|
|
805
|
-
endl;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Generates the write() method for a struct
|
|
810
|
-
*/
|
|
811
|
-
void t_php_generator::generate_php_struct_writer(ofstream& out,
|
|
812
|
-
t_struct* tstruct) {
|
|
813
|
-
string name = tstruct->get_name();
|
|
814
|
-
const vector<t_field*>& fields = tstruct->get_sorted_members();
|
|
815
|
-
vector<t_field*>::const_iterator f_iter;
|
|
816
|
-
|
|
817
|
-
if (binary_inline_) {
|
|
818
|
-
indent(out) <<
|
|
819
|
-
"public function write(&$output) {" << endl;
|
|
820
|
-
} else {
|
|
821
|
-
indent(out) <<
|
|
822
|
-
"public function write($output) {" << endl;
|
|
823
|
-
}
|
|
824
|
-
indent_up();
|
|
825
|
-
|
|
826
|
-
if (oop_) {
|
|
827
|
-
indent(out) << "return $this->_write('" << tstruct->get_name() << "', self::$_TSPEC, $output);" << endl;
|
|
828
|
-
scope_down(out);
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
indent(out) <<
|
|
833
|
-
"$xfer = 0;" << endl;
|
|
834
|
-
|
|
835
|
-
if (!binary_inline_) {
|
|
836
|
-
indent(out) <<
|
|
837
|
-
"$xfer += $output->writeStructBegin('" << name << "');" << endl;
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
841
|
-
out <<
|
|
842
|
-
indent() << "if ($this->" << (*f_iter)->get_name() << " !== null) {" << endl;
|
|
843
|
-
indent_up();
|
|
844
|
-
|
|
845
|
-
t_type* type = get_true_type((*f_iter)->get_type());
|
|
846
|
-
string expect;
|
|
847
|
-
if (type->is_container()) {
|
|
848
|
-
expect = "array";
|
|
849
|
-
} else if (type->is_struct()) {
|
|
850
|
-
expect = "object";
|
|
851
|
-
}
|
|
852
|
-
if (!expect.empty()) {
|
|
853
|
-
out <<
|
|
854
|
-
indent() << "if (!is_" << expect << "($this->" << (*f_iter)->get_name() << ")) {" << endl;
|
|
855
|
-
indent_up();
|
|
856
|
-
out <<
|
|
857
|
-
indent() << "throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);" << endl;
|
|
858
|
-
scope_down(out);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// Write field header
|
|
862
|
-
if (binary_inline_) {
|
|
863
|
-
out <<
|
|
864
|
-
indent() << "$output .= pack('c', " << type_to_enum((*f_iter)->get_type()) << ");" << endl <<
|
|
865
|
-
indent() << "$output .= pack('n', " << (*f_iter)->get_key() << ");" << endl;
|
|
866
|
-
} else {
|
|
867
|
-
indent(out) <<
|
|
868
|
-
"$xfer += $output->writeFieldBegin(" <<
|
|
869
|
-
"'" << (*f_iter)->get_name() << "', " <<
|
|
870
|
-
type_to_enum((*f_iter)->get_type()) << ", " <<
|
|
871
|
-
(*f_iter)->get_key() << ");" << endl;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
// Write field contents
|
|
875
|
-
generate_serialize_field(out, *f_iter, "this->");
|
|
876
|
-
|
|
877
|
-
// Write field closer
|
|
878
|
-
if (!binary_inline_) {
|
|
879
|
-
indent(out) <<
|
|
880
|
-
"$xfer += $output->writeFieldEnd();" << endl;
|
|
881
|
-
}
|
|
882
|
-
|
|
883
|
-
indent_down();
|
|
884
|
-
indent(out) <<
|
|
885
|
-
"}" << endl;
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
if (binary_inline_) {
|
|
889
|
-
out <<
|
|
890
|
-
indent() << "$output .= pack('c', TType::STOP);" << endl;
|
|
891
|
-
} else {
|
|
892
|
-
out <<
|
|
893
|
-
indent() << "$xfer += $output->writeFieldStop();" << endl <<
|
|
894
|
-
indent() << "$xfer += $output->writeStructEnd();" << endl;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
out <<
|
|
898
|
-
indent() << "return $xfer;" << endl;
|
|
899
|
-
|
|
900
|
-
indent_down();
|
|
901
|
-
out <<
|
|
902
|
-
indent() << "}" << endl <<
|
|
903
|
-
endl;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
/**
|
|
907
|
-
* Generates a thrift service.
|
|
908
|
-
*
|
|
909
|
-
* @param tservice The service definition
|
|
910
|
-
*/
|
|
911
|
-
void t_php_generator::generate_service(t_service* tservice) {
|
|
912
|
-
string f_service_name = get_out_dir()+service_name_+".php";
|
|
913
|
-
f_service_.open(f_service_name.c_str());
|
|
914
|
-
|
|
915
|
-
f_service_ <<
|
|
916
|
-
"<?php" << endl <<
|
|
917
|
-
autogen_comment() <<
|
|
918
|
-
php_includes();
|
|
919
|
-
|
|
920
|
-
f_service_ <<
|
|
921
|
-
"include_once $GLOBALS['THRIFT_ROOT'].'/packages/" << program_name_ << "/" << program_name_ << "_types.php';" << endl;
|
|
922
|
-
|
|
923
|
-
if (tservice->get_extends() != NULL) {
|
|
924
|
-
f_service_ <<
|
|
925
|
-
"include_once $GLOBALS['THRIFT_ROOT'].'/packages/" << tservice->get_extends()->get_program()->get_name() << "/" << tservice->get_extends()->get_name() << ".php';" << endl;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
f_service_ <<
|
|
929
|
-
endl;
|
|
930
|
-
|
|
931
|
-
// Generate the three main parts of the service (well, two for now in PHP)
|
|
932
|
-
generate_service_interface(tservice);
|
|
933
|
-
if (rest_) {
|
|
934
|
-
generate_service_rest(tservice);
|
|
935
|
-
}
|
|
936
|
-
generate_service_client(tservice);
|
|
937
|
-
generate_service_helpers(tservice);
|
|
938
|
-
if (phps_) {
|
|
939
|
-
generate_service_processor(tservice);
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
// Close service file
|
|
943
|
-
f_service_ << "?>" << endl;
|
|
944
|
-
f_service_.close();
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
/**
|
|
948
|
-
* Generates a service server definition.
|
|
949
|
-
*
|
|
950
|
-
* @param tservice The service to generate a server for.
|
|
951
|
-
*/
|
|
952
|
-
void t_php_generator::generate_service_processor(t_service* tservice) {
|
|
953
|
-
// Generate the dispatch methods
|
|
954
|
-
vector<t_function*> functions = tservice->get_functions();
|
|
955
|
-
vector<t_function*>::iterator f_iter;
|
|
956
|
-
|
|
957
|
-
string extends = "";
|
|
958
|
-
string extends_processor = "";
|
|
959
|
-
if (tservice->get_extends() != NULL) {
|
|
960
|
-
extends = tservice->get_extends()->get_name();
|
|
961
|
-
extends_processor = " extends " + extends + "Processor";
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
// Generate the header portion
|
|
965
|
-
f_service_ <<
|
|
966
|
-
"class " << service_name_ << "Processor" << extends_processor << " {" << endl;
|
|
967
|
-
indent_up();
|
|
968
|
-
|
|
969
|
-
if (extends.empty()) {
|
|
970
|
-
f_service_ <<
|
|
971
|
-
indent() << "protected $handler_ = null;" << endl;
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
f_service_ <<
|
|
975
|
-
indent() << "public function __construct($handler) {" << endl;
|
|
976
|
-
if (extends.empty()) {
|
|
977
|
-
f_service_ <<
|
|
978
|
-
indent() << " $this->handler_ = $handler;" << endl;
|
|
979
|
-
} else {
|
|
980
|
-
f_service_ <<
|
|
981
|
-
indent() << " parent::__construct($handler);" << endl;
|
|
982
|
-
}
|
|
983
|
-
f_service_ <<
|
|
984
|
-
indent() << "}" << endl <<
|
|
985
|
-
endl;
|
|
986
|
-
|
|
987
|
-
// Generate the server implementation
|
|
988
|
-
indent(f_service_) <<
|
|
989
|
-
"public function process($input, $output) {" << endl;
|
|
990
|
-
indent_up();
|
|
991
|
-
|
|
992
|
-
f_service_ <<
|
|
993
|
-
indent() << "$rseqid = 0;" << endl <<
|
|
994
|
-
indent() << "$fname = null;" << endl <<
|
|
995
|
-
indent() << "$mtype = 0;" << endl <<
|
|
996
|
-
endl;
|
|
997
|
-
|
|
998
|
-
if (binary_inline_) {
|
|
999
|
-
t_field ffname(g_type_string, "fname");
|
|
1000
|
-
t_field fmtype(g_type_byte, "mtype");
|
|
1001
|
-
t_field fseqid(g_type_i32, "rseqid");
|
|
1002
|
-
generate_deserialize_field(f_service_, &ffname, "", true);
|
|
1003
|
-
generate_deserialize_field(f_service_, &fmtype, "", true);
|
|
1004
|
-
generate_deserialize_field(f_service_, &fseqid, "", true);
|
|
1005
|
-
} else {
|
|
1006
|
-
f_service_ <<
|
|
1007
|
-
indent() << "$input->readMessageBegin($fname, $mtype, $rseqid);" << endl;
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
// HOT: check for method implementation
|
|
1011
|
-
f_service_ <<
|
|
1012
|
-
indent() << "$methodname = 'process_'.$fname;" << endl <<
|
|
1013
|
-
indent() << "if (!method_exists($this, $methodname)) {" << endl;
|
|
1014
|
-
if (binary_inline_) {
|
|
1015
|
-
f_service_ <<
|
|
1016
|
-
indent() << " throw new Exception('Function '.$fname.' not implemented.');" << endl;
|
|
1017
|
-
} else {
|
|
1018
|
-
f_service_ <<
|
|
1019
|
-
indent() << " $input->skip(TType::STRUCT);" << endl <<
|
|
1020
|
-
indent() << " $input->readMessageEnd();" << endl <<
|
|
1021
|
-
indent() << " $x = new TApplicationException('Function '.$fname.' not implemented.', TApplicationException::UNKNOWN_METHOD);" << endl <<
|
|
1022
|
-
indent() << " $output->writeMessageBegin($fname, TMessageType::EXCEPTION, $rseqid);" << endl <<
|
|
1023
|
-
indent() << " $x->write($output);" << endl <<
|
|
1024
|
-
indent() << " $output->writeMessageEnd();" << endl <<
|
|
1025
|
-
indent() << " $output->getTransport()->flush();" << endl <<
|
|
1026
|
-
indent() << " return;" << endl;
|
|
1027
|
-
}
|
|
1028
|
-
f_service_ <<
|
|
1029
|
-
indent() << "}" << endl <<
|
|
1030
|
-
indent() << "$this->$methodname($rseqid, $input, $output);" << endl <<
|
|
1031
|
-
indent() << "return true;" << endl;
|
|
1032
|
-
indent_down();
|
|
1033
|
-
f_service_ <<
|
|
1034
|
-
indent() << "}" << endl <<
|
|
1035
|
-
endl;
|
|
1036
|
-
|
|
1037
|
-
// Generate the process subfunctions
|
|
1038
|
-
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
|
1039
|
-
generate_process_function(tservice, *f_iter);
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
indent_down();
|
|
1043
|
-
f_service_ << "}" << endl;
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
/**
|
|
1047
|
-
* Generates a process function definition.
|
|
1048
|
-
*
|
|
1049
|
-
* @param tfunction The function to write a dispatcher for
|
|
1050
|
-
*/
|
|
1051
|
-
void t_php_generator::generate_process_function(t_service* tservice,
|
|
1052
|
-
t_function* tfunction) {
|
|
1053
|
-
// Open function
|
|
1054
|
-
indent(f_service_) <<
|
|
1055
|
-
"protected function process_" << tfunction->get_name() <<
|
|
1056
|
-
"($seqid, $input, $output) {" << endl;
|
|
1057
|
-
indent_up();
|
|
1058
|
-
|
|
1059
|
-
string argsname = php_namespace(tservice->get_program()) + service_name_ + "_" + tfunction->get_name() + "_args";
|
|
1060
|
-
string resultname = php_namespace(tservice->get_program()) + service_name_ + "_" + tfunction->get_name() + "_result";
|
|
1061
|
-
|
|
1062
|
-
f_service_ <<
|
|
1063
|
-
indent() << "$args = new " << argsname << "();" << endl <<
|
|
1064
|
-
indent() << "$args->read($input);" << endl;
|
|
1065
|
-
if (!binary_inline_) {
|
|
1066
|
-
f_service_ <<
|
|
1067
|
-
indent() << "$input->readMessageEnd();" << endl;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
t_struct* xs = tfunction->get_xceptions();
|
|
1071
|
-
const std::vector<t_field*>& xceptions = xs->get_members();
|
|
1072
|
-
vector<t_field*>::const_iterator x_iter;
|
|
1073
|
-
|
|
1074
|
-
// Declare result for non oneway function
|
|
1075
|
-
if (!tfunction->is_oneway()) {
|
|
1076
|
-
f_service_ <<
|
|
1077
|
-
indent() << "$result = new " << resultname << "();" << endl;
|
|
1078
|
-
}
|
|
1079
|
-
|
|
1080
|
-
// Try block for a function with exceptions
|
|
1081
|
-
if (xceptions.size() > 0) {
|
|
1082
|
-
f_service_ <<
|
|
1083
|
-
indent() << "try {" << endl;
|
|
1084
|
-
indent_up();
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
// Generate the function call
|
|
1088
|
-
t_struct* arg_struct = tfunction->get_arglist();
|
|
1089
|
-
const std::vector<t_field*>& fields = arg_struct->get_members();
|
|
1090
|
-
vector<t_field*>::const_iterator f_iter;
|
|
1091
|
-
|
|
1092
|
-
f_service_ << indent();
|
|
1093
|
-
if (!tfunction->is_oneway() && !tfunction->get_returntype()->is_void()) {
|
|
1094
|
-
f_service_ << "$result->success = ";
|
|
1095
|
-
}
|
|
1096
|
-
f_service_ <<
|
|
1097
|
-
"$this->handler_->" << tfunction->get_name() << "(";
|
|
1098
|
-
bool first = true;
|
|
1099
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
1100
|
-
if (first) {
|
|
1101
|
-
first = false;
|
|
1102
|
-
} else {
|
|
1103
|
-
f_service_ << ", ";
|
|
1104
|
-
}
|
|
1105
|
-
f_service_ << "$args->" << (*f_iter)->get_name();
|
|
1106
|
-
}
|
|
1107
|
-
f_service_ << ");" << endl;
|
|
1108
|
-
|
|
1109
|
-
if (!tfunction->is_oneway() && xceptions.size() > 0) {
|
|
1110
|
-
indent_down();
|
|
1111
|
-
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
|
|
1112
|
-
f_service_ <<
|
|
1113
|
-
indent() << "} catch (" << php_namespace((*x_iter)->get_type()->get_program()) << (*x_iter)->get_type()->get_name() << " $" << (*x_iter)->get_name() << ") {" << endl;
|
|
1114
|
-
if (!tfunction->is_oneway()) {
|
|
1115
|
-
indent_up();
|
|
1116
|
-
f_service_ <<
|
|
1117
|
-
indent() << "$result->" << (*x_iter)->get_name() << " = $" << (*x_iter)->get_name() << ";" << endl;
|
|
1118
|
-
indent_down();
|
|
1119
|
-
f_service_ << indent();
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
f_service_ << "}" << endl;
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
// Shortcut out here for oneway functions
|
|
1126
|
-
if (tfunction->is_oneway()) {
|
|
1127
|
-
f_service_ <<
|
|
1128
|
-
indent() << "return;" << endl;
|
|
1129
|
-
indent_down();
|
|
1130
|
-
f_service_ <<
|
|
1131
|
-
indent() << "}" << endl;
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
// Serialize the request header
|
|
1136
|
-
if (binary_inline_) {
|
|
1137
|
-
f_service_ <<
|
|
1138
|
-
indent() << "$buff = pack('N', (0x80010000 | TMessageType::REPLY)); " << endl <<
|
|
1139
|
-
indent() << "$buff .= pack('N', strlen('" << tfunction->get_name() << "'));" << endl <<
|
|
1140
|
-
indent() << "$buff .= '" << tfunction->get_name() << "';" << endl <<
|
|
1141
|
-
indent() << "$buff .= pack('N', $seqid);" << endl <<
|
|
1142
|
-
indent() << "$result->write($buff);" << endl <<
|
|
1143
|
-
indent() << "$output->write($buff);" << endl <<
|
|
1144
|
-
indent() << "$output->flush();" << endl;
|
|
1145
|
-
} else {
|
|
1146
|
-
f_service_ <<
|
|
1147
|
-
indent() << "$output->writeMessageBegin('" << tfunction->get_name() << "', TMessageType::REPLY, $seqid);" << endl <<
|
|
1148
|
-
indent() << "$result->write($output);" << endl <<
|
|
1149
|
-
indent() << "$output->getTransport()->flush();" << endl;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
// Close function
|
|
1153
|
-
indent_down();
|
|
1154
|
-
f_service_ <<
|
|
1155
|
-
indent() << "}" << endl;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
/**
|
|
1159
|
-
* Generates helper functions for a service.
|
|
1160
|
-
*
|
|
1161
|
-
* @param tservice The service to generate a header definition for
|
|
1162
|
-
*/
|
|
1163
|
-
void t_php_generator::generate_service_helpers(t_service* tservice) {
|
|
1164
|
-
vector<t_function*> functions = tservice->get_functions();
|
|
1165
|
-
vector<t_function*>::iterator f_iter;
|
|
1166
|
-
|
|
1167
|
-
f_service_ <<
|
|
1168
|
-
"// HELPER FUNCTIONS AND STRUCTURES" << endl << endl;
|
|
1169
|
-
|
|
1170
|
-
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
|
1171
|
-
t_struct* ts = (*f_iter)->get_arglist();
|
|
1172
|
-
string name = ts->get_name();
|
|
1173
|
-
ts->set_name(service_name_ + "_" + name);
|
|
1174
|
-
generate_php_struct_definition(f_service_, ts, false);
|
|
1175
|
-
generate_php_function_helpers(*f_iter);
|
|
1176
|
-
ts->set_name(name);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
/**
|
|
1181
|
-
* Generates a struct and helpers for a function.
|
|
1182
|
-
*
|
|
1183
|
-
* @param tfunction The function
|
|
1184
|
-
*/
|
|
1185
|
-
void t_php_generator::generate_php_function_helpers(t_function* tfunction) {
|
|
1186
|
-
if (!tfunction->is_oneway()) {
|
|
1187
|
-
t_struct result(program_, service_name_ + "_" + tfunction->get_name() + "_result");
|
|
1188
|
-
t_field success(tfunction->get_returntype(), "success", 0);
|
|
1189
|
-
if (!tfunction->get_returntype()->is_void()) {
|
|
1190
|
-
result.append(&success);
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
t_struct* xs = tfunction->get_xceptions();
|
|
1194
|
-
const vector<t_field*>& fields = xs->get_members();
|
|
1195
|
-
vector<t_field*>::const_iterator f_iter;
|
|
1196
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
1197
|
-
result.append(*f_iter);
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
generate_php_struct_definition(f_service_, &result, false);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Generates a service interface definition.
|
|
1206
|
-
*
|
|
1207
|
-
* @param tservice The service to generate a header definition for
|
|
1208
|
-
*/
|
|
1209
|
-
void t_php_generator::generate_service_interface(t_service* tservice) {
|
|
1210
|
-
string extends = "";
|
|
1211
|
-
string extends_if = "";
|
|
1212
|
-
if (tservice->get_extends() != NULL) {
|
|
1213
|
-
extends = " extends " + tservice->get_extends()->get_name();
|
|
1214
|
-
extends_if = " extends " + tservice->get_extends()->get_name() + "If";
|
|
1215
|
-
}
|
|
1216
|
-
f_service_ <<
|
|
1217
|
-
"interface " << service_name_ << "If" << extends_if << " {" << endl;
|
|
1218
|
-
indent_up();
|
|
1219
|
-
vector<t_function*> functions = tservice->get_functions();
|
|
1220
|
-
vector<t_function*>::iterator f_iter;
|
|
1221
|
-
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
|
1222
|
-
indent(f_service_) <<
|
|
1223
|
-
"public function " << function_signature(*f_iter) << ";" << endl;
|
|
1224
|
-
}
|
|
1225
|
-
indent_down();
|
|
1226
|
-
f_service_ <<
|
|
1227
|
-
"}" << endl << endl;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
/**
|
|
1231
|
-
* Generates a REST interface
|
|
1232
|
-
*/
|
|
1233
|
-
void t_php_generator::generate_service_rest(t_service* tservice) {
|
|
1234
|
-
string extends = "";
|
|
1235
|
-
string extends_if = "";
|
|
1236
|
-
if (tservice->get_extends() != NULL) {
|
|
1237
|
-
extends = " extends " + tservice->get_extends()->get_name();
|
|
1238
|
-
extends_if = " extends " + tservice->get_extends()->get_name() + "Rest";
|
|
1239
|
-
}
|
|
1240
|
-
f_service_ <<
|
|
1241
|
-
"class " << service_name_ << "Rest" << extends_if << " {" << endl;
|
|
1242
|
-
indent_up();
|
|
1243
|
-
|
|
1244
|
-
if (extends.empty()) {
|
|
1245
|
-
f_service_ <<
|
|
1246
|
-
indent() << "protected $impl_;" << endl <<
|
|
1247
|
-
endl;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
f_service_ <<
|
|
1251
|
-
indent() << "public function __construct($impl) {" << endl <<
|
|
1252
|
-
indent() << " $this->impl_ = $impl;" << endl <<
|
|
1253
|
-
indent() << "}" << endl <<
|
|
1254
|
-
endl;
|
|
1255
|
-
|
|
1256
|
-
vector<t_function*> functions = tservice->get_functions();
|
|
1257
|
-
vector<t_function*>::iterator f_iter;
|
|
1258
|
-
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
|
1259
|
-
indent(f_service_) <<
|
|
1260
|
-
"public function " << (*f_iter)->get_name() << "($request) {" << endl;
|
|
1261
|
-
indent_up();
|
|
1262
|
-
const vector<t_field*>& args = (*f_iter)->get_arglist()->get_members();
|
|
1263
|
-
vector<t_field*>::const_iterator a_iter;
|
|
1264
|
-
for (a_iter = args.begin(); a_iter != args.end(); ++a_iter) {
|
|
1265
|
-
t_type* atype = get_true_type((*a_iter)->get_type());
|
|
1266
|
-
string cast = type_to_cast(atype);
|
|
1267
|
-
string req = "$request['" + (*a_iter)->get_name() + "']";
|
|
1268
|
-
if (atype->is_bool()) {
|
|
1269
|
-
f_service_ <<
|
|
1270
|
-
indent() << "$" << (*a_iter)->get_name() << " = " << cast << "(!empty(" << req << ") && (" << req << " !== 'false'));" << endl;
|
|
1271
|
-
} else {
|
|
1272
|
-
f_service_ <<
|
|
1273
|
-
indent() << "$" << (*a_iter)->get_name() << " = isset(" << req << ") ? " << cast << req << " : null;" << endl;
|
|
1274
|
-
}
|
|
1275
|
-
if (atype->is_string() &&
|
|
1276
|
-
((t_base_type*)atype)->is_string_list()) {
|
|
1277
|
-
f_service_ <<
|
|
1278
|
-
indent() << "$" << (*a_iter)->get_name() << " = explode(',', $" << (*a_iter)->get_name() << ");" << endl;
|
|
1279
|
-
} else if (atype->is_map() || atype->is_list()) {
|
|
1280
|
-
f_service_ <<
|
|
1281
|
-
indent() << "$" << (*a_iter)->get_name() << " = json_decode($" << (*a_iter)->get_name() << ", true);" << endl;
|
|
1282
|
-
} else if (atype->is_set()) {
|
|
1283
|
-
f_service_ <<
|
|
1284
|
-
indent() << "$" << (*a_iter)->get_name() << " = array_fill_keys(json_decode($" << (*a_iter)->get_name() << ", true), 1);" << endl;
|
|
1285
|
-
} else if (atype->is_struct() || atype->is_xception()) {
|
|
1286
|
-
f_service_ <<
|
|
1287
|
-
indent() << "if ($" << (*a_iter)->get_name() << " !== null) {" << endl <<
|
|
1288
|
-
indent() << " $" << (*a_iter)->get_name() << " = new " << php_namespace(atype->get_program()) << atype->get_name() << "(json_decode($" << (*a_iter)->get_name() << ", true));" << endl <<
|
|
1289
|
-
indent() << "}" << endl;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
f_service_ <<
|
|
1293
|
-
indent() << "return $this->impl_->" << (*f_iter)->get_name() << "(" << argument_list((*f_iter)->get_arglist()) << ");" << endl;
|
|
1294
|
-
indent_down();
|
|
1295
|
-
indent(f_service_) <<
|
|
1296
|
-
"}" << endl <<
|
|
1297
|
-
endl;
|
|
1298
|
-
}
|
|
1299
|
-
indent_down();
|
|
1300
|
-
f_service_ <<
|
|
1301
|
-
"}" << endl << endl;
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
void t_php_generator::generate_service_client(t_service* tservice) {
|
|
1305
|
-
if (autoload_) {
|
|
1306
|
-
// Make output file
|
|
1307
|
-
ofstream autoload_out;
|
|
1308
|
-
string f_struct = program_name_+"."+(tservice->get_name())+".client.php";
|
|
1309
|
-
string f_struct_name = get_out_dir()+f_struct;
|
|
1310
|
-
autoload_out.open(f_struct_name.c_str());
|
|
1311
|
-
autoload_out << "<?php" << endl;
|
|
1312
|
-
_generate_service_client(autoload_out, tservice);
|
|
1313
|
-
autoload_out << endl << "?>" << endl;
|
|
1314
|
-
autoload_out.close();
|
|
1315
|
-
|
|
1316
|
-
f_service_ <<
|
|
1317
|
-
"$GLOBALS['THRIFT_AUTOLOAD']['" << lowercase(service_name_ + "Client") << "'] = '" << program_name_ << "/" << f_struct << "';" << endl;
|
|
1318
|
-
|
|
1319
|
-
} else {
|
|
1320
|
-
_generate_service_client(f_service_, tservice);
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* Generates a service client definition.
|
|
1326
|
-
*
|
|
1327
|
-
* @param tservice The service to generate a server for.
|
|
1328
|
-
*/
|
|
1329
|
-
void t_php_generator::_generate_service_client(ofstream& out, t_service* tservice) {
|
|
1330
|
-
string extends = "";
|
|
1331
|
-
string extends_client = "";
|
|
1332
|
-
if (tservice->get_extends() != NULL) {
|
|
1333
|
-
extends = tservice->get_extends()->get_name();
|
|
1334
|
-
extends_client = " extends " + extends + "Client";
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
out <<
|
|
1338
|
-
"class " << service_name_ << "Client" << extends_client << " implements " << service_name_ << "If {" << endl;
|
|
1339
|
-
indent_up();
|
|
1340
|
-
|
|
1341
|
-
// Private members
|
|
1342
|
-
if (extends.empty()) {
|
|
1343
|
-
out <<
|
|
1344
|
-
indent() << "protected $input_ = null;" << endl <<
|
|
1345
|
-
indent() << "protected $output_ = null;" << endl <<
|
|
1346
|
-
endl;
|
|
1347
|
-
out <<
|
|
1348
|
-
indent() << "protected $seqid_ = 0;" << endl <<
|
|
1349
|
-
endl;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
// Constructor function
|
|
1353
|
-
out <<
|
|
1354
|
-
indent() << "public function __construct($input, $output=null) {" << endl;
|
|
1355
|
-
if (!extends.empty()) {
|
|
1356
|
-
out <<
|
|
1357
|
-
indent() << " parent::__construct($input, $output);" << endl;
|
|
1358
|
-
} else {
|
|
1359
|
-
out <<
|
|
1360
|
-
indent() << " $this->input_ = $input;" << endl <<
|
|
1361
|
-
indent() << " $this->output_ = $output ? $output : $input;" << endl;
|
|
1362
|
-
}
|
|
1363
|
-
out <<
|
|
1364
|
-
indent() << "}" << endl << endl;
|
|
1365
|
-
|
|
1366
|
-
// Generate client method implementations
|
|
1367
|
-
vector<t_function*> functions = tservice->get_functions();
|
|
1368
|
-
vector<t_function*>::const_iterator f_iter;
|
|
1369
|
-
for (f_iter = functions.begin(); f_iter != functions.end(); ++f_iter) {
|
|
1370
|
-
t_struct* arg_struct = (*f_iter)->get_arglist();
|
|
1371
|
-
const vector<t_field*>& fields = arg_struct->get_members();
|
|
1372
|
-
vector<t_field*>::const_iterator fld_iter;
|
|
1373
|
-
string funname = (*f_iter)->get_name();
|
|
1374
|
-
|
|
1375
|
-
// Open function
|
|
1376
|
-
indent(out) <<
|
|
1377
|
-
"public function " << function_signature(*f_iter) << endl;
|
|
1378
|
-
scope_up(out);
|
|
1379
|
-
indent(out) <<
|
|
1380
|
-
"$this->send_" << funname << "(";
|
|
1381
|
-
|
|
1382
|
-
bool first = true;
|
|
1383
|
-
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
|
1384
|
-
if (first) {
|
|
1385
|
-
first = false;
|
|
1386
|
-
} else {
|
|
1387
|
-
out << ", ";
|
|
1388
|
-
}
|
|
1389
|
-
out << "$" << (*fld_iter)->get_name();
|
|
1390
|
-
}
|
|
1391
|
-
out << ");" << endl;
|
|
1392
|
-
|
|
1393
|
-
if (!(*f_iter)->is_oneway()) {
|
|
1394
|
-
out << indent();
|
|
1395
|
-
if (!(*f_iter)->get_returntype()->is_void()) {
|
|
1396
|
-
out << "return ";
|
|
1397
|
-
}
|
|
1398
|
-
out <<
|
|
1399
|
-
"$this->recv_" << funname << "();" << endl;
|
|
1400
|
-
}
|
|
1401
|
-
scope_down(out);
|
|
1402
|
-
out << endl;
|
|
1403
|
-
|
|
1404
|
-
indent(out) <<
|
|
1405
|
-
"public function send_" << function_signature(*f_iter) << endl;
|
|
1406
|
-
scope_up(out);
|
|
1407
|
-
|
|
1408
|
-
std::string argsname = php_namespace(tservice->get_program()) + service_name_ + "_" + (*f_iter)->get_name() + "_args";
|
|
1409
|
-
|
|
1410
|
-
out <<
|
|
1411
|
-
indent() << "$args = new " << argsname << "();" << endl;
|
|
1412
|
-
|
|
1413
|
-
for (fld_iter = fields.begin(); fld_iter != fields.end(); ++fld_iter) {
|
|
1414
|
-
out <<
|
|
1415
|
-
indent() << "$args->" << (*fld_iter)->get_name() << " = $" << (*fld_iter)->get_name() << ";" << endl;
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
out <<
|
|
1419
|
-
indent() << "$bin_accel = ($this->output_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED) && function_exists('thrift_protocol_write_binary');" << endl;
|
|
1420
|
-
|
|
1421
|
-
out <<
|
|
1422
|
-
indent() << "if ($bin_accel)" << endl;
|
|
1423
|
-
scope_up(out);
|
|
1424
|
-
|
|
1425
|
-
out <<
|
|
1426
|
-
indent() << "thrift_protocol_write_binary($this->output_, '" << (*f_iter)->get_name() << "', TMessageType::CALL, $args, $this->seqid_, $this->output_->isStrictWrite());" << endl;
|
|
1427
|
-
|
|
1428
|
-
scope_down(out);
|
|
1429
|
-
out <<
|
|
1430
|
-
indent() << "else" << endl;
|
|
1431
|
-
scope_up(out);
|
|
1432
|
-
|
|
1433
|
-
// Serialize the request header
|
|
1434
|
-
if (binary_inline_) {
|
|
1435
|
-
out <<
|
|
1436
|
-
indent() << "$buff = pack('N', (0x80010000 | TMessageType::CALL));" << endl <<
|
|
1437
|
-
indent() << "$buff .= pack('N', strlen('" << funname << "'));" << endl <<
|
|
1438
|
-
indent() << "$buff .= '" << funname << "';" << endl <<
|
|
1439
|
-
indent() << "$buff .= pack('N', $this->seqid_);" << endl;
|
|
1440
|
-
} else {
|
|
1441
|
-
out <<
|
|
1442
|
-
indent() << "$this->output_->writeMessageBegin('" << (*f_iter)->get_name() << "', TMessageType::CALL, $this->seqid_);" << endl;
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
// Write to the stream
|
|
1446
|
-
if (binary_inline_) {
|
|
1447
|
-
out <<
|
|
1448
|
-
indent() << "$args->write($buff);" << endl <<
|
|
1449
|
-
indent() << "$this->output_->write($buff);" << endl <<
|
|
1450
|
-
indent() << "$this->output_->flush();" << endl;
|
|
1451
|
-
} else {
|
|
1452
|
-
out <<
|
|
1453
|
-
indent() << "$args->write($this->output_);" << endl <<
|
|
1454
|
-
indent() << "$this->output_->writeMessageEnd();" << endl <<
|
|
1455
|
-
indent() << "$this->output_->getTransport()->flush();" << endl;
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
scope_down(out);
|
|
1459
|
-
|
|
1460
|
-
scope_down(out);
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
if (!(*f_iter)->is_oneway()) {
|
|
1464
|
-
std::string resultname = php_namespace(tservice->get_program()) + service_name_ + "_" + (*f_iter)->get_name() + "_result";
|
|
1465
|
-
t_struct noargs(program_);
|
|
1466
|
-
|
|
1467
|
-
t_function recv_function((*f_iter)->get_returntype(),
|
|
1468
|
-
string("recv_") + (*f_iter)->get_name(),
|
|
1469
|
-
&noargs);
|
|
1470
|
-
// Open function
|
|
1471
|
-
out <<
|
|
1472
|
-
endl <<
|
|
1473
|
-
indent() << "public function " << function_signature(&recv_function) << endl;
|
|
1474
|
-
scope_up(out);
|
|
1475
|
-
|
|
1476
|
-
out <<
|
|
1477
|
-
indent() << "$bin_accel = ($this->input_ instanceof TProtocol::$TBINARYPROTOCOLACCELERATED)"
|
|
1478
|
-
<< " && function_exists('thrift_protocol_read_binary');" << endl;
|
|
1479
|
-
|
|
1480
|
-
out <<
|
|
1481
|
-
indent() << "if ($bin_accel) $result = thrift_protocol_read_binary($this->input_, '" << resultname << "', $this->input_->isStrictRead());" << endl;
|
|
1482
|
-
out <<
|
|
1483
|
-
indent() << "else" << endl;
|
|
1484
|
-
scope_up(out);
|
|
1485
|
-
|
|
1486
|
-
out <<
|
|
1487
|
-
indent() << "$rseqid = 0;" << endl <<
|
|
1488
|
-
indent() << "$fname = null;" << endl <<
|
|
1489
|
-
indent() << "$mtype = 0;" << endl <<
|
|
1490
|
-
endl;
|
|
1491
|
-
|
|
1492
|
-
if (binary_inline_) {
|
|
1493
|
-
t_field ffname(g_type_string, "fname");
|
|
1494
|
-
t_field fseqid(g_type_i32, "rseqid");
|
|
1495
|
-
out <<
|
|
1496
|
-
indent() << "$ver = unpack('N', $this->input_->readAll(4));" << endl <<
|
|
1497
|
-
indent() << "$ver = $ver[1];" << endl <<
|
|
1498
|
-
indent() << "$mtype = $ver & 0xff;" << endl <<
|
|
1499
|
-
indent() << "$ver = $ver & 0xffff0000;" << endl <<
|
|
1500
|
-
indent() << "if ($ver != 0x80010000) throw new TProtocolException('Bad version identifier: '.$ver, TProtocolException::BAD_VERSION);" << endl;
|
|
1501
|
-
generate_deserialize_field(out, &ffname, "", true);
|
|
1502
|
-
generate_deserialize_field(out, &fseqid, "", true);
|
|
1503
|
-
} else {
|
|
1504
|
-
out <<
|
|
1505
|
-
indent() << "$this->input_->readMessageBegin($fname, $mtype, $rseqid);" << endl <<
|
|
1506
|
-
indent() << "if ($mtype == TMessageType::EXCEPTION) {" << endl <<
|
|
1507
|
-
indent() << " $x = new TApplicationException();" << endl <<
|
|
1508
|
-
indent() << " $x->read($this->input_);" << endl <<
|
|
1509
|
-
indent() << " $this->input_->readMessageEnd();" << endl <<
|
|
1510
|
-
indent() << " throw $x;" << endl <<
|
|
1511
|
-
indent() << "}" << endl;
|
|
1512
|
-
}
|
|
1513
|
-
|
|
1514
|
-
out <<
|
|
1515
|
-
indent() << "$result = new " << resultname << "();" << endl <<
|
|
1516
|
-
indent() << "$result->read($this->input_);" << endl;
|
|
1517
|
-
|
|
1518
|
-
if (!binary_inline_) {
|
|
1519
|
-
out <<
|
|
1520
|
-
indent() << "$this->input_->readMessageEnd();" << endl;
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
|
-
scope_down(out);
|
|
1524
|
-
|
|
1525
|
-
// Careful, only return result if not a void function
|
|
1526
|
-
if (!(*f_iter)->get_returntype()->is_void()) {
|
|
1527
|
-
out <<
|
|
1528
|
-
indent() << "if ($result->success !== null) {" << endl <<
|
|
1529
|
-
indent() << " return $result->success;" << endl <<
|
|
1530
|
-
indent() << "}" << endl;
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
t_struct* xs = (*f_iter)->get_xceptions();
|
|
1534
|
-
const std::vector<t_field*>& xceptions = xs->get_members();
|
|
1535
|
-
vector<t_field*>::const_iterator x_iter;
|
|
1536
|
-
for (x_iter = xceptions.begin(); x_iter != xceptions.end(); ++x_iter) {
|
|
1537
|
-
out <<
|
|
1538
|
-
indent() << "if ($result->" << (*x_iter)->get_name() << " !== null) {" << endl <<
|
|
1539
|
-
indent() << " throw $result->" << (*x_iter)->get_name() << ";" << endl <<
|
|
1540
|
-
indent() << "}" << endl;
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
// Careful, only return _result if not a void function
|
|
1544
|
-
if ((*f_iter)->get_returntype()->is_void()) {
|
|
1545
|
-
indent(out) <<
|
|
1546
|
-
"return;" << endl;
|
|
1547
|
-
} else {
|
|
1548
|
-
out <<
|
|
1549
|
-
indent() << "throw new Exception(\"" << (*f_iter)->get_name() << " failed: unknown result\");" << endl;
|
|
1550
|
-
}
|
|
1551
|
-
|
|
1552
|
-
// Close function
|
|
1553
|
-
scope_down(out);
|
|
1554
|
-
out << endl;
|
|
1555
|
-
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
|
|
1559
|
-
indent_down();
|
|
1560
|
-
out <<
|
|
1561
|
-
"}" << endl << endl;
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
/**
|
|
1565
|
-
* Deserializes a field of any type.
|
|
1566
|
-
*/
|
|
1567
|
-
void t_php_generator::generate_deserialize_field(ofstream &out,
|
|
1568
|
-
t_field* tfield,
|
|
1569
|
-
string prefix,
|
|
1570
|
-
bool inclass) {
|
|
1571
|
-
t_type* type = get_true_type(tfield->get_type());
|
|
1572
|
-
|
|
1573
|
-
if (type->is_void()) {
|
|
1574
|
-
throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE: " +
|
|
1575
|
-
prefix + tfield->get_name();
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
string name = prefix + tfield->get_name();
|
|
1579
|
-
|
|
1580
|
-
if (type->is_struct() || type->is_xception()) {
|
|
1581
|
-
generate_deserialize_struct(out,
|
|
1582
|
-
(t_struct*)type,
|
|
1583
|
-
name);
|
|
1584
|
-
} else {
|
|
1585
|
-
|
|
1586
|
-
if (type->is_container()) {
|
|
1587
|
-
generate_deserialize_container(out, type, name);
|
|
1588
|
-
} else if (type->is_base_type() || type->is_enum()) {
|
|
1589
|
-
|
|
1590
|
-
if (binary_inline_) {
|
|
1591
|
-
std::string itrans = (inclass ? "$this->input_" : "$input");
|
|
1592
|
-
|
|
1593
|
-
if (type->is_base_type()) {
|
|
1594
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
1595
|
-
switch (tbase) {
|
|
1596
|
-
case t_base_type::TYPE_VOID:
|
|
1597
|
-
throw "compiler error: cannot serialize void field in a struct: " +
|
|
1598
|
-
name;
|
|
1599
|
-
break;
|
|
1600
|
-
case t_base_type::TYPE_STRING:
|
|
1601
|
-
out <<
|
|
1602
|
-
indent() << "$len = unpack('N', " << itrans << "->readAll(4));" << endl <<
|
|
1603
|
-
indent() << "$len = $len[1];" << endl <<
|
|
1604
|
-
indent() << "if ($len > 0x7fffffff) {" << endl <<
|
|
1605
|
-
indent() << " $len = 0 - (($len - 1) ^ 0xffffffff);" << endl <<
|
|
1606
|
-
indent() << "}" << endl <<
|
|
1607
|
-
indent() << "$" << name << " = " << itrans << "->readAll($len);" << endl;
|
|
1608
|
-
break;
|
|
1609
|
-
case t_base_type::TYPE_BOOL:
|
|
1610
|
-
out <<
|
|
1611
|
-
indent() << "$" << name << " = unpack('c', " << itrans << "->readAll(1));" << endl <<
|
|
1612
|
-
indent() << "$" << name << " = (bool)$" << name << "[1];" << endl;
|
|
1613
|
-
break;
|
|
1614
|
-
case t_base_type::TYPE_BYTE:
|
|
1615
|
-
out <<
|
|
1616
|
-
indent() << "$" << name << " = unpack('c', " << itrans << "->readAll(1));" << endl <<
|
|
1617
|
-
indent() << "$" << name << " = $" << name << "[1];" << endl;
|
|
1618
|
-
break;
|
|
1619
|
-
case t_base_type::TYPE_I16:
|
|
1620
|
-
out <<
|
|
1621
|
-
indent() << "$val = unpack('n', " << itrans << "->readAll(2));" << endl <<
|
|
1622
|
-
indent() << "$val = $val[1];" << endl <<
|
|
1623
|
-
indent() << "if ($val > 0x7fff) {" << endl <<
|
|
1624
|
-
indent() << " $val = 0 - (($val - 1) ^ 0xffff);" << endl <<
|
|
1625
|
-
indent() << "}" << endl <<
|
|
1626
|
-
indent() << "$" << name << " = $val;" << endl;
|
|
1627
|
-
break;
|
|
1628
|
-
case t_base_type::TYPE_I32:
|
|
1629
|
-
out <<
|
|
1630
|
-
indent() << "$val = unpack('N', " << itrans << "->readAll(4));" << endl <<
|
|
1631
|
-
indent() << "$val = $val[1];" << endl <<
|
|
1632
|
-
indent() << "if ($val > 0x7fffffff) {" << endl <<
|
|
1633
|
-
indent() << " $val = 0 - (($val - 1) ^ 0xffffffff);" << endl <<
|
|
1634
|
-
indent() << "}" << endl <<
|
|
1635
|
-
indent() << "$" << name << " = $val;" << endl;
|
|
1636
|
-
break;
|
|
1637
|
-
case t_base_type::TYPE_I64:
|
|
1638
|
-
out <<
|
|
1639
|
-
indent() << "$arr = unpack('N2', " << itrans << "->readAll(8));" << endl <<
|
|
1640
|
-
indent() << "if ($arr[1] & 0x80000000) {" << endl <<
|
|
1641
|
-
indent() << " $arr[1] = $arr[1] ^ 0xFFFFFFFF;" << endl <<
|
|
1642
|
-
indent() << " $arr[2] = $arr[2] ^ 0xFFFFFFFF;" << endl <<
|
|
1643
|
-
indent() << " $" << name << " = 0 - $arr[1]*4294967296 - $arr[2] - 1;" << endl <<
|
|
1644
|
-
indent() << "} else {" << endl <<
|
|
1645
|
-
indent() << " $" << name << " = $arr[1]*4294967296 + $arr[2];" << endl <<
|
|
1646
|
-
indent() << "}" << endl;
|
|
1647
|
-
break;
|
|
1648
|
-
case t_base_type::TYPE_DOUBLE:
|
|
1649
|
-
out <<
|
|
1650
|
-
indent() << "$arr = unpack('d', strrev(" << itrans << "->readAll(8)));" << endl <<
|
|
1651
|
-
indent() << "$" << name << " = $arr[1];" << endl;
|
|
1652
|
-
break;
|
|
1653
|
-
default:
|
|
1654
|
-
throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase) + tfield->get_name();
|
|
1655
|
-
}
|
|
1656
|
-
} else if (type->is_enum()) {
|
|
1657
|
-
out <<
|
|
1658
|
-
indent() << "$val = unpack('N', " << itrans << "->readAll(4));" << endl <<
|
|
1659
|
-
indent() << "$val = $val[1];" << endl <<
|
|
1660
|
-
indent() << "if ($val > 0x7fffffff) {" << endl <<
|
|
1661
|
-
indent() << " $val = 0 - (($val - 1) ^ 0xffffffff);" << endl <<
|
|
1662
|
-
indent() << "}" << endl <<
|
|
1663
|
-
indent() << "$" << name << " = $val;" << endl;
|
|
1664
|
-
}
|
|
1665
|
-
} else {
|
|
1666
|
-
|
|
1667
|
-
indent(out) <<
|
|
1668
|
-
"$xfer += $input->";
|
|
1669
|
-
|
|
1670
|
-
if (type->is_base_type()) {
|
|
1671
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
1672
|
-
switch (tbase) {
|
|
1673
|
-
case t_base_type::TYPE_VOID:
|
|
1674
|
-
throw "compiler error: cannot serialize void field in a struct: " +
|
|
1675
|
-
name;
|
|
1676
|
-
break;
|
|
1677
|
-
case t_base_type::TYPE_STRING:
|
|
1678
|
-
out << "readString($" << name << ");";
|
|
1679
|
-
break;
|
|
1680
|
-
case t_base_type::TYPE_BOOL:
|
|
1681
|
-
out << "readBool($" << name << ");";
|
|
1682
|
-
break;
|
|
1683
|
-
case t_base_type::TYPE_BYTE:
|
|
1684
|
-
out << "readByte($" << name << ");";
|
|
1685
|
-
break;
|
|
1686
|
-
case t_base_type::TYPE_I16:
|
|
1687
|
-
out << "readI16($" << name << ");";
|
|
1688
|
-
break;
|
|
1689
|
-
case t_base_type::TYPE_I32:
|
|
1690
|
-
out << "readI32($" << name << ");";
|
|
1691
|
-
break;
|
|
1692
|
-
case t_base_type::TYPE_I64:
|
|
1693
|
-
out << "readI64($" << name << ");";
|
|
1694
|
-
break;
|
|
1695
|
-
case t_base_type::TYPE_DOUBLE:
|
|
1696
|
-
out << "readDouble($" << name << ");";
|
|
1697
|
-
break;
|
|
1698
|
-
default:
|
|
1699
|
-
throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase);
|
|
1700
|
-
}
|
|
1701
|
-
} else if (type->is_enum()) {
|
|
1702
|
-
out << "readI32($" << name << ");";
|
|
1703
|
-
}
|
|
1704
|
-
out << endl;
|
|
1705
|
-
}
|
|
1706
|
-
} else {
|
|
1707
|
-
printf("DO NOT KNOW HOW TO DESERIALIZE FIELD '%s' TYPE '%s'\n",
|
|
1708
|
-
tfield->get_name().c_str(), type->get_name().c_str());
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
/**
|
|
1714
|
-
* Generates an unserializer for a variable. This makes two key assumptions,
|
|
1715
|
-
* first that there is a const char* variable named data that points to the
|
|
1716
|
-
* buffer for deserialization, and that there is a variable protocol which
|
|
1717
|
-
* is a reference to a TProtocol serialization object.
|
|
1718
|
-
*/
|
|
1719
|
-
void t_php_generator::generate_deserialize_struct(ofstream &out,
|
|
1720
|
-
t_struct* tstruct,
|
|
1721
|
-
string prefix) {
|
|
1722
|
-
out <<
|
|
1723
|
-
indent() << "$" << prefix << " = new " << php_namespace(tstruct->get_program()) << tstruct->get_name() << "();" << endl <<
|
|
1724
|
-
indent() << "$xfer += $" << prefix << "->read($input);" << endl;
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
|
-
void t_php_generator::generate_deserialize_container(ofstream &out,
|
|
1728
|
-
t_type* ttype,
|
|
1729
|
-
string prefix) {
|
|
1730
|
-
string size = tmp("_size");
|
|
1731
|
-
string ktype = tmp("_ktype");
|
|
1732
|
-
string vtype = tmp("_vtype");
|
|
1733
|
-
string etype = tmp("_etype");
|
|
1734
|
-
|
|
1735
|
-
t_field fsize(g_type_i32, size);
|
|
1736
|
-
t_field fktype(g_type_byte, ktype);
|
|
1737
|
-
t_field fvtype(g_type_byte, vtype);
|
|
1738
|
-
t_field fetype(g_type_byte, etype);
|
|
1739
|
-
|
|
1740
|
-
out <<
|
|
1741
|
-
indent() << "$" << prefix << " = array();" << endl <<
|
|
1742
|
-
indent() << "$" << size << " = 0;" << endl;
|
|
1743
|
-
|
|
1744
|
-
// Declare variables, read header
|
|
1745
|
-
if (ttype->is_map()) {
|
|
1746
|
-
out <<
|
|
1747
|
-
indent() << "$" << ktype << " = 0;" << endl <<
|
|
1748
|
-
indent() << "$" << vtype << " = 0;" << endl;
|
|
1749
|
-
if (binary_inline_) {
|
|
1750
|
-
generate_deserialize_field(out, &fktype);
|
|
1751
|
-
generate_deserialize_field(out, &fvtype);
|
|
1752
|
-
generate_deserialize_field(out, &fsize);
|
|
1753
|
-
} else {
|
|
1754
|
-
out <<
|
|
1755
|
-
indent() << "$xfer += $input->readMapBegin(" <<
|
|
1756
|
-
"$" << ktype << ", $" << vtype << ", $" << size << ");" << endl;
|
|
1757
|
-
}
|
|
1758
|
-
} else if (ttype->is_set()) {
|
|
1759
|
-
if (binary_inline_) {
|
|
1760
|
-
generate_deserialize_field(out, &fetype);
|
|
1761
|
-
generate_deserialize_field(out, &fsize);
|
|
1762
|
-
} else {
|
|
1763
|
-
out <<
|
|
1764
|
-
indent() << "$" << etype << " = 0;" << endl <<
|
|
1765
|
-
indent() << "$xfer += $input->readSetBegin(" <<
|
|
1766
|
-
"$" << etype << ", $" << size << ");" << endl;
|
|
1767
|
-
}
|
|
1768
|
-
} else if (ttype->is_list()) {
|
|
1769
|
-
if (binary_inline_) {
|
|
1770
|
-
generate_deserialize_field(out, &fetype);
|
|
1771
|
-
generate_deserialize_field(out, &fsize);
|
|
1772
|
-
} else {
|
|
1773
|
-
out <<
|
|
1774
|
-
indent() << "$" << etype << " = 0;" << endl <<
|
|
1775
|
-
indent() << "$xfer += $input->readListBegin(" <<
|
|
1776
|
-
"$" << etype << ", $" << size << ");" << endl;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
// For loop iterates over elements
|
|
1781
|
-
string i = tmp("_i");
|
|
1782
|
-
indent(out) <<
|
|
1783
|
-
"for ($" <<
|
|
1784
|
-
i << " = 0; $" << i << " < $" << size << "; ++$" << i << ")" << endl;
|
|
1785
|
-
|
|
1786
|
-
scope_up(out);
|
|
1787
|
-
|
|
1788
|
-
if (ttype->is_map()) {
|
|
1789
|
-
generate_deserialize_map_element(out, (t_map*)ttype, prefix);
|
|
1790
|
-
} else if (ttype->is_set()) {
|
|
1791
|
-
generate_deserialize_set_element(out, (t_set*)ttype, prefix);
|
|
1792
|
-
} else if (ttype->is_list()) {
|
|
1793
|
-
generate_deserialize_list_element(out, (t_list*)ttype, prefix);
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
|
-
scope_down(out);
|
|
1797
|
-
|
|
1798
|
-
if (!binary_inline_) {
|
|
1799
|
-
// Read container end
|
|
1800
|
-
if (ttype->is_map()) {
|
|
1801
|
-
indent(out) << "$xfer += $input->readMapEnd();" << endl;
|
|
1802
|
-
} else if (ttype->is_set()) {
|
|
1803
|
-
indent(out) << "$xfer += $input->readSetEnd();" << endl;
|
|
1804
|
-
} else if (ttype->is_list()) {
|
|
1805
|
-
indent(out) << "$xfer += $input->readListEnd();" << endl;
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
/**
|
|
1812
|
-
* Generates code to deserialize a map
|
|
1813
|
-
*/
|
|
1814
|
-
void t_php_generator::generate_deserialize_map_element(ofstream &out,
|
|
1815
|
-
t_map* tmap,
|
|
1816
|
-
string prefix) {
|
|
1817
|
-
string key = tmp("key");
|
|
1818
|
-
string val = tmp("val");
|
|
1819
|
-
t_field fkey(tmap->get_key_type(), key);
|
|
1820
|
-
t_field fval(tmap->get_val_type(), val);
|
|
1821
|
-
|
|
1822
|
-
indent(out) <<
|
|
1823
|
-
declare_field(&fkey, true, true) << endl;
|
|
1824
|
-
indent(out) <<
|
|
1825
|
-
declare_field(&fval, true, true) << endl;
|
|
1826
|
-
|
|
1827
|
-
generate_deserialize_field(out, &fkey);
|
|
1828
|
-
generate_deserialize_field(out, &fval);
|
|
1829
|
-
|
|
1830
|
-
indent(out) <<
|
|
1831
|
-
"$" << prefix << "[$" << key << "] = $" << val << ";" << endl;
|
|
1832
|
-
}
|
|
1833
|
-
|
|
1834
|
-
void t_php_generator::generate_deserialize_set_element(ofstream &out,
|
|
1835
|
-
t_set* tset,
|
|
1836
|
-
string prefix) {
|
|
1837
|
-
string elem = tmp("elem");
|
|
1838
|
-
t_field felem(tset->get_elem_type(), elem);
|
|
1839
|
-
|
|
1840
|
-
indent(out) <<
|
|
1841
|
-
"$" << elem << " = null;" << endl;
|
|
1842
|
-
|
|
1843
|
-
generate_deserialize_field(out, &felem);
|
|
1844
|
-
|
|
1845
|
-
indent(out) <<
|
|
1846
|
-
"$" << prefix << "[$" << elem << "] = true;" << endl;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
void t_php_generator::generate_deserialize_list_element(ofstream &out,
|
|
1850
|
-
t_list* tlist,
|
|
1851
|
-
string prefix) {
|
|
1852
|
-
string elem = tmp("elem");
|
|
1853
|
-
t_field felem(tlist->get_elem_type(), elem);
|
|
1854
|
-
|
|
1855
|
-
indent(out) <<
|
|
1856
|
-
"$" << elem << " = null;" << endl;
|
|
1857
|
-
|
|
1858
|
-
generate_deserialize_field(out, &felem);
|
|
1859
|
-
|
|
1860
|
-
indent(out) <<
|
|
1861
|
-
"$" << prefix << " []= $" << elem << ";" << endl;
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
/**
|
|
1866
|
-
* Serializes a field of any type.
|
|
1867
|
-
*
|
|
1868
|
-
* @param tfield The field to serialize
|
|
1869
|
-
* @param prefix Name to prepend to field name
|
|
1870
|
-
*/
|
|
1871
|
-
void t_php_generator::generate_serialize_field(ofstream &out,
|
|
1872
|
-
t_field* tfield,
|
|
1873
|
-
string prefix) {
|
|
1874
|
-
t_type* type = get_true_type(tfield->get_type());
|
|
1875
|
-
|
|
1876
|
-
// Do nothing for void types
|
|
1877
|
-
if (type->is_void()) {
|
|
1878
|
-
throw "CANNOT GENERATE SERIALIZE CODE FOR void TYPE: " +
|
|
1879
|
-
prefix + tfield->get_name();
|
|
1880
|
-
}
|
|
1881
|
-
|
|
1882
|
-
if (type->is_struct() || type->is_xception()) {
|
|
1883
|
-
generate_serialize_struct(out,
|
|
1884
|
-
(t_struct*)type,
|
|
1885
|
-
prefix + tfield->get_name());
|
|
1886
|
-
} else if (type->is_container()) {
|
|
1887
|
-
generate_serialize_container(out,
|
|
1888
|
-
type,
|
|
1889
|
-
prefix + tfield->get_name());
|
|
1890
|
-
} else if (type->is_base_type() || type->is_enum()) {
|
|
1891
|
-
|
|
1892
|
-
string name = prefix + tfield->get_name();
|
|
1893
|
-
|
|
1894
|
-
if (binary_inline_) {
|
|
1895
|
-
if (type->is_base_type()) {
|
|
1896
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
1897
|
-
switch (tbase) {
|
|
1898
|
-
case t_base_type::TYPE_VOID:
|
|
1899
|
-
throw
|
|
1900
|
-
"compiler error: cannot serialize void field in a struct: " + name;
|
|
1901
|
-
break;
|
|
1902
|
-
case t_base_type::TYPE_STRING:
|
|
1903
|
-
out <<
|
|
1904
|
-
indent() << "$output .= pack('N', strlen($" << name << "));" << endl <<
|
|
1905
|
-
indent() << "$output .= $" << name << ";" << endl;
|
|
1906
|
-
break;
|
|
1907
|
-
case t_base_type::TYPE_BOOL:
|
|
1908
|
-
out <<
|
|
1909
|
-
indent() << "$output .= pack('c', $" << name << " ? 1 : 0);" << endl;
|
|
1910
|
-
break;
|
|
1911
|
-
case t_base_type::TYPE_BYTE:
|
|
1912
|
-
out <<
|
|
1913
|
-
indent() << "$output .= pack('c', $" << name << ");" << endl;
|
|
1914
|
-
break;
|
|
1915
|
-
case t_base_type::TYPE_I16:
|
|
1916
|
-
out <<
|
|
1917
|
-
indent() << "$output .= pack('n', $" << name << ");" << endl;
|
|
1918
|
-
break;
|
|
1919
|
-
case t_base_type::TYPE_I32:
|
|
1920
|
-
out <<
|
|
1921
|
-
indent() << "$output .= pack('N', $" << name << ");" << endl;
|
|
1922
|
-
break;
|
|
1923
|
-
case t_base_type::TYPE_I64:
|
|
1924
|
-
out <<
|
|
1925
|
-
indent() << "$output .= pack('N2', $" << name << " >> 32, $" << name << " & 0xFFFFFFFF);" << endl;
|
|
1926
|
-
break;
|
|
1927
|
-
case t_base_type::TYPE_DOUBLE:
|
|
1928
|
-
out <<
|
|
1929
|
-
indent() << "$output .= strrev(pack('d', $" << name << "));" << endl;
|
|
1930
|
-
break;
|
|
1931
|
-
default:
|
|
1932
|
-
throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase);
|
|
1933
|
-
}
|
|
1934
|
-
} else if (type->is_enum()) {
|
|
1935
|
-
out <<
|
|
1936
|
-
indent() << "$output .= pack('N', $" << name << ");" << endl;
|
|
1937
|
-
}
|
|
1938
|
-
} else {
|
|
1939
|
-
|
|
1940
|
-
indent(out) <<
|
|
1941
|
-
"$xfer += $output->";
|
|
1942
|
-
|
|
1943
|
-
if (type->is_base_type()) {
|
|
1944
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
1945
|
-
switch (tbase) {
|
|
1946
|
-
case t_base_type::TYPE_VOID:
|
|
1947
|
-
throw
|
|
1948
|
-
"compiler error: cannot serialize void field in a struct: " + name;
|
|
1949
|
-
break;
|
|
1950
|
-
case t_base_type::TYPE_STRING:
|
|
1951
|
-
out << "writeString($" << name << ");";
|
|
1952
|
-
break;
|
|
1953
|
-
case t_base_type::TYPE_BOOL:
|
|
1954
|
-
out << "writeBool($" << name << ");";
|
|
1955
|
-
break;
|
|
1956
|
-
case t_base_type::TYPE_BYTE:
|
|
1957
|
-
out << "writeByte($" << name << ");";
|
|
1958
|
-
break;
|
|
1959
|
-
case t_base_type::TYPE_I16:
|
|
1960
|
-
out << "writeI16($" << name << ");";
|
|
1961
|
-
break;
|
|
1962
|
-
case t_base_type::TYPE_I32:
|
|
1963
|
-
out << "writeI32($" << name << ");";
|
|
1964
|
-
break;
|
|
1965
|
-
case t_base_type::TYPE_I64:
|
|
1966
|
-
out << "writeI64($" << name << ");";
|
|
1967
|
-
break;
|
|
1968
|
-
case t_base_type::TYPE_DOUBLE:
|
|
1969
|
-
out << "writeDouble($" << name << ");";
|
|
1970
|
-
break;
|
|
1971
|
-
default:
|
|
1972
|
-
throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase);
|
|
1973
|
-
}
|
|
1974
|
-
} else if (type->is_enum()) {
|
|
1975
|
-
out << "writeI32($" << name << ");";
|
|
1976
|
-
}
|
|
1977
|
-
out << endl;
|
|
1978
|
-
}
|
|
1979
|
-
} else {
|
|
1980
|
-
printf("DO NOT KNOW HOW TO SERIALIZE FIELD '%s%s' TYPE '%s'\n",
|
|
1981
|
-
prefix.c_str(),
|
|
1982
|
-
tfield->get_name().c_str(),
|
|
1983
|
-
type->get_name().c_str());
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
/**
|
|
1988
|
-
* Serializes all the members of a struct.
|
|
1989
|
-
*
|
|
1990
|
-
* @param tstruct The struct to serialize
|
|
1991
|
-
* @param prefix String prefix to attach to all fields
|
|
1992
|
-
*/
|
|
1993
|
-
void t_php_generator::generate_serialize_struct(ofstream &out,
|
|
1994
|
-
t_struct* tstruct,
|
|
1995
|
-
string prefix) {
|
|
1996
|
-
indent(out) <<
|
|
1997
|
-
"$xfer += $" << prefix << "->write($output);" << endl;
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
/**
|
|
2001
|
-
* Writes out a container
|
|
2002
|
-
*/
|
|
2003
|
-
void t_php_generator::generate_serialize_container(ofstream &out,
|
|
2004
|
-
t_type* ttype,
|
|
2005
|
-
string prefix) {
|
|
2006
|
-
scope_up(out);
|
|
2007
|
-
|
|
2008
|
-
if (ttype->is_map()) {
|
|
2009
|
-
if (binary_inline_) {
|
|
2010
|
-
out <<
|
|
2011
|
-
indent() << "$output .= pack('c', " << type_to_enum(((t_map*)ttype)->get_key_type()) << ");" << endl <<
|
|
2012
|
-
indent() << "$output .= pack('c', " << type_to_enum(((t_map*)ttype)->get_val_type()) << ");" << endl <<
|
|
2013
|
-
indent() << "$output .= strrev(pack('l', count($" << prefix << ")));" << endl;
|
|
2014
|
-
} else {
|
|
2015
|
-
indent(out) <<
|
|
2016
|
-
"$output->writeMapBegin(" <<
|
|
2017
|
-
type_to_enum(((t_map*)ttype)->get_key_type()) << ", " <<
|
|
2018
|
-
type_to_enum(((t_map*)ttype)->get_val_type()) << ", " <<
|
|
2019
|
-
"count($" << prefix << "));" << endl;
|
|
2020
|
-
}
|
|
2021
|
-
} else if (ttype->is_set()) {
|
|
2022
|
-
if (binary_inline_) {
|
|
2023
|
-
out <<
|
|
2024
|
-
indent() << "$output .= pack('c', " << type_to_enum(((t_set*)ttype)->get_elem_type()) << ");" << endl <<
|
|
2025
|
-
indent() << "$output .= strrev(pack('l', count($" << prefix << ")));" << endl;
|
|
2026
|
-
|
|
2027
|
-
} else {
|
|
2028
|
-
indent(out) <<
|
|
2029
|
-
"$output->writeSetBegin(" <<
|
|
2030
|
-
type_to_enum(((t_set*)ttype)->get_elem_type()) << ", " <<
|
|
2031
|
-
"count($" << prefix << "));" << endl;
|
|
2032
|
-
}
|
|
2033
|
-
} else if (ttype->is_list()) {
|
|
2034
|
-
if (binary_inline_) {
|
|
2035
|
-
out <<
|
|
2036
|
-
indent() << "$output .= pack('c', " << type_to_enum(((t_list*)ttype)->get_elem_type()) << ");" << endl <<
|
|
2037
|
-
indent() << "$output .= strrev(pack('l', count($" << prefix << ")));" << endl;
|
|
2038
|
-
|
|
2039
|
-
} else {
|
|
2040
|
-
indent(out) <<
|
|
2041
|
-
"$output->writeListBegin(" <<
|
|
2042
|
-
type_to_enum(((t_list*)ttype)->get_elem_type()) << ", " <<
|
|
2043
|
-
"count($" << prefix << "));" << endl;
|
|
2044
|
-
}
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
scope_up(out);
|
|
2048
|
-
|
|
2049
|
-
if (ttype->is_map()) {
|
|
2050
|
-
string kiter = tmp("kiter");
|
|
2051
|
-
string viter = tmp("viter");
|
|
2052
|
-
indent(out) <<
|
|
2053
|
-
"foreach ($" << prefix << " as " <<
|
|
2054
|
-
"$" << kiter << " => $" << viter << ")" << endl;
|
|
2055
|
-
scope_up(out);
|
|
2056
|
-
generate_serialize_map_element(out, (t_map*)ttype, kiter, viter);
|
|
2057
|
-
scope_down(out);
|
|
2058
|
-
} else if (ttype->is_set()) {
|
|
2059
|
-
string iter = tmp("iter");
|
|
2060
|
-
indent(out) <<
|
|
2061
|
-
"foreach ($" << prefix << " as $" << iter << " => $true)" << endl;
|
|
2062
|
-
scope_up(out);
|
|
2063
|
-
generate_serialize_set_element(out, (t_set*)ttype, iter);
|
|
2064
|
-
scope_down(out);
|
|
2065
|
-
} else if (ttype->is_list()) {
|
|
2066
|
-
string iter = tmp("iter");
|
|
2067
|
-
indent(out) <<
|
|
2068
|
-
"foreach ($" << prefix << " as $" << iter << ")" << endl;
|
|
2069
|
-
scope_up(out);
|
|
2070
|
-
generate_serialize_list_element(out, (t_list*)ttype, iter);
|
|
2071
|
-
scope_down(out);
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
scope_down(out);
|
|
2075
|
-
|
|
2076
|
-
if (!binary_inline_) {
|
|
2077
|
-
if (ttype->is_map()) {
|
|
2078
|
-
indent(out) <<
|
|
2079
|
-
"$output->writeMapEnd();" << endl;
|
|
2080
|
-
} else if (ttype->is_set()) {
|
|
2081
|
-
indent(out) <<
|
|
2082
|
-
"$output->writeSetEnd();" << endl;
|
|
2083
|
-
} else if (ttype->is_list()) {
|
|
2084
|
-
indent(out) <<
|
|
2085
|
-
"$output->writeListEnd();" << endl;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
scope_down(out);
|
|
2090
|
-
}
|
|
2091
|
-
|
|
2092
|
-
/**
|
|
2093
|
-
* Serializes the members of a map.
|
|
2094
|
-
*
|
|
2095
|
-
*/
|
|
2096
|
-
void t_php_generator::generate_serialize_map_element(ofstream &out,
|
|
2097
|
-
t_map* tmap,
|
|
2098
|
-
string kiter,
|
|
2099
|
-
string viter) {
|
|
2100
|
-
t_field kfield(tmap->get_key_type(), kiter);
|
|
2101
|
-
generate_serialize_field(out, &kfield, "");
|
|
2102
|
-
|
|
2103
|
-
t_field vfield(tmap->get_val_type(), viter);
|
|
2104
|
-
generate_serialize_field(out, &vfield, "");
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
/**
|
|
2108
|
-
* Serializes the members of a set.
|
|
2109
|
-
*/
|
|
2110
|
-
void t_php_generator::generate_serialize_set_element(ofstream &out,
|
|
2111
|
-
t_set* tset,
|
|
2112
|
-
string iter) {
|
|
2113
|
-
t_field efield(tset->get_elem_type(), iter);
|
|
2114
|
-
generate_serialize_field(out, &efield, "");
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
/**
|
|
2118
|
-
* Serializes the members of a list.
|
|
2119
|
-
*/
|
|
2120
|
-
void t_php_generator::generate_serialize_list_element(ofstream &out,
|
|
2121
|
-
t_list* tlist,
|
|
2122
|
-
string iter) {
|
|
2123
|
-
t_field efield(tlist->get_elem_type(), iter);
|
|
2124
|
-
generate_serialize_field(out, &efield, "");
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
/**
|
|
2128
|
-
* Declares a field, which may include initialization as necessary.
|
|
2129
|
-
*
|
|
2130
|
-
* @param ttype The type
|
|
2131
|
-
*/
|
|
2132
|
-
string t_php_generator::declare_field(t_field* tfield, bool init, bool obj) {
|
|
2133
|
-
string result = "$" + tfield->get_name();
|
|
2134
|
-
if (init) {
|
|
2135
|
-
t_type* type = get_true_type(tfield->get_type());
|
|
2136
|
-
if (type->is_base_type()) {
|
|
2137
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
2138
|
-
switch (tbase) {
|
|
2139
|
-
case t_base_type::TYPE_VOID:
|
|
2140
|
-
break;
|
|
2141
|
-
case t_base_type::TYPE_STRING:
|
|
2142
|
-
result += " = ''";
|
|
2143
|
-
break;
|
|
2144
|
-
case t_base_type::TYPE_BOOL:
|
|
2145
|
-
result += " = false";
|
|
2146
|
-
break;
|
|
2147
|
-
case t_base_type::TYPE_BYTE:
|
|
2148
|
-
case t_base_type::TYPE_I16:
|
|
2149
|
-
case t_base_type::TYPE_I32:
|
|
2150
|
-
case t_base_type::TYPE_I64:
|
|
2151
|
-
result += " = 0";
|
|
2152
|
-
break;
|
|
2153
|
-
case t_base_type::TYPE_DOUBLE:
|
|
2154
|
-
result += " = 0.0";
|
|
2155
|
-
break;
|
|
2156
|
-
default:
|
|
2157
|
-
throw "compiler error: no PHP initializer for base type " + t_base_type::t_base_name(tbase);
|
|
2158
|
-
}
|
|
2159
|
-
} else if (type->is_enum()) {
|
|
2160
|
-
result += " = 0";
|
|
2161
|
-
} else if (type->is_container()) {
|
|
2162
|
-
result += " = array()";
|
|
2163
|
-
} else if (type->is_struct() || type->is_xception()) {
|
|
2164
|
-
if (obj) {
|
|
2165
|
-
result += " = new " + php_namespace(type->get_program()) + type->get_name() + "()";
|
|
2166
|
-
} else {
|
|
2167
|
-
result += " = null";
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
return result + ";";
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
|
-
/**
|
|
2175
|
-
* Renders a function signature of the form 'type name(args)'
|
|
2176
|
-
*
|
|
2177
|
-
* @param tfunction Function definition
|
|
2178
|
-
* @return String of rendered function definition
|
|
2179
|
-
*/
|
|
2180
|
-
string t_php_generator::function_signature(t_function* tfunction,
|
|
2181
|
-
string prefix) {
|
|
2182
|
-
return
|
|
2183
|
-
prefix + tfunction->get_name() +
|
|
2184
|
-
"(" + argument_list(tfunction->get_arglist()) + ")";
|
|
2185
|
-
}
|
|
2186
|
-
|
|
2187
|
-
/**
|
|
2188
|
-
* Renders a field list
|
|
2189
|
-
*/
|
|
2190
|
-
string t_php_generator::argument_list(t_struct* tstruct) {
|
|
2191
|
-
string result = "";
|
|
2192
|
-
|
|
2193
|
-
const vector<t_field*>& fields = tstruct->get_members();
|
|
2194
|
-
vector<t_field*>::const_iterator f_iter;
|
|
2195
|
-
bool first = true;
|
|
2196
|
-
for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
|
|
2197
|
-
if (first) {
|
|
2198
|
-
first = false;
|
|
2199
|
-
} else {
|
|
2200
|
-
result += ", ";
|
|
2201
|
-
}
|
|
2202
|
-
result += "$" + (*f_iter)->get_name();
|
|
2203
|
-
}
|
|
2204
|
-
return result;
|
|
2205
|
-
}
|
|
2206
|
-
|
|
2207
|
-
/**
|
|
2208
|
-
* Gets a typecast string for a particular type.
|
|
2209
|
-
*/
|
|
2210
|
-
string t_php_generator::type_to_cast(t_type* type) {
|
|
2211
|
-
if (type->is_base_type()) {
|
|
2212
|
-
t_base_type* btype = (t_base_type*)type;
|
|
2213
|
-
switch (btype->get_base()) {
|
|
2214
|
-
case t_base_type::TYPE_BOOL:
|
|
2215
|
-
return "(bool)";
|
|
2216
|
-
case t_base_type::TYPE_BYTE:
|
|
2217
|
-
case t_base_type::TYPE_I16:
|
|
2218
|
-
case t_base_type::TYPE_I32:
|
|
2219
|
-
case t_base_type::TYPE_I64:
|
|
2220
|
-
return "(int)";
|
|
2221
|
-
case t_base_type::TYPE_DOUBLE:
|
|
2222
|
-
return "(double)";
|
|
2223
|
-
case t_base_type::TYPE_STRING:
|
|
2224
|
-
return "(string)";
|
|
2225
|
-
default:
|
|
2226
|
-
return "";
|
|
2227
|
-
}
|
|
2228
|
-
} else if (type->is_enum()) {
|
|
2229
|
-
return "(int)";
|
|
2230
|
-
}
|
|
2231
|
-
return "";
|
|
2232
|
-
}
|
|
2233
|
-
|
|
2234
|
-
/**
|
|
2235
|
-
* Converts the parse type to a C++ enum string for the given type.
|
|
2236
|
-
*/
|
|
2237
|
-
string t_php_generator ::type_to_enum(t_type* type) {
|
|
2238
|
-
type = get_true_type(type);
|
|
2239
|
-
|
|
2240
|
-
if (type->is_base_type()) {
|
|
2241
|
-
t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
|
|
2242
|
-
switch (tbase) {
|
|
2243
|
-
case t_base_type::TYPE_VOID:
|
|
2244
|
-
throw "NO T_VOID CONSTRUCT";
|
|
2245
|
-
case t_base_type::TYPE_STRING:
|
|
2246
|
-
return "TType::STRING";
|
|
2247
|
-
case t_base_type::TYPE_BOOL:
|
|
2248
|
-
return "TType::BOOL";
|
|
2249
|
-
case t_base_type::TYPE_BYTE:
|
|
2250
|
-
return "TType::BYTE";
|
|
2251
|
-
case t_base_type::TYPE_I16:
|
|
2252
|
-
return "TType::I16";
|
|
2253
|
-
case t_base_type::TYPE_I32:
|
|
2254
|
-
return "TType::I32";
|
|
2255
|
-
case t_base_type::TYPE_I64:
|
|
2256
|
-
return "TType::I64";
|
|
2257
|
-
case t_base_type::TYPE_DOUBLE:
|
|
2258
|
-
return "TType::DOUBLE";
|
|
2259
|
-
}
|
|
2260
|
-
} else if (type->is_enum()) {
|
|
2261
|
-
return "TType::I32";
|
|
2262
|
-
} else if (type->is_struct() || type->is_xception()) {
|
|
2263
|
-
return "TType::STRUCT";
|
|
2264
|
-
} else if (type->is_map()) {
|
|
2265
|
-
return "TType::MAP";
|
|
2266
|
-
} else if (type->is_set()) {
|
|
2267
|
-
return "TType::SET";
|
|
2268
|
-
} else if (type->is_list()) {
|
|
2269
|
-
return "TType::LST";
|
|
2270
|
-
}
|
|
2271
|
-
|
|
2272
|
-
throw "INVALID TYPE IN type_to_enum: " + type->get_name();
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
THRIFT_REGISTER_GENERATOR(php, "PHP",
|
|
2276
|
-
" inlined: Generate PHP inlined files\n"
|
|
2277
|
-
" server: Generate PHP server stubs\n"
|
|
2278
|
-
" autoload: Generate PHP with autoload\n"
|
|
2279
|
-
" oop: Generate PHP with object oriented subclasses\n"
|
|
2280
|
-
" rest: Generate PHP REST processors\n"
|
|
2281
|
-
);
|