I was looking to do the same and found this . The creator explains how this works, and there is a github repository if you want to use its code in your application.
This works fine for me, as it looks like the implementation of the Zend Framework that I have already used in the past.
source share