Example #1
0
<?php

require './vendor/autoload.php';
use Jlem\Context\Filters\CommonFilter;
use Jlem\Context\Filters\DefaultsFilter;
use Jlem\Context\Filters\ConditionFilter;
use Jlem\Context\Filters\Condition;
use Jlem\Context\Config;
use Jlem\ArrayOk\ArrayOk;
$config = ['common' => ['show_tuner_truck_module' => true, 'date_format' => 'M j, Y', 'comment_query_criteria' => 'Acme\\Comment\\Criteria\\Member', 'show_comment_ip' => false, 'some_vals' => ['one', 'two', 'three']], 'defaults' => ['UK' => ['date_format' => 'j M, Y', 'show_comment_ip' => false, 'some_vals' => ['five']], 'Honda' => ['show_tuner_truck_module' => false], 'Admin' => ['comment_query_criteria' => 'Acme\\Comment\\Criteria\\Admin', 'show_comment_ip' => true], 'Moderator' => ['comment_query_criteria' => 'Acme\\Comment\\Criteria\\Moderator']], 'conditions' => ['admin_uk' => new Condition(['country' => 'UK', 'user' => 'Admin'], ['show_tuner_truck_module' => 'admin_uk']), 'ford_uk' => new Condition(['country' => 'UK', 'manufacturer' => 'Ford'], ['show_tuner_truck_module' => 'ford_uk'])]];
$context = ['user' => 'Admin', 'country' => 'UK', 'manufacturer' => 'Ford'];
$Config = new Config($context);
$Config->addFilter('common', new CommonFilter($config));
$Config->addFilter('defaults', new DefaultsFilter($config));
$Config->addFilter('conditions', new ConditionFilter($config));
// In request process
$results = $Config->load();
var_dump($results);
Example #2
0
 public function testMergeReplacesNumericIndexesAsValues()
 {
     $config = array('common' => array('some_vals' => ['one', 'two', 'three']), 'defaults' => array('UK' => array('some_vals' => ['five']), 'Admin' => array('comment_query_criteria' => 'Acme\\Comment\\Criteria\\Admin')), 'conditions' => array('admin_uk' => new Condition(array('country' => 'UK', 'user' => 'Admin'), array('some_vals' => ['six'])), 'ford_uk' => new Condition(array('country' => 'UK', 'manufacturer' => 'Ford'), array('some_vals' => ['seven']))));
     $context = array('user' => 'Admin', 'country' => 'UK', 'manufacturer' => 'Ford');
     $Config = new Config($context);
     $Config->addFilter('common', new CommonFilter($config));
     $Config->addFilter('defaults', new DefaultsFilter($config));
     $Config->addFilter('conditions', new ConditionFilter($config));
     $actual = $Config->load()->toArray();
     $expected = array('some_vals' => ['seven'], 'comment_query_criteria' => 'Acme\\Comment\\Criteria\\Admin');
     $this->assertEquals($expected, $actual);
 }