THRIFT-5979: Add native method types to PHP Server and Factory classes#3459
Merged
Conversation
ff4555e to
f633f23
Compare
Client: php Migrate the public methods on lib/php/lib/Server/ and lib/php/lib/Factory/ from PHPDoc @param/@return annotations to native parameter and return types. The Server abstractions and the protocol/transport factories are isolated subtrees -- they reference TTransport/TProtocol only via composition, so adding native types here does not cascade out to the Transport or Protocol hierarchies (separate sub-tickets). Server: * TServer::serve() / stop() typed void. * TSimpleServer / TForkingServer match the new abstract signatures and drop the now-dead `if ($transport != null)` guards after accept(), which is non-nullable. * TForkingServer's protected helpers (handleParent, handleChild, collectChildren) typed. * TServerTransport::listen() / close() / acceptImpl() / accept() typed; accept() now returns TTransport (was already that semantically -- it throws on null), acceptImpl() returns ?TTransport, the null check switched to strict ===. * TServerSocket overrides typed; acceptImpl() returns ?TSocket. * TSSLServerSocket::listen() typed; acceptImpl() returns ?TSSLSocket. Factory: * TProtocolFactory interface typed: getProtocol(TTransport): TProtocol. * TBinaryProtocolFactory / TCompactProtocolFactory / TJSONProtocolFactory match with covariant concrete return types. * TTransportFactoryInterface typed: getTransport(TTransport): TTransport. * TTransportFactory / TFramedTransportFactory match with covariant return types where appropriate. * New TBinaryProtocolAcceleratedFactory closes the long-standing gap where TBinaryProtocolAccelerated had no library-provided factory -- the cross-test harness had to hand-roll one in test/php/TestServer.php. The ad-hoc class is dropped in favor of the library one. The new factory defaults strictWrite=true to match the protocol's own ctor default, distinguishing it from TBinaryProtocolFactory. Test fixtures (latent issues surfaced by typed signatures): * ServerStub::serve/stop now typed void. * ServerTransportStub uses constructor property promotion with ?TTransport and matches abstract acceptImpl(): ?TTransport. * TSimpleServerTest had stubs of the wrong class for the factories (TServerTransport where TTransport/TProtocol was expected); fixed. * TForkingServerTest mocks had accept() returning null to simulate "no connection", which violated the now-typed TTransport return. Replaced with throwing TTransportException, which is what real accept() does on null and what the serve() loop already catches. * TBinaryProtocolAcceleratedFactoryTest covers the new factory. Generated-by: Claude Opus 4.7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrates the public methods on
lib/php/lib/Server/andlib/php/lib/Factory/from PHPDoc@param/@returnannotations to native parameter and return types, plus closes a long-standing factory gap that surfaced during cross-test debugging.The Server abstractions and the protocol/transport factories are isolated subtrees — they reference
TTransport/TProtocolonly via composition, so adding native types here does not cascade out to the Transport or Protocol hierarchies (separate sub-tickets).Server
TServer::serve()/stop()typedvoid.TSimpleServer/TForkingServermatch the new abstract signatures, and drop the now-deadif ($transport != null)guards afteraccept(), which is non-nullable.TForkingServer's protected helpers (handleParent,handleChild,collectChildren) typed.TServerTransport::listen()/close()/acceptImpl()/accept()typed;accept()now returnsTTransport(it was already that semantically — it throws on null),acceptImpl()returns?TTransport, the null check switched to strict===.TServerSocketoverrides typed;acceptImpl()returns?TSocket.TSSLServerSocket::listen()typed;acceptImpl()returns?TSSLSocket.Factory
TProtocolFactoryinterface typed:getProtocol(TTransport): TProtocol.TBinaryProtocolFactory/TCompactProtocolFactory/TJSONProtocolFactorymatch with covariant concrete return types.TTransportFactoryInterfacetyped:getTransport(TTransport): TTransport.TTransportFactory/TFramedTransportFactorymatch with covariant return types where appropriate.TBinaryProtocolAcceleratedFactorycloses the long-standing gap whereTBinaryProtocolAcceleratedhad no library-provided factory — the cross-test harness had to hand-roll one intest/php/TestServer.php. The ad-hoc class is dropped in favor of the library one. The new factory defaultsstrictWrite=trueto match the protocol's own constructor default, distinguishing it fromTBinaryProtocolFactory.Test fixtures (latent issues surfaced by typed signatures)
ServerStub::serve/stopnow typedvoid.ServerTransportStubuses constructor property promotion with?TTransportand matches abstractacceptImpl(): ?TTransport.TSimpleServerTesthad stubs of the wrong class for the factories (TServerTransportwhereTTransport/TProtocolwas expected); fixed.TForkingServerTestmocks hadaccept()returningnullto simulate "no connection", which violated the now-typedTTransportreturn. Replaced with throwingTTransportException, which is what realaccept()does on null and what theserve()loop already catches.TBinaryProtocolAcceleratedFactoryTestcovers the new factory (7 tests).Part of THRIFT-5960 — modernizing PHP runtime library typing. Builds on the property typing (THRIFT-5976), constructor promotion (THRIFT-5977), and
declare(strict_types=1)(THRIFT-5978).TBinaryProtocolAcceleratedFactoryis purely additive.[skip ci]anywhere in the commit message to free up build resources. — N/A (code change)Generated-by: Claude Opus 4.7