Skip to content
comhon-project edited this page Aug 5, 2017 · 57 revisions

Table of Contents

  1. Manifest list
  2. Manifest description
  3. Manifest Person example

Manifest list

The list of all your manifests must be referenced in an XML or JSON file. The path to this file must be defined in the file config.json with the key manifestList (see Installation page for more informations).

If you decide to define your manifest list in XML format, your file must have "xml" extention and content must look like :

<manifests>
    <person>relative/path/to/person/manifest.xml</person>
    <house>relative/path/to/house/manifest.xml</house>
    <town>relative/path/to/town/manifest.xml</town>
</manifests>

If you decide to define your manifest list in JSON format, your file must have "json" extention and content must look like :

{
	"person"     : "relative/path/to/person/manifest.json",
	"house"      : "relative/path/to/house/manifest.json",
	"town"       : "relative/path/to/town/manifest.json"
}

As you can see the list permit to associate a name to a manifest path. Each name is unique and each manifest path must have "xml" or "json" extention. Finaly the manifest path must be relative to the folder that contain manifest list file.

Manifest description

A Manifest permit to describe a concept by listing its properties. Manifests can be defined in XML or JSON format. for each example we will illustrate XML and JSON format.

<manifest>
    <properties>
        ...
    </properties>
</manifest>
{
    "properties": []
}

for the following explanations we will build a manifest Person like example.

Basic property

A property has a name and a type

<manifest>
    <properties>
        <property type="string" name="firstName"/>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "firstName",
            "type": "string"
        }
    ]
}

Id property

We want an id to find easily a person, so we need to add an id property.
An id property is a part of a model id. Commonly models have only one id property but you can define several id properties.
To define a property as id property, you just have to add an attribute is_id (id must be a float, integer or string).

<manifest>
    <properties>
        <property type="string" name="id" is_id="1"/>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "id",
            "type": "string",
            "is_id": true
        }
    ]
}

Foreign property

A Foreign property is a property that contain the key is_foreign, it refers another Object that has an existence elsewhere. For example, model Person can have a foreign property mother. A random person 'John' has a mother 'Jane' and 'Jane' can exist without 'John'.

<manifest>
    <properties>
        <property type="string" name="\mother" is_foreign="1"/>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "mother",
            "type": "\\person",
            "is_foreign": true
        }
    ]
}

(we will explain later why there is backslash in type value)

Enumeration property

We want to have a property sex and this property can have only 2 values : male or female. So we must define an enumeration. (enumeration type must be a simple model)

<manifest>
    <properties>
        <property type="string" name="sex">
            <enum>
                <value>male</value>
                <value>female</value>
            </enum>
        </property>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "sex",
            "type": "string",
            "enum": [
                "male",
                "female"
            ]
        }
    ]
}

Array property

We want to have a property middleNames. actually a person can have a second name, third name... so we can define an array property to store these names.

<manifest>
    <properties>
        <property type="array" name="middleNames">
            <values type="string" name="middleName"/>
        </property>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "middleNames",
            "type": "array",
            "values": {
                "type": "string",
                "name": "middleName"
            }
        }
    ]
}

Now we want to have a property children, and a child is a person that can exists elsewhere so we can build a foreign property array.

<manifest>
    <properties>
        <property type="array" name="children" is_foreign="true">
            <values type="\person" name="child"/>
        </property>
    </properties>
</manifest>
{
    "properties": [
        {
            "name": "children",
            "type": "array",
            "values": {
                "type": "\\person",
                "name": "child"
            },
            "is_foreign": true
        }
    ]
}

Local property type

We want to add a property tatoos. A tatoo is not a simple thing, we must define a model to define it. But where define this model ? In file that reference manifest list ? no because a tatoo exists only on Person body (on domestic animal too but to simply we ignore it). So we define a local property type. By the way we could define a manifest tatoo in manifest list, but it's more efficient and more understandable to define a local property type.

<manifest>
    <types>
        <type name="tatoo">
            <properties>
                <property type="string" name="type"/>
                <property type="string" name="location"/>
                <property type="\person" name="tatooArtist" is_foreign="1"/>
            </properties>
	</type>
        <!-- a local property type can contain another one -->
        <type name="example">
            <properties>
                <property type="tatoo" name="tatoo"/>
                <property type="string" name="a_name"/>
            </properties>
        </type>
    </types>

    <properties>
        <property type="array" name="tatoos">
            <values type="tatoo" name="tatoo"/>
        </property>
        <property type="example">example</property>
    </properties>
