i think there is even a util in doctrine common for this, but i may be wrong