Pop quiz, without looking: at which battle did the supremacy of the phalanx meet its end, and what were the reasons for its demise?
Here is a straight answer with no quibbling that I am prepared to argue, that also stays entirely within the classical period. The traditional Greek Hoplite phalanx was first decisively defeated at the Battle of Chaeronea in 338 B.C. by Philip the Great of Macedon. The main reason for it's defeat was the Macedonian use of the Sarissa instead of the traditional Hoplite spear.
Neither cavalry nor ranged/light infantry could break a phalanx. Both could nip at it and wear it down but the point of phalangeal combat was to make battle quick and decisive, neither cavalry or light infantry could be decisive when fighting Hoplites formed in battle array. Except for a short interregnum during the middle ages heavy infantry as been THE decisive combat arm for almost all of recorded history. Cavalry has never been able to break an infantry formation. Anyone with riding experience can tell you that horses will not run at or into an immovable object such as that presented by formed infantry, they have to be tricked into doing it.
Didn't Longstreet do this at the Battle of Chickamauga? I know ultimately Thomas prevented the total rout, but didn't he use cavalry to crush the Union flank and collapse their lines? Or did he do it with his infantry and merely assisted by his cavalry?
Longstreet exploited a gap the Union created in their lines while maneuvering and did not have to break any infantry formations, the Union did that for him. You are correct in that his infantry played the main part. Cavalry is an exploitation and pursuit force against infantry. It is much easier to kill your opponent when he is running away, that is why the loser always suffers higher casualties if his forces rout and the winner has the reserves available for pursuit or did not exhaust their main army too much in achieving the victory. Even today victory is determined by possesses the field after a battle, no mater how large or small.