Self-similar magnetohydrodynamic solution for the dynamics of magnetic flux emergence