Exemplo n.º 1
0
 public function testOrderWithoutCutAndShortSequence()
 {
     $actual = new ArrayOk(array('luke' => 'jedi', 'vader' => 'sith', 'yoda' => 'master'));
     $sequence = array('yoda', 'luke');
     $expected = array('yoda' => 'master', 'luke' => 'jedi', 'vader' => 'sith');
     $actual->order($sequence, false);
     $this->assertSame($expected, $actual->items);
 }
Exemplo n.º 2
0
 /**
  * Merges all of the arrays found in the defaults configuration in the order defined by the context 
  *
  * @param ArrayOk $sequence
  * @param ArrayOk $config
  * @access protected
  * @return array
  */
 protected function mergeDefaults(ArrayOk $sequence, ArrayOk $config)
 {
     $toMerge = array();
     foreach ($sequence->toArray() as $context) {
         if ($config->exists($context)) {
             $toMerge[] = $config[$context]->toArray();
         }
     }
     return empty($toMerge) ?: call_user_func_array('array_merge', $toMerge);
 }
Exemplo n.º 3
0
<?php

require 'vendor/autoload.php';
use Jlem\ArrayOk\Proxy;
use Jlem\ArrayOk\ArrayOk;
$initial = ['slapp' => ['sith' => ['vader', 'sidious'], 'jedi' => ['luke'], 'special' => ['hi' => 'there'], 'asdfasdf' => 'dkdkdkd'], 'wat' => 'k?'];
$test = new ArrayOk($initial);
$what = $test->get();
var_dump($what);
$thing = new ArrayOk($what);
var_dump($thing);
Exemplo n.º 4
0
 /**
  * Checks to see if the given context matches any of the current conditions
  * 
  * @param  ArrayOk $Context
  * @return bool
  */
 public function matchesContext(ArrayOk $Context)
 {
     if (empty($this->conditions)) {
         return false;
     }
     foreach ($this->conditions as $key => $value) {
         // Bug out if the key isn't even set
         if (!$Context->exists($key)) {
             return false;
         }
         // Bug out if the key is set, but the value doesn't match
         if (!preg_match("#{$Context[$key]}#", $value)) {
             return false;
         }
     }
     return true;
 }