Пример #1
0
 private function checkFilterUsage()
 {
     // -------------------------------------------------------------------------------------------------------------
     // --- white list should have @ least 1 key
     // -------------------------------------------------------------------------------------------------------------
     //      TODO add potential list here as well
     if (!isset($this->listWhite) && !isset($this->listBlack) && !isset($this->listPotential)) {
         throw new RuntimeException("Set a white/black list before start filtering!");
     }
     $resultRaw = $this->obj->getArray();
     if (isset($this->listWhite)) {
         foreach ($this->listWhite as $resultKey) {
             if (!isset($resultRaw[$resultKey])) {
                 throw new InvalidArgumentException("{$resultKey} - is an invalid key. Check your white list!");
             }
             $this->result[$resultKey] = $resultRaw[$resultKey];
         }
     }
     if (isset($this->listPotential)) {
         foreach ($this->listPotential as $resultKey) {
             !isset($resultRaw[$resultKey]) ?: ($this->result[$resultKey] = $resultRaw[$resultKey]);
         }
     }
     if (isset($this->listBlack)) {
         foreach ($this->listBlack as $resultKey) {
             if (!isset($resultRaw[$resultKey])) {
                 throw new InvalidArgumentException("{$resultKey} - is an invalid key. Check your black list!");
             }
             $this->obj->remove($resultKey);
         }
         $this->result = $this->obj->getArray();
     }
 }
Пример #2
0
 public function testValuesAssoc()
 {
     $exaKeys = ['hm', 'bar', 'bar', 'foo', 'foo', 'foo', 'baz', 'baz', 'baz', 'baz', 'baz'];
     $exaValues = ['valHm', 'valBar', 'valBar2', 'valFoo', 'valFoo2', 'valFoo3', 'valBaz', 'valBaz2', 'valBaz3', 'valBaz4', 'valBaz5'];
     $combiner = new Combiner(new Key($exaKeys), new Value($exaValues));
     $this->assertEquals(['hm' => 'valHm', 'bar' => 'valBar', 'bar2' => 'valBar2', 'foo' => 'valFoo', 'foo2' => 'valFoo2', 'foo3' => 'valFoo3', 'baz' => 'valBaz', 'baz2' => 'valBaz2', 'baz3' => 'valBaz3', 'baz4' => 'valBaz4', 'baz5' => 'valBaz5'], $combiner->getArray());
     $this->assertEquals('valBaz3', $combiner->getTwin('baz', '^valBaz3$'));
     $this->assertEquals(['hm' => 'valHm', 'bar' => 'valBar', 'bar2' => 'valBar2', 'foo' => 'valFoo', 'foo2' => 'valFoo2', 'foo3' => 'valFoo3', 'baz' => 'valBaz3'], $combiner->replace('baz', $combiner->getTwin('baz', '^valBaz3$'))->getArray());
     $this->assertEquals(['hm' => 'valHm', 'bar' => 'valBar2', 'foo' => 'valFoo3', 'baz' => 'valBaz4'], $combiner->replace('bar', $combiner->getTwin('bar', '^valBar2$'))->replace('foo', $combiner->getTwin('foo', '^valFoo3$'))->replace('baz', $combiner->getTwin('baz', '^valBaz4$'))->getArray());
 }