Most soundbars have an HDMI 'passthrough', so you'd connect the PS4 to the soundbar via HDMI, then HDMI from the soundbar to the TV.
That'll get you sound from your PS4, but it's a lot of messing around with HDMI cables to revert back to Apple TV or cable etc....
I assume an HDMI hub would work:
PS4/AppleTV/Cable etc to hub via HDMI
hub to soundbar via HDMI
soundbar to TV via HDMI
That would eliminate the need to switch cables as you go.....although also negating optical output. Everything would be passed over HDMI and should be controllable at the hub level to determine which device is 'primary' at any given time.