Skip to content
comhon-project edited this page Sep 21, 2020 · 14 revisions

Table of content

  1. Preamble
  2. Get configurations
  3. Example
  4. List
  5. Extends configuration

Preamble

Comhon! allow you to set some configurations. They must be stored in a json file. By default Comhon! will search the file config.json in folder where you have launched your script.

But you may configure where configuration file must be searched. To do so, in your entrypoint script just add following lines :

use Comhon\Object\Config\Config;

// must be called before any Comhon functions
Config::setLoadPath('my/absolute/or/relative/path/to/my_config.json');

Warning!! Configuration file is required and an exception will be thrown if file is not found.

Get configurations

There is a singleton that store configuartions so they are accessible anywhere.

use Comhon\Object\Config\Config;

$config = Config::getInstance();

Config is an instance of Comhon object so you must call getValue to get a specific configuration.

$format = Config::getInstance()->getValue('manifest_format');
echo $format // output 'xml' for example

Example

Configuration file looks like :

{
  "manifest_format": "json",
  "autoload": {
    "manifest":{
      "Test":"../manifests/test/manifest"
    },
    "serialization":{
      "Test":"../manifests/test/serialization"
    },
    "options":{
      "Test":"../manifests/test/options"
    }
  },
  "request_collection_limit":20,
  "regex_list":"./regex.json",
  "sql_table": "./table",
  "sql_database": "./database",
  "date_time_format": "c",
  "database": {
    "charset": "utf8",
    "timezone": "UTC"
  }
}

List

We will explain one by one each available configurations. But before we have to explain configurations that describe a path. Each path may be absolute or relative. A path is considered as relative only if path begin with a . (or ..). A relative path is relative to configuration file.

manifest_format

Define in wich format you have defined your Manifests, Serialization and Options. Allowed format are json and xml (default json)

autoload

Define namespaces prefixes and path where Manifests, Serialization and Options must be found. See Manifests, Serialization and Options pages for more informations.

request_collection_limit

Default limit that is applied when requesting objects collection with complex requester in public context. This limit may be overridden for each model.

regex_list

Define path where regex list file must be found. Actually you may define some regex to validate values (see pattern).

sql_table

Define path to directory that contain all your sql tables informations. By default Comhon! will look into folder named table in folder where your script is launched.

sql_database

Define path to directory that contain all your sql databases informations. By default Comhon! will look into folder named database in folder where your script is launched.

date_time_format

Define default date time format to use when import/export datetimes values (default 'c' that is ISO 8601).

database

Define some informations to configure database connection :

  • charset
  • timezone

Extends configuration

Comhon allow you to extends configuration with your own model to set specific configurations. To do so, you must define a manifest to describe your configurations. Your manifest MUST extends from Comhon\Config.

Manifest Example

{
    "version": "3.0",
    "name": "My\\Namespace\\Config",
    "extends": [
        "\\Comhon\\Config"
    ],
    "properties": [
        {
            "name": "my_conf_1",
            "inheritance-": "Comhon\\Manifest\\Property\\String"
        },
        {
            "name": "my_conf_2",
            "inheritance-": "Comhon\\Manifest\\Property\\String"
        }
    ]
}

Configuration Example

{
  "manifest_format": "json",
  "autoload": {
    "manifest":{
      "My":"../manifests/my/manifest"
    }
  },
  "my_conf_1": "my_value_1",
  "my_conf_2": "my_value_2",
  "inheritance-": "My\\Namespace\\Config"
}

Don't forget to :

  • put the namespace prefix of your configuration model
  • put inheritance- key, otherwise it will be loaded as classic Comhon\Config

Clone this wiki locally