Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MgdSchema object should support namespaced properties #107

Closed
piotras opened this issue Jul 1, 2011 · 11 comments
Closed

MgdSchema object should support namespaced properties #107

piotras opened this issue Jul 1, 2011 · 11 comments

Comments

@piotras
Copy link
Member

piotras commented Jul 1, 2011

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.

Methods like:

read_property_value(ns:name)
write_property_value(ns:name, value)

should resolve the problem.

@bergie
Copy link
Member

bergie commented Jul 1, 2011

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.

@piotras
Copy link
Member Author

piotras commented Jul 1, 2011

The second approach is better as it could fit to every GIR "bindings". Adding magic to PHP bindings is fine, but no forward compatible.

@bergie
Copy link
Member

bergie commented Jul 1, 2011

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.

So:

<Schema xmlns="http://www.midgard-project.org/repligard/1.4" xmlns:my="http://example.net/myschema/">
    <type name="my:article">
        <property name="title">
        <property name="my:foo">
        ....

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")

@piotras
Copy link
Member Author

piotras commented Jul 1, 2011

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:

http://www.midgard-project.org/api-docs/midgard/core/unstable/midgard3/MidgardCR/MidgardCR.RDFSQLNamespaceManager.html

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().

@bergie
Copy link
Member

bergie commented Jul 1, 2011

Full URI/IRI support is important mainly for data exporters and importers, for example when Midgard Create needs to store RDF entities.

@piotras
Copy link
Member Author

piotras commented Jul 2, 2011

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.

@piotras
Copy link
Member Author

piotras commented Jul 3, 2011

Tried to register properties with ':' and '_' and GObject transparently replaces these characters with dash.

<property name="foaf:person">

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.

@piotras
Copy link
Member Author

piotras commented Jul 4, 2011

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.

@bergie
Copy link
Member

bergie commented Jul 4, 2011

On some languages properties with the ns-property convention will be a problem, but that can probably be handler on bindings level.

@piotras
Copy link
Member Author

piotras commented Jul 4, 2011

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.

@piotras
Copy link
Member Author

piotras commented Sep 2, 2011

At this moment 'ns-name' convention seems to be safest.

@piotras piotras closed this as completed Sep 2, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants