/** <code>{% else %}</code> tag. */ public function handleTElse(TemplateCompilerEx $compiler, TemplateNodeEx $node, &$tag, array &$args) { // if it's {% ifchanged %} ... {% else %} ... {% endif %} // then it should work like {% empty %}, and this handler should not be called if ($node->nodeParent->nodeContent[0] == 'ifchanged') { TemplateUtils::panic(__FILE__, __LINE__); } return '}else{'; }
/** Generates prefixed block name that is guaranteed to be unique in current template. By default generates 5-character unique key using combination of @c uniqid, @c mt_rand and @c md5. Beware: potential infinite loop - if key length is too small, then key space might be exhausted, which will lead to infinite loop in this function. Increase @c $keyLength if your usage could lead to this condition. @param[in] $idPrefix @c uniqid prefix @param[in] $blockPrefix Unique key will be prefixed with this. Default: @c custom:. @param[in] $keyLength Length of generated key. Must be lower than 32. Default: 5. */ public function generateUniqueBlock($idPrefix, $blockPrefix = 'custom:', $keyLength = 5) { if (32 - $keyLength <= 0) { TemplateUtils::panic(__FILE__, __LINE__); } do { $generatedID = md5(uniqid($idPrefix, true)); $randomOffset = mt_rand(0, 32 - $keyLength); $blockName = $blockPrefix . mb_substr($generatedID, $randomOffset, $keyLength); } while (isset($this->blocks[$blockName])); return $blockName; }
/** Tests the behaviour of @ref TemplateUtils::panic. */ public function testUtilsPanic() { $this->setExpectedException('TemplateError', 'PANIC', TemplateError::E_INTERNAL_CORE_FAILURE); TemplateUtils::panic(__FILE__, __LINE__); }