-
Notifications
You must be signed in to change notification settings - Fork 0
Manifest
- [Manifest list] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/Manifest#manifest-list)
- [Manifest description] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/Manifest#manifest-description)
- [Manifest Person example] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/Manifest#manifest-person-example)
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] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/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.
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.
There are two kind of properties : property and foreign property.
- A property has a name and a type
- A Foreign property (defined by the node
<foreignProperty>in XML format or with the keyis_foreignin JSON format) has a name, a type, and refer another Object that has an existence elsewhere. For example, modelPersoncan have a foreign propertymother. A random person 'John' has a mother 'Jane' and 'Jane' can exist without 'John'.
<manifest>
<properties>
<property type="string">firstName</property>
<foreignProperty type="person">mother</foreignProperty>
</properties>
</manifest>{
"properties": {
"firstName": {
"type": "string"
},
"mother": {
"type": "person",
"is_foreign": true
}
}
}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 attribut id with value "1" in XML format or add a key is_id with value true in JSON format (foreign properties can not be id).
<manifest>
<properties>
<property type="string" id="1">id</property>
</properties>
</manifest>{
"properties": {
"id": {
"type": "string",
"is_id": true
}
}
}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</name>
<enum>
<value>male</value>
<value>female</value>
</enum>
</property>
</properties>
</manifest>{
"properties": {
"sex": {
"type": "string",
"enum": [
"male",
"female"
]
}
}
}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</name>
<values type="string" name="middleName"/>
</property>
</properties>
</manifest>{
"properties": {
"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>
<foreignProperty type="array">
<name>children</name>
<values type="person" name="child"/>
</foreignProperty>
</properties>
</manifest>{
"properties": {
"children": {
"type": "array",
"values": {
"type": "person",
"name": "child"
},
"is_foreign": true
}
}
}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 XML 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 id="tatoo">
<properties>
<property type="string">type</property>
<property type="string">bodyPart</property>
<foreignProperty type="person">tatooArtist</foreignProperty>
</properties>
</type>
<!-- a local property type can contain another one -->
<type id="example">
<properties>
<property type="tatoo">tatoo</property>
<property type="string">thing</property>
</properties>
</type>
</types>
<properties>
<property type="array">
<name>tatoos</name>
<values type="tatoo" name="tatoo"/>
</property>
<property type="example">example</property>
</properties>
</manifest>{
"types": {
"tatoo": {
"properties": {
"type": {"type": "string"},
"bodyPart": {"type": "string"},
"tatooArtist": {"type": "person", "is_foreign": true}
}
}
},
"properties": {
"tatoos": {
"values": {
"type": "tatoo",
"name": "tatoo"
},
"type": "array"
}
}
}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)
- disadvantages :
- open manifest file to load local model when needed (one time by local model)
<manifest>
<manifests>
<localThing>relative/path/to/local/manifest.xml</localThing>
<localAnotherThing>relative/path/to/another/local/manifest.xml</localAnotherThing>
</manifests>
<properties>
<property type="localThing">thing</property>
<property type="localAnotherThing">anotherThing</property>
</properties>
</manifest>{
"manifests": {
"localThing": "relative/path/to/local/manifest.xml",
"localAnotherThing": "relative/path/to/another/local/manifest.xml"
},
"properties": {
"thing": {
"type": "localThing"
},
"anotherThing": {
"type": "localAnotherThing"
}
}
}if you want to associate a class to your manifest you can define it in the attribut 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] (https://github.com/jeanphilippe-p/ObjectManagerLib/wiki/Getting-started) page to know how to define a class object and how to instanciate it.
<manifest>
<types>
<type id="tatoo">
<properties>
<property type="string">type</property>
<property type="string">bodyPart</property>
<foreignProperty type="person">tatooArtist</foreignProperty>
</properties>
</type>
</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
}
}
}