. * * @file * @ingroup Skins */ namespace Skins\Chameleon\Menu; /** * Class Menu * * @author Stephan Gambke * @since 1.0 * @ingroup Skins */ abstract class Menu { private $menuItemFormatter = null; private $itemListFormatter = null; abstract public function getHtml(); /** * @param string $href * @param string $text * @param int $depth * @param string $subitems * * @return string */ protected function getHtmlForMenuItem( $href, $text, $depth, $subitems ) { return call_user_func( $this->getMenuItemFormatter(), $href, $text, $depth, $subitems ); } /** * @return callable */ public function getMenuItemFormatter() { if ( $this->menuItemFormatter === null ) { $this->setMenuItemFormatter( function ( $href, $text, $depth, $subitems ) { $href = \Sanitizer::cleanUrl( $href ); $text = htmlspecialchars( $text ); $indent = str_repeat( "\t", 2 * $depth ); if ( $subitems !== '' ) { return "$indent
  • \n$indent\t$text\n$subitems$indent
  • \n"; } else { return "$indent
  • $text
  • \n"; } } ); } return $this->menuItemFormatter; } /** * @param callable $menuItemFormatter */ public function setMenuItemFormatter( $menuItemFormatter ) { $this->menuItemFormatter = $menuItemFormatter; } /** * @param string $rawItemsHtml * @param int $depth * * @return string */ protected function getHtmlForMenuItemList( $rawItemsHtml, $depth ) { return call_user_func( $this->getItemListFormatter(), $rawItemsHtml, $depth ); } /** * @return callable */ public function getItemListFormatter() { if ( $this->itemListFormatter === null ) { $this->setItemListFormatter( function ( $rawItemsHtml, $depth ) { $indent = str_repeat( "\t", 2 * $depth + 1 ); return "$indent\n"; } ); } return $this->itemListFormatter; } /** * @param callable $itemListFormatter */ public function setItemListFormatter( $itemListFormatter ) { $this->itemListFormatter = $itemListFormatter; } }