GObject for PHP (new bindings project)
Today, my brain refused to recall details of mercurial commands and I moved GObject for PHP project to github.
I didn't mention this project on blog, but that is only because I wasn't blogging much lately.
It's been in the news, that PHP-GTK aois being split up into different projects, PECL/Cairo, GLib, GObject, etcao, but there were not many details on these changes. It's time to fill the gap.
I was working on aoGObjecta part from the list. Our idea is to get rid of legacy code, target php 5.3+ and build highly modular system, which would be easy to extend and maintain.
This new PHP extension is called aoGObject for PHPa, so, my main concern, obviously is building comfortable bridge between GObject objects and PHP's objects. It starts to work, but there's a lot of stuff to be done. Please join the project, if you are interested. We need more hands! Anyway, here's what is done:
I started my implementation with aomastera branch. I see it as a common ground for various specific php extensions wrapping gobject libraries. For example, Mark Skilbeck implemented libnotify binding this way. Eventually, new generation of GTK+ bindings could be implemented in similar fashion.
At the moment I have PHP counterparts of the following parts of GObject world:
- GType - implemented as GObject\Type. This is the scaffolding, which is used for creating new classes in runtime.
- GParamSpec - implemented as GObject\ParamSpec. These describe properties and are assigned to GObject\Type.
- GObject - implemented as GObject\Object. Base class for all specific classes in GObject hierarchy.
- GSignal - implemented as GObject\Signal. Signal's are definitions of event slots. Whenever you define new GObject class (using GType) you can specify which event slots it will have, how those events should be handled and, after that, during runtime, trigger events.
So, it's easy. Define classes, properties, signal slots. Create objects, set properties, emit signals. GObject-for-php takes care of event marshalling, conversion of parameters, etc.
After the code above started to work, I branched the code to give another concept a try. These days, a lot of effort in GNOME community goes into GObject Introspection project. They idea is, that bindings developers spend too much time by manually tweaking bindings to every change in C libraries. That's what PHP-GTK team had to do, for example.
Here's quotation from project's web site:
The introspection project solves this by putting all of the metadata inside the GObject library itself, using annotations in the comments. This will lead to less duplicate work from binding authors, and a more reliable experience for binding consumers. Additionally, because the introspection build process will occur inside the GObject libraries themselves, a goal is to encourage GObject authors to consider shaping their APIs to be more binding friendly from the start, rather than as an afterthought.
So, aointrospectiona branch aims to provide bindings for GObject Introspection infrastructure. The main entry point is GIRepository\load_ns(aNamespace') function, which creates php-counterparts of all classes, functions, constants of corresponding GObject namespace dynamically. At least, it will do that one day. With your help