Interface WFKeyValueObserving

Description

At present, we don't implement full, real-time KVO. In the web world, I didn't think we needed it, as you can just pull the data right when you need it.

Also, because we cannot modify the runtime environment like Cocoa does, it makes it hard for direct accessor calls to trigger change events since we have no easy way to detect the calls to setKey($value) and propagate the changes to the observers.

So instead, we have a simpler paradigm of SETTING UP the bindings at config time, then loading the values from the FORM onto their objects based on bindings (via pushBindings()). For the other direction, pullBindings() is called by the observer just before it wants to use bound values.

While the implementation of pullBindings() in WFWidget is all that's needed to pull bound properties into the objects, for pushBindings(), it's a little more complicated. Only each widget knows WHICH of its bound properties even should be pushed back. For instance, likely the "value" properties will be pushed back, but attributes like size, maxLength, etc. would not be pushed back to the bound object. Additionally, the WFWidgets do some additional magic such as performing validation and maintaining error lists for each widget. Thus, each widget should implement pushBindings() and for each binding that should have its value propagated back to the bound object, it should use the propagateValueToBinding() of the WFWidget subclass to help with this.

The only method subclasses are likely to need to overload is processBindingOptions.

Located in /framework/WFBinding.php (line 28)


	
			
Method Summary
void processBindingOptions (string $boundProperty, assoc_array $options, reference &$boundValue)
void pullBindings ()
void pushBindings ()
Methods
processBindingOptions (line 63)

This is essentially a callback that allows subclasses to munge the bound value based on bindings options.

The default implementation in WFWidget has no bindings. This is a method many subclasses will overload.

All subclasses should call the super method first, like so:

parent::processBindingOptions($boundProperty, $options, $boundValue); // make changes to the boundValue as appropriate for the current property.

void processBindingOptions (string $boundProperty, assoc_array $options, reference &$boundValue)
  • string $boundProperty: The name of the bound property being processed.
  • assoc_array $options: The binding options for this binding. These values have already been coalesced with the default values manifested in setupExposedBindings.
  • reference &$boundValue: A reference to the bound value, so that you can change it based on options as needed.
pullBindings (line 38)

Update the values of all bound properties for the object.

Goes through each property, applying the value transformers and giving subclasses a chance to munge values based on bindings options.

The default implementation of this function (presently in WFWidget) should be sufficient.

void pullBindings ()
pushBindings (line 47)

Update the values of all objects bound via bindings.

This is the mechanism that is used to "push" the values from the bound properties BACK to their originators to keep changes in sync.

The default implementation of this function (presently in WFWidget) should be sufficient.

void pushBindings ()

Documentation generated on Thu, 17 Apr 2008 13:51:33 -0400 by phpDocumentor 1.4.1