From the Ehlers-Pirani-Schild analysis on the foundations of gravitational theories to extended theories of gravity and dark matter