1<?php 2 3namespace ComboStrap\TagAttribute; 4 5use ComboStrap\ExceptionBadArgument; 6use ComboStrap\LogUtility; 7use ComboStrap\PluginUtility; 8use ComboStrap\TagAttributes; 9 10class Hero 11{ 12 13 const COMPONENT_NAME = "hero"; 14 const CANONICAL = self::COMPONENT_NAME; 15 const ATTRIBUTE = self::COMPONENT_NAME; 16 17 18 public static function processHero(TagAttributes &$attributes) 19 { 20 21 $hero = $attributes->getValueAndRemove(self::ATTRIBUTE); 22 if ($hero === null) { 23 return; 24 } 25 try { 26 switch ($hero) { 27 case "sm": 28 case "small": 29 $attributes->addClassName(self::COMPONENT_NAME . "-sm"); 30 break; 31 case "md": 32 case "medium": 33 $attributes->addClassName(self::COMPONENT_NAME . "-md"); 34 break; 35 case "lg": 36 case "large": 37 $attributes->addClassName(self::COMPONENT_NAME . "-lg"); 38 break; 39 case "xl": 40 case "extra-large": 41 $attributes->addClassName(self::COMPONENT_NAME . "-xl"); 42 break; 43 case "none": 44 return; 45 default: 46 throw new ExceptionBadArgument("The hero value ($hero) is unknown and was not applied"); 47 } 48 /** 49 * We could have used bootstrap specific class such as 50 * `px-4 py-2` 51 * but the unit scale goes only to 5 (=3 rem) and 52 * the `xl` hero goes to 4 rem 53 */ 54 PluginUtility::getSnippetManager()->attachCssInternalStyleSheet(self::COMPONENT_NAME); 55 } catch (ExceptionBadArgument $e) { 56 LogUtility::error($e->getMessage(), self::CANONICAL); 57 } 58 59 } 60} 61