  We report the construction of a passive, deterministic and
near-unity-fidelity controlled-$\pi$-phase gate for single-photon wavepackets
with a node comprising a two-level emitter and a small number of cavities. The
proposed gate is rooted in the concept of time-reversal symmetric photon
transport, which makes the entire photon transport process into a perfect
absorption and re-emission process. Consequently, it can circumvent the
longstanding issue of wavepacket distortion inherent in photonic phase gates
employing nonlinear media. Moreover, such time-reversal symmetric transport
ensures the nonlinear $\pi$ phase shift by a single two-level emitter for the
two-photon case. We develop analytical solutions to reveal the temporal
dynamics of the nonlinear photon transport and to optimize the gate structure.
Notably, the gate fidelity can exceed 99\% for a node with only four cavities
for both single-photon and two-photon operations. Moreover, the proposed gate
architecture is compatible with the platforms of integrated photonics.
