Component Writer's Guide :: Object Properties

From RadPHP XE2 Documentation
Jump to: navigation, search

In RPCL, properties stored in a resource file are initially strings, so when they are loaded, they need to be fixed up to find the right reference to the object.

The process of fixation consists in searching the object that is named like the value of the property, and to do that, there is a method on Component called fixupProperty:

  protected function writeImages($value)  
  { 
    $this->_images = $this->fixupProperty($value); 
  }

Images is a property that links to an ImageList component, and when setting the property, we set the internal value for it as the result of calling the fixupProperty method.

If $value is a string, we will search for a valid object named as $value, if found, will be returned, if not, a string will be returned and we must find another time to fixup.

By another time, we mean the loaded() method, for example, when the XML resource file is read from disk, the property is stored as a string and writeImages is called with a string $value, but at that time, it's likely that the referring object has not been created yet, so that's why we need to override loaded(), and add an extra line there, because in loaded(), all objects can be found:

function loaded()
{
  parent::loaded();
  $this->writeImages($this->_images);
}

What we are doing here is to set the property again, to ensure the value is going to be the valid object reference.

Personal tools