public function testSet_WhenNotArray_MustReplace() { $arr = ['a' => ['b' => 'c']]; $da = new DotArray($arr); $da->set('a.b.c', 'X'); $this->assertSame(['a' => ['b' => ['c' => 'X']]], $da->getArray()); }
private function askForCustomOptionArray($currentValue, Option $option) { $da = new DotArray($currentValue); $this->stdio->outln($option->getPath()); $this->stdio->outln($option->getDescription()); $continue = true; while ($continue) { $this->stdio->displayList($da->flatten()); $actions = ['delete', 'clear all', 'add', 'replace', 'skip']; $action = $this->stdio->chooseAction($actions); switch ($action) { case 'delete': $index = $this->stdio->chooseFromList($da->flatten(), 'Item to delete', false); if ($index !== null) { $da->remove($index); } break; case 'clear all': $da = new DotArray(); break; case 'add': $newValue = $this->stdio->ask('Enter value of the new item'); $da = new DotArray(array_merge($da->getArray(), [$newValue])); break; case 'replace': $index = $this->stdio->chooseFromList($da->flatten(), 'Item to replace', false); if ($index !== null) { $da->set($index, $this->stdio->ask('Enter new value')); } break; case 'skip': $continue = false; break; } } $this->frontmatter->set($option->getPath(), $da->getArray()); }