PHP code example of treehouselabs / model-config

1. Go to this page and download the library: Download treehouselabs/model-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

treehouselabs / model-config example snippets



# Project\Model\Article

class House
{
    protected $type;
}


# Project\Model\Config\Field\HouseType

use TreeHouse\Model\Config\Field\Enum;

class HouseType extends Enum
{
    const HOUSE     = 1;
    const APARTMENT = 2;
    const OTHER     = 3;
}

$house = new House();
$house->setType(HouseType::APARTMENT);


# Project\Model\Config\Field\Facilities

use TreeHouse\Model\Config\Field\Enum;

class Facilities extends Enum
{
    const ELEVATOR        = 1;
    const ALARM           = 2;
    const AIRCONDITIONING = 3;
    const ROLLER_BLINDS   = 4;

    protected static $multiValued = true;
}

$builder = new ConfigBuilder();
$builder->addField('type', HouseType::class);
$builder->addField('facilities', Facilities::class);

$config = $builder->getConfig();

$config->isMultiValued('facilities'); // true
$config->hasFieldConfig('foo'); // false
$config->hasFieldConfigKey('type', 2); // true
$config->hasFieldConfigValue('type', 'apartment'); // true
$config->getFieldConfigValueByKey('type', 2); // 'apartment'
$config->getFieldConfigKey('type', 'apartment'); // 2