nur-sery/nur_src/v/bs3/Bs3IconManager.php

173 lines
7.8 KiB
PHP
Raw Normal View History

2023-12-03 22:10:18 +04:00
<?php
namespace nur\v\bs3;
use nur\v\model\IIconManager;
class Bs3IconManager implements IIconManager {
const GLYPHS = [
"debug" => "bullhorn",
"info" => "info-sign",
"success" => "ok-sign",
"warning" => "exclamation-sign",
"error" => "remove-sign",
"refresh",
"config" => "cog",
"save" => "floppy-disk",
"download" => "download-alt",
"new_window",
"mail" => "enveloppe",
"search",
"user",
"login" => "log-in",
"logout" => "log-out",
"bin" => "trash",
"arrow_up", "arrow_down", "arrow_left", "arrow_right",
"chevron_up", "chevron_down", "chevron_left", "chevron_right",
"hand_up", "hand_down", "hand_left", "hand_right",
"menu_up", "menu_down", "menu_left", "menu_right",
"triangle_up", "triangle_down", "triangle_left", "triangle_right",
"star", "star_empty",
"heart", "heart_empty",
];
private function _getIcon(string $glyph, $suffix=null, ?string $alt=null, ?array $glyphMap=null): array {
if ($glyphMap === null) $glyphMap = self::_GLYPH_MAP;
if (isset($glyphMap[$glyph])) $glyph = $glyphMap[$glyph];
if ($alt) {
$alt = <<<EOT
<span class="sr-only">$alt</span>
EOT;
}
$html = <<<EOT
<span class="glyphicon glyphicon-$glyph" aria-hidden="true"></span>$alt
EOT;
$icon = [$html];
if ($suffix) {
$icon[] = "&nbsp;";
$icon[] = q($suffix);
}
return $icon;
}
function getIcon(string $glyph, $suffix=null, ?string $alt=null, ?array $glyphMap=null): array {
return $this->_getIcon($glyph, $suffix, $alt);
}
#############################################################################
const _AUTOGEN_CONSTS = ["_GLYPH_MAP", "" => ["_AUTOGEN__GLYPHS"]];
static final function _AUTOGEN__GLYPH_MAP(): array {
$glyphs = [];
$index = 0;
foreach (self::GLYPHS as $key => $glyph) {
if ($key === $index) {
$name = $glyph;
$glyph = strtolower(str_replace("_", "-", $glyph));
$index++;
} else {
$name = $key;
}
$glyphs[$name] = $glyph;
}
return $glyphs;
}
const _GLYPH_MAP = /*autogen*/[
'debug' => 'bullhorn',
'info' => 'info-sign',
'success' => 'ok-sign',
'warning' => 'exclamation-sign',
'error' => 'remove-sign',
'refresh' => 'refresh',
'config' => 'cog',
'save' => 'floppy-disk',
'download' => 'download-alt',
'new_window' => 'new-window',
'mail' => 'enveloppe',
'search' => 'search',
'user' => 'user',
'login' => 'log-in',
'logout' => 'log-out',
'bin' => 'trash',
'arrow_up' => 'arrow-up',
'arrow_down' => 'arrow-down',
'arrow_left' => 'arrow-left',
'arrow_right' => 'arrow-right',
'chevron_up' => 'chevron-up',
'chevron_down' => 'chevron-down',
'chevron_left' => 'chevron-left',
'chevron_right' => 'chevron-right',
'hand_up' => 'hand-up',
'hand_down' => 'hand-down',
'hand_left' => 'hand-left',
'hand_right' => 'hand-right',
'menu_up' => 'menu-up',
'menu_down' => 'menu-down',
'menu_left' => 'menu-left',
'menu_right' => 'menu-right',
'triangle_up' => 'triangle-up',
'triangle_down' => 'triangle-down',
'triangle_left' => 'triangle-left',
'triangle_right' => 'triangle-right',
'star' => 'star',
'star_empty' => 'star-empty',
'heart' => 'heart',
'heart_empty' => 'heart-empty',
];
static final function _AUTOGEN__GLYPHS(): array {
$glyphMap = self::_AUTOGEN__GLYPH_MAP();
$im = new self();
$glyphs = [];
foreach (array_keys($glyphMap) as $glyph) {
$name = strtoupper($glyph);
$glyphs[$name] = $im->_getIcon($glyph, null, null, $glyphMap);
}
return $glyphs;
}
# --autogen-dynamic-consts--
const DEBUG = /*autogen*/['<span class="glyphicon glyphicon-bullhorn" aria-hidden="true"></span>'];
const INFO = /*autogen*/['<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>'];
const SUCCESS = /*autogen*/['<span class="glyphicon glyphicon-ok-sign" aria-hidden="true"></span>'];
const WARNING = /*autogen*/[
'<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>',
];
const ERROR = /*autogen*/['<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>'];
const REFRESH = /*autogen*/['<span class="glyphicon glyphicon-refresh" aria-hidden="true"></span>'];
const CONFIG = /*autogen*/['<span class="glyphicon glyphicon-cog" aria-hidden="true"></span>'];
const SAVE = /*autogen*/['<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>'];
const DOWNLOAD = /*autogen*/['<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span>'];
const NEW_WINDOW = /*autogen*/['<span class="glyphicon glyphicon-new-window" aria-hidden="true"></span>'];
const MAIL = /*autogen*/['<span class="glyphicon glyphicon-enveloppe" aria-hidden="true"></span>'];
const SEARCH = /*autogen*/['<span class="glyphicon glyphicon-search" aria-hidden="true"></span>'];
const USER = /*autogen*/['<span class="glyphicon glyphicon-user" aria-hidden="true"></span>'];
const LOGIN = /*autogen*/['<span class="glyphicon glyphicon-log-in" aria-hidden="true"></span>'];
const LOGOUT = /*autogen*/['<span class="glyphicon glyphicon-log-out" aria-hidden="true"></span>'];
const BIN = /*autogen*/['<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>'];
const ARROW_UP = /*autogen*/['<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>'];
const ARROW_DOWN = /*autogen*/['<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>'];
const ARROW_LEFT = /*autogen*/['<span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>'];
const ARROW_RIGHT = /*autogen*/['<span class="glyphicon glyphicon-arrow-right" aria-hidden="true"></span>'];
const CHEVRON_UP = /*autogen*/['<span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span>'];
const CHEVRON_DOWN = /*autogen*/['<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>'];
const CHEVRON_LEFT = /*autogen*/['<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>'];
const CHEVRON_RIGHT = /*autogen*/['<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>'];
const HAND_UP = /*autogen*/['<span class="glyphicon glyphicon-hand-up" aria-hidden="true"></span>'];
const HAND_DOWN = /*autogen*/['<span class="glyphicon glyphicon-hand-down" aria-hidden="true"></span>'];
const HAND_LEFT = /*autogen*/['<span class="glyphicon glyphicon-hand-left" aria-hidden="true"></span>'];
const HAND_RIGHT = /*autogen*/['<span class="glyphicon glyphicon-hand-right" aria-hidden="true"></span>'];
const MENU_UP = /*autogen*/['<span class="glyphicon glyphicon-menu-up" aria-hidden="true"></span>'];
const MENU_DOWN = /*autogen*/['<span class="glyphicon glyphicon-menu-down" aria-hidden="true"></span>'];
const MENU_LEFT = /*autogen*/['<span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span>'];
const MENU_RIGHT = /*autogen*/['<span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span>'];
const TRIANGLE_UP = /*autogen*/['<span class="glyphicon glyphicon-triangle-up" aria-hidden="true"></span>'];
const TRIANGLE_DOWN = /*autogen*/['<span class="glyphicon glyphicon-triangle-down" aria-hidden="true"></span>'];
const TRIANGLE_LEFT = /*autogen*/['<span class="glyphicon glyphicon-triangle-left" aria-hidden="true"></span>'];
const TRIANGLE_RIGHT = /*autogen*/['<span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>'];
const STAR = /*autogen*/['<span class="glyphicon glyphicon-star" aria-hidden="true"></span>'];
const STAR_EMPTY = /*autogen*/['<span class="glyphicon glyphicon-star-empty" aria-hidden="true"></span>'];
const HEART = /*autogen*/['<span class="glyphicon glyphicon-heart" aria-hidden="true"></span>'];
const HEART_EMPTY = /*autogen*/['<span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span>'];
}