</manifest>
{
    "types": [
        {
            "name": "tatoo",
            "properties": [
                {
                    "name": "type",
                    "type": "string"
                },
                {
                    "name": "location",
                    "type": "string"
                },
                {
                    "name": "tatooArtist",
                    "type": "\\person",
                    "is_foreign": true
                }
            ]
        }
    ],
    "properties": [
        {
            "name": "tatoos",
            "type": "array",
            "values": {
                "type": "tatoo",
                "name": "tatoo"
            }
        }
    ]
}

If you have a large number of complex local models and they are not always used, you can define them in others manifests files.

advantages :

  • simplify the current manifest
  • load local model only if needed (saving time when load current manifest)
<manifest>
    <manifests>
        <localThing>relative/path/to/local/manifest.xml</localThing>
        <localAnotherThing>relative/path/to/another/local/manifest.xml</localAnotherThing>
    </manifests>

    <properties>
        <property type="localThing" name="thing"/>
        <property type="localAnotherThing" name="anotherThing"/>
    </properties>
</manifest>
{
    "manifests": {
        "localThing": "relative/path/to/local/manifest.xml",
        "localAnotherThing": "relative/path/to/another/local/manifest.xml"
    },
    "properties": [
        {
            "name": "thing",
            "type": "localThing"
        },
        {
            "name": "anotherThing",
            "type": "localAnotherThing"
        }
    ]
}

Associate a class object

if you want to associate a class to your manifest you can define it in the attribute object. The class must contain namespace.

<manifest object="Class\With\Name\Space\A_Class">
    <types/>
    <manifests/>
    <properties/>
</manifest>
{
    "object": "Class\\With\\Name\\Space\\A_Class",
}

Take a look at Getting started page to know how to define a class object and how to instanciate it.

Manifest Person example

<manifest>
    <types>
        <tatoo>
            <properties>
                <property type="string">type</property>
                <property type="string">bodyPart</property>
                <foreignProperty type="person">tatooArtist</foreignProperty>
            </properties>
        </tatoo>
    </types>
    <manifests/>
    <properties>
        <property type="string" id="1">id</property>
        <property type="string">firstName</property>
        <property type="string">lastName</property>
        <property type="integer">age</property>
        <foreignProperty type="place">birthPlace</foreignProperty>
        <property type="string">
            <name>sex</name>
            <enum>
                <value>male</value>
                <value>female</value>
            </enum>
        </property>
        <property type="array">
            <name>tatoos</name>
            <values type="tatoo" name="tatoo"/>
        </property>
        <foreignProperty type="person">father</foreignProperty>
        <foreignProperty type="person">mother</foreignProperty>
        <foreignProperty type="array">
            <name>children</name>
            <values type="person" name="child"/>
        </foreignProperty>
        <foreignProperty type="array">
            <name>homes</name>
            <values type="home" name="home"/>
        </foreignProperty>
    </properties>
</manifest>
{
	"manifests": {},
	"types": {
		"tatoo": {
			"properties": {
				"type": {"type": "string"},
				"bodyPart": {"type": "string"},
				"tatooArtist": {"type": "person", "is_foreign": true}
			}
		}
	},
	"properties": {
		"id": {
			"type": "string",
			"is_id": true
		},
		"firstName": {"type": "string"},
		"lastName": {"type": "string"},
		"age": {"type": "integer"},
		"birthPlace": {
			"type": "place",
			"is_foreign": true
		},
		"sex": {
			"enum": [
				"male",
				"female"
			],
			"type": "string"
		},
		"tatoos": {
			"values": {
				"type": "tatoo",
				"name": "tatoo"
			},
			"type": "array"
		},
		"father": {"type": "person", "is_foreign": true},
		"mother": {"type": "person", "is_foreign": true},
		"children": {
			"values": {
				"type": "person",
				"name": "child"
			},
			"type": "array",
			"is_foreign": true
		},
		"homes": {
			"values": {
				"type": "home",
				"name": "home"
			},
			"type": "array",
			"is_foreign": true
		}
	}
}

Clone this wiki locally