\NLComponent
NLComponent is the base class for all objects that can appear in an NLView. This holds common behaviour of all components, and includes a factory method for constructing an NLComponent hierarchy given a raw object representation.
The serialised form of a component tree is represented as a json expression. e.g.:
{
"ClassName": "NLVerticalBoxLayout",
"children": [
{ "ClassName": "NLTextComponent", "Text": "Some text" }
],
"bindings": {
"myproperty": {}
},
"layout": {
(layout properties defined by the layout manager/parent)
}
}
There is a relationship between properties and bindings. Properties are defined per class.
Thoughts on field definition and binding:
- each property has a name, and specifies the class name of a DBField-derivative.
- binding is performed on demand.
- the binding process iterates over the defined properties, and creates an instance of the datatype
specified for that property. It calculates the value by examining the bound value. It evaluates that within
the context, and assigns it to the value property of the field object in the binding.
- then rendering takes place.
- there needs to be a syntax in the serialised NLComponent for the binding. Probably an object that defines
the place where the value comes from.
- bindings are assumed to be bidirectional, so that a user may edit a component and expect the value to be saved
back to the context.
- some bindings may be unidirectional (readony). The context will define this in its metadata.
- the context object may provide a getViewMetadata() method, which will return a map containing what can be
bound to. It would be great if this metadata is expressed in terms also of SS data types, so for example nested
objects can be returned.
- there needs to be a way for a component to bind to values that are stored directly in the component. This will need
to have very robust serialisation as it may include rich text.
Synopsis
- // members
- protected $children = NULL;
- protected $rawBindings = NULL;
- protected $bindings = NULL;
- protected $bindingValues = NULL;
- protected $layoutValues = NULL;
- protected $view $view;
- private $_metadata = NULL;
- // methods
- public static void factory()
- public static array get_metadata()
- public void getMetadataValue()
- public void getMetadata()
- protected void getProperties()
- protected map getBindingDefinitions()
- public ViewableData getBindingValues()
- public getLayoutValues()
- public string render()
- public void getChildren()
- public abstract string renderContent()
- protected array containerClasses()
- public void maxChildren()
Hierarchy
Extends
- ViewableData
Members
private
- $_metadata
protected
- $bindingValues
—
null
This maps properties to actual values to be rendered. - $bindings
—
null
This holds the binding definitions that are stored in the component. i.e. it identifies the source of values per property, but not the actual value. - $children
—
null
If the component type supports child components, they are represented in an array here. - $layoutValues
—
null
An object that holds the layout properties for the component. It is initialised in the constructor from the raw object passed in. - $rawBindings
- $view
—
$view
A reference to the view object.
Methods
protected
- containerClasses() — This function can be overridden by subclasses to provide additional CSS classes to add to the component's containment markup. Generally treated as additive, if a subclass overrides this, it should also add the classes of the parent. The classes are made unique before being rendered.
- getBindingDefinitions() — Return the binding definitions, mapping properties to where they get values from. This comes from the raw bindings, and is processed on demand and stored into $this->bindings.
- getProperties() — Shorthand form of getting properties, which comes from metadata structure.
public
- factory() — Given an NLComponent object hierarchy, generate the actual NLComponent instances. The object passed in is an object structure that is a deserialised json object, so the objects are untyped. We use the ClassName property in each to determine the actual type. Bindings are done lazily; the component only interprets the binding definitions in $object later if it needs to.
- getBindingValues()
- getChildren()
- getLayoutValues() — Return the layout values. These are stored in the serialised object, and managed by the parent. This is a raw object that can have any properties set by the layout manager. If there is no layout object defined, a new stdClass object is returned, so the call doesn't have to check if its null or not.
- getMetadata() — Return the metadata array, which is derived from get_metadata but includes inheriting properties from the parent.
- getMetadataValue()
- get_metadata() — Return a map of metadata properties about this component type. Every component class should define this method. Not all properties need to be defined for each component type. getMetadataCombined can be used to get metadata values, with properties inherited up the component hierarchy.
- maxChildren() — Return the maximum number of children allowed for this type of component. Subclasses can override it.
- render() — render() generates the HTML for the component, including generic containment. Generally subclasses shouldn't override this, but will override renderContent. The parent component (typically layout components) can provide extra properties that affect the containment.
- renderContent() — renderContent generates the HTML that goes inside the generic component containment. Subclasses need to override this.