private function matchValue(array $value) { $isCalled = false; foreach ($this->patterns as $key => $pattern) { list($object, $method) = $this->flow[$key]; if (empty($pattern)) { $value = $object->{$method}($value); $isCalled = true; break; } else { try { $this->mapper->match($pattern, [$value]); } catch (\Exception $e) { $isCalled = false; continue; } $mappedValue = $this->mapper->current(); if (!is_null($mappedValue)) { $isCalled = true; $value = $object->{$method}($value); break; } } } if (!$isCalled) { throw new NoMatch(); } return $value; }
public function testNested() { $pattern = ['id' => 0, 'value' => ['title' => '', 'tags' => []]]; $data = [['id' => 11, 'value' => 'foo'], ['id' => '1', 'value' => 'bar'], ['id' => 13, 'value' => ['title' => 'bar', 'tags' => [1, 2, 3]]], ['id' => 13, 'value' => ['id' => 0, 'value' => 'foo']]]; $matching = new Pattern(); $matching->match($pattern, $data); $this->assertEquals($matching->current(), ['id' => 13, 'value' => ['title' => 'bar', 'tags' => [1, 2, 3]]]); $this->assertEquals(1, iterator_count($matching)); }