/** * Recursively drop back to the parents menu style * when the current menu has a parent and has no changes * * @return MenuStyle */ private function getMenuStyle() { if (null === $this->parent) { return $this->buildStyle(); } if ($this->style !== MenuStyle::getDefaultStyleValues()) { return $this->buildStyle(); } return $this->parent->getMenuStyle(); }
/** * Recursively drop back to the parents menu style * when the current menu has a parent and has no changes * * @return MenuStyle */ private function getMenuStyle() { $diff = array_udiff_assoc($this->style, $this->getStyleClassDefaults(), function ($current, $default) { if ($current instanceof TerminalInterface) { return 0; } return $current === $default ? 0 : 1; }); if (!$diff && null !== $this->parent) { return $this->parent->getMenuStyle(); } return new MenuStyle(...array_values($this->style)); }
public function testAddSubMenu() { $builder = new CliMenuBuilder(); $builder->disableDefaultItems(); $subMenuBuilder = $builder->addSubMenu('sub-menu'); $menu = $builder->build(); $this->checkItems($menu, [['class' => MenuMenuItem::class]]); $this->assertInstanceOf(CliMenuBuilder::class, $subMenuBuilder); $this->assertNotSame($subMenuBuilder, $builder); $this->assertSame($builder, $subMenuBuilder->end()); }