use Org\Mxchange\CoreFramework\Menu\RenderableMenu;
use Org\Mxchange\CoreFramework\Parser\Parseable;
use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
-use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
use Org\Mxchange\CoreFramework\Template\Engine\BaseTemplateEngine;
+use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
+use Org\Mxchange\CoreFramework\Traits\Stacker\StackableTrait;
use Org\Mxchange\CoreFramework\Utils\String\StringUtils;
// Import SPL stuff
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class MenuTemplateEngine extends BaseTemplateEngine implements CompileableTemplate {
+ // Load traits
+ use StackableTrait;
+
/**
* Main nodes in the XML tree ('menu' is ignored)
*/
- private $mainNodes = array(
+ private $mainNodes = [
'block-list',
- );
+ ];
/**
* Sub nodes in the XML tree
*/
- private $subNodes = array(
+ private $subNodes = [
'entry-list',
'entry',
'entry-id',
'anchor-text',
'anchor-title',
'anchor-href',
- );
+ ];
/**
* Variables for a menu entry
*/
- private $menuEntryVariables = array(
+ private $menuEntryVariables = [
// List entry
'entry_id',
// Anchor
'anchor-text',
'anchor-title',
'anchor-href',
- );
+ ];
/**
* Variables for a menu block
*/
- private $menuBlockVariables = array(
+ private $menuBlockVariables = [
// Title
'title_id',
'title_class',
'footer_id',
'footer_class',
'footer_text',
- );
+ ];
/**
* Rendered menu entries
*/
- private $menuEntries = array();
+ private $menuEntries = [];
/**
* Rendered menu blocks
*/
- private $menuBlocks = array();
+ private $menuBlocks = [];
/**
* Current main node
*/
- private $curr = array();
+ private $curr = [];
/**
* Content from dependency
*/
- private $dependencyContent = array();
+ private $dependencyContent = [];
/**
* Instance of a menu
* located in 'menu' by default
* @return void
*/
- public function loadMenuTemplate ($template) {
+ public function loadMenuTemplate (string $template) {
// Set template type
$this->setTemplateType(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('menu_template_type'));
* @param $element Element name to set as current main node
* @return $currMainNode Current main node
*/
- private final function setCurrMainNode ($element) {
- $this->curr['main_node'] = (string) $element;
+ private final function setCurrMainNode (string $element) {
+ $this->curr['main_node'] = $element;
}
/**
* @return void
* @throws InvalidXmlNodeException If an unknown/invalid XML node name was found
*/
- public function startElement ($resource, $element, array $attributes) {
+ public function startElement ($resource, string $element, array $attributes) {
// Initial method name which will never be called...
$methodName = 'initMenu';
* @return void
* @throws XmlNodeMismatchException If current main node mismatches the closing one
*/
- public function finishElement ($resource, $nodeName) {
- // Make all lower-case
- $nodeName = strtolower($nodeName);
-
+ public function finishElement ($resource, string $nodeName) {
// Does this match with current main node?
//* DEBUG: */ echo "END: >".$nodeName."<<br />\n";
if (($nodeName != $this->getCurrMainNode()) && (in_array($nodeName, $this->getMainNodes()))) {
// Did not match!
throw new XmlNodeMismatchException (array($this, $nodeName, $this->getCurrMainNode()), Parseable::EXCEPTION_XML_NODE_MISMATCH);
- } // END - if
+ }
// Construct method name
$methodName = 'finish' . StringUtils::convertToClassName($nodeName);
// Call the corresponding method
//* DEBUG: */ echo "call: ".$methodName."<br />\n";
- call_user_func_array(array($this, $methodName), array());
+ call_user_func_array(array($this, $methodName), []);
}
/**
* @return void
* @todo Find something useful with this!
*/
- public function characterHandler ($resource, $characters) {
+ public function characterHandler ($resource, string $characters) {
// Trim all spaces away
$characters = trim($characters);
if (empty($characters)) {
// Then skip it silently
return;
- } // END - if
+ }
// Assign the found characters to variable and use the last entry from
// stack as the name
* @param $templateDependency A template to load to satisfy dependencies
* @return void
*/
- private function handleTemplateDependency ($node, $templateDependency) {
+ private function handleTemplateDependency (string $node, string $templateDependency) {
// Is the template dependency set?
if ((!empty($templateDependency)) && (!isset($this->dependencyContent[$node]))) {
// Get a temporay menu template instance
// Save the parsed raw content in our dependency array
$this->dependencyContent[$node] = $templateInstance->getRawTemplateData();
- } // END - if
+ }
}
/**
* @return void
* @todo Add cache creation here
*/
- private function initMenu ($templateDependency = '') {
+ private function initMenu (string $templateDependency = '') {
// Get web template engine
$this->setTemplateInstance(ObjectFactory::createObjectByConfiguredName('html_template_class', array(GenericRegistry::getRegistry()->getInstance('application'))));
if ($variableName == 'anchor-href') {
// Expand variable with URL then
$variableValue = '{?base_url?}/' . $variableValue;
- } // END - if
+ }
// ... into the instance
$this->getTemplateInstance()->assignVariable($variableName, $variableValue);
- } // END - foreach
+ }
// Compile template + variables
$this->getTemplateInstance()->compileTemplate();
// ... into the instance
$this->getTemplateInstance()->assignVariable($variableName, $variableValue);
- } // END - foreach
+ }
// Assign block content
$this->getTemplateInstance()->assignVariable('block_content', $blockContent);
array_push($this->menuBlocks, $this->getTemplateInstance()->getRawTemplateData());
// Reset rendered menu entries array
- $this->menuEntries = array();
+ $this->menuEntries = [];
}
/**
$menuContent = implode('', $this->menuBlocks);
// Clean variable
- $this->menuBlocks = array();
+ $this->menuBlocks = [];
// And return it
return $menuContent;