some symfony code partially refactored for slimfony