Home  Support Page  The Manual  Advanced topics

Property types

Each ORM-related entity (aka a persistent object) may have properties of various types.

An entity property type abstraction is the key concept of Phoebius ORM layer. It provides mapping between entity property (a class or a native value) and the database cells.

You may define a property type that maps the objects of any complexity, either a primitive or a composite type, or even a reference to other entity.

Right now there are several types you may assigned as property mapper.

Primitive types represent native PHP values. They are treated as fundamental and thus used as the base for other property types. All these types are defined by the DBType class constants. To use them just set the value of the constant you need to use:

$app/var/domain.xml

...
<property name="id" type="uint32" />
<property name="text" type="varchar" size="255" />
<property name="cost" type="currency" precision="12" scale="9" />
...
Primitive types may be set with the predefined attributes that will be passed to the property handler:
  • size attribute defines the size of the type; it may be applied to varchar, char and binary primitive types
  • precision and scale attributes may be applied to currency, decimal and float types

Types can handle boxable primitives. This covers case when the native PHP value should be wrapped by the class which exposes various helper methods to handle the type. To do this, you may specify the class which implements IOrmPropertyAssignable or IBoxable interfaces. The first one provides a worker that is responsible for mapping the primitive; the second one provides an interface for explicit mapping. Date class is the good example.

To use boxable primitve just set the name of the class as a property type - code generator would smartly resolve the actual property type handler:

$app/var/domain.xml

...
<property name="created" type="Date" />
...
This would be translated to BoxablePropertyType.

Other entities may be the types too. In this case a one-tone association is build

You may implement your own types easily. All you need is to implement OrmPropertyType, provide a public constructor and set the name of the type in the definition:

class MyPropertyType extends OrmPropertyType 
{
	function __construct($typeParam1, $typeParam2){}
	
	... implementation of OrmPropertyType follows
}
<property name="myCustomProperty" type="MyPropertyType">
	<param name="typeParam1" value="1">
	<param name="typeParam2" value="2">
</property>