Ability to read and write namespaced properties should be added to MidgardObject. As proposed in MidgardCR API: http://www.midgard-project.org/api-docs/midgard/core/unstable/midgard3/MidgardCR/MidgardCR.RepositoryObject.html.
should resolve the problem.
This indeed solves the problem, but using those methods is a bit clunky. At least binding-level "magic" methods should be provided, so $object->ns_name also works.
Other alternative is to use "sub-objects" for namespaces, like we do now with the metadata object. So then it'd be $object->ns->name.
Though it should be noted that these ideas only work with the namespace prefix (ns), not the full URI version.
The second approach is better as it could fit to every GIR "bindings". Adding magic to PHP bindings is fine, but no forward compatible.
I like it. So properties in http://www.midgard-project.org/repligard/1.4 are direct properties of the object itself, and properties in other namespaces are accessed via subobject.
<Schema xmlns="http://www.midgard-project.org/repligard/1.4" xmlns:my="http://example.net/myschema/">
Is accessible via:
$object = new \my\article();
$object->title = 'My title';
$object->my->foo = 'Bar';
Using our existing conventions with Metadata object has the additional benefit that compatibility of "namespaced" properties is already solved with query building and views. For example, in a view:
<property name="foo" use="my.article:my.foo">
(we should probably also reverse the usage of . and : here, so it would actually be use="my:article.my:foo", just like use="midgard_attachment.name")
In practice, almost every application and developer uses namespaces instead of full URIs (or IRIs). For those, repository have to provide namespaceManager. Such is also proposed in MidgardCR API:
Finally I think we should provide two solutions. Languages which do not allow to use variable as property name, one would call get_property_value().
Full URI/IRI support is important mainly for data exporters and importers, for example when Midgard Create needs to store RDF entities.
One issue we need to consider: If A->ns is the same as B->ns, then both ns objects should have the same properties as they are instance of the same class. I also wonder if it makes sense to create GObject request feature so properties setter and getter could be more virtual.
Tried to register properties with ':' and '_' and GObject transparently replaces these characters with dash.
is registered as foaf-person.
This approach could be used as convention, however we do not know if it's going to be supported by GLib forever. Second issue is that you can not access property as obj.foaf-person as language parser might throw syntax error.
So, if we could follow obj->ns->propertyname approach, we should be introspection safe, and provide nicer OOP.
Though, it's very important to remeber that 'ns' property (and its properties) might be dynamic and thus not introspectable directly. But proposed API wrappers (self get_property_value, etc) will resolve the problem.
From Tim Janik:
"Similar to C over C++, properties can be namespaced simply by convention. E.g. always prefix all property names with "foo-", like: foo-label, foo-visible, etc. "
So this convention works with any Midgard version.
On some languages properties with the ns-property convention will be a problem, but that can probably be handler on bindings level.
With GIR you are not able to access properties directly, as every mgdschema type is not static. Object.get(name) or Object.get_property(name) should be used always, so ns-property convention seems to be safe.
At this moment 'ns-name' convention seems to be safest.