Refactor the PHP part of the Lua library

Also introduce a new non-legacy style which will be made
use of in a following commit.

This commit includes code previously written by Jens Ohlig.

Change-Id: I1d0f139d3e29bac6a1893e856e8d196ca3b02608
Merge "Refactor the PHP part of the Lua library"