<?php
namespace App\Smarty\Functions; class NameFormat { static public function create($params, $smarty) { return sprintf("<span>%s</span>", static::renderStr((string)$params['firstName'], (string)$params['lastName'], (string)$params['middleName'])); } static public function renderStr(string $firstName, string $lastName, string $middleName='') : string { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); switch ($CFG['localization']['nameFormat']) { case 'last,first,middle': return implode(" ", array_filter([ $lastName, $firstName, $middleName, ])); break; case 'first,middle,last': return implode(" ", array_filter([ $firstName, $middleName, $lastName, ])); break; default: throw new \Exception("Unsupported name format configured: {$CFG['localization']['nameFormat']}"); } } }