Skip to content
jeanphilippe-p edited this page Aug 13, 2016 · 31 revisions

Table of content

  1. How it works ?
  2. Model class
  3. Simple Model
  4. Complex Model
  5. Container Model
  6. InstanceModel class
  7. Object class
  8. Extends from Object
  9. Code Example

How it works ?

[Comhon!] () has two main concepts to understand : object and model.

  • An Object contain values and a model
  • Values is a map of values [a_property_name => a_value]
  • A Model contain properties
  • A property has a name and a type
  • A type can be (string, boolean, another model ...)

In other words map of values replace class attributes and model properties replace attributes types.

Model class

Simple Model

list of simple model managed :

  • boolean
  • dateTime
  • float
  • integer
  • string

Complex Model

A complex model is described by a manifest (please take a look at [Manifest] () page). It contain a map of properties and each property has it own model

Container Model

Model can associate a container to a property name and this container will contain the "real" model.

For exemple you have a model Person and you want to have a property sex and this property can have only 2 values : male or female (enumeration). So your property sex will have a container ModelEnum that contain a model String.

Properties can have three kind of container :

  • ModelForeign (property is a reference to another object)
  • ModelEnum (enumeration)
  • ModelArray (array)

InstanceModel class

Instanciating models has a cost (due to manifest loading) so we need to instanciate them only one time. The singleton InstanceModel manage all models instances so we don't have to know if model is already instanciated or not.

Object class

Like we said before, an Object contain a Model so when you instanciate an Object you have to indicate it's model.

$Object = new Object('a_model_name')

To access value you have to call getter getValue('property_name').

To set a value you have to call setter setValue('property_name', a_value).

Extends from Object

if you want to associate a class to you object you can define it in your manifest. Your class must extends from Object class

class Person Extends Object {
  public function getName() {
    return $this->getValue('name');
  }
  
  public function setAge($age) {
    $this->setValue('age', $age);
  }
}

Code Example

// first way to instanciate an object
$personModel = InstanceModel::getInstance()->getInstanceModel('person');
$person = $personModel->getObjectInstance();
// getObjectInstance() return instance of Object or class that you have defined in your manifest

// second way to instanciate an object
$person = new Object('person');

// set object values
$person->setValue('age', 21);
$person->setValue('foo', 'bar'); // will not work because person doesn't have property 'foo'

// get an object value
$age = $person->getValue('age');

Clone this wiki locally