Midgard Reflection Property once again
Posted on 2006-03-27 17:33:27 EEST.
Why there's MidgardReflectionProperty when we had
MidgardObjectProperty?
Reflection used in class name better describes what this class
is designed for.
It's somehow usual now ( I know, one would say 'I do not
believe!' ) that we have reflection property class documented
already in
midgard-core and in
midgard-php documentation.
As always midgard-php part of reflection property was the worst
part.
I needed to change this :
$mrp = new midgard_reflection_property();
echo $mrp->description("midgard_article", "sitegroup"));
to:
$mrp = new midgard_reflection_property("midgard_article");
echo $mrp->description("sitegroup"));
A well known "big deal" is a possibility to fetch GObject
instance while using php object. At first I decided to use
Zend's resources ( sorry , I do not provide any url to zend
sites ). But the problem with Zend resources is the fact that
resources' id (very internal feature IMO) is available on zend
and php level. As there is no possibility to set own private
pointer as a member of zend object , one is forced to add
resource's id as object's property.
Now think about 200 php object instances and 200 integers, it's
easy to change object's resource's property value from 199 to
10 ( for example ) and get something very unexpected.
And now think about objects which use some ACL features in
"critical mission" environment and possibility to change any
resource id...
Let me quote:
"Watch, but do not touch. Touch, but do not taste".
I think this sentence from "The Devil's Advocate"
describes perfectly the sense of resource handlers.
I spent some time on reading php-gtk sources. (It's a good way
to "kill" your time anyway when you work with Zend. Read plenty
of source code and try to understand it.) I thought that I
could find some good way to make a good wrapper and use 1:1,
php and gobject objects.
No way. This extension uses 0 property as resources handler for
gtk object. What happens if I change value 1 ( let's say some
window object ) to 2 ( let's say some other widget object)? I
expect bad things.
At the end I decided to write very easy objects "collection". A
collection which holds 1:1 references for zend ( php in this
case ) and gobject objects. The idea is very simple. I use two
data types: GHashTable and GSList.
The first one is a collection of zend objects' pointers
assigned as hash keys , and gobject ones assigned as values. If
HashTable is initialized with NULL compare functions then
direct equal ( pointers ) one is used.
The second one is used as collection of pointers to any gobject
which was initialized during particular request. So at the end
of the request , it's enough to iterate over list and free all
objects memory. Plain and simple.
The only problem I can see is zend object pointer which can be
"overwritten" during some loop. What really happens with this
pointer then? If You know, or you just found zend docs about
this, feel free to tell me ;)