本文整理汇总了PHP中Zend_Markup_Token::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Markup_Token::addAttribute方法的具体用法?PHP Zend_Markup_Token::addAttribute怎么用?PHP Zend_Markup_Token::addAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Markup_Token
的用法示例。
在下文中一共展示了Zend_Markup_Token::addAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _createTree
/**
* Create a tree from the tokenized text
*
* @return void
*/
protected function _createTree()
{
$inside = true;
foreach ($this->_tokens as $key => $token) {
// first check if the token is a stopper
if ($this->_isStopper($token, $this->_current)) {
if ($this->_current->getName() == 'li') {
// list items are handled differently
if (isset($this->_tokens[$key + 1]) && $this->_tokens[$key + 1]['type'] == Zend_Markup_Token::TYPE_TAG && $this->_tokens[$key + 1]['name'] == 'list') {
// the next item is a correct tag
$this->_current->setStopper($token['tag']);
$this->_current = $this->_current->getParent();
} else {
// close the list
$this->_current->setStopper($token['tag']);
$this->_current = $this->_current->getParent()->getParent();
// go up in the tree until we found the end
while ($this->_isStopper($token, $this->_current)) {
$this->_current->setStopper($token['tag']);
$this->_current = $this->_current->getParent();
}
}
} else {
// go up in the tree until we found the end of stoppers
while ($this->_isStopper($token, $this->_current)) {
$this->_current->setStopper($token['tag']);
if (!empty($token['attributes'])) {
foreach ($token['attributes'] as $name => $value) {
$this->_current->addAttribute($name, $value);
}
}
$this->_current = $this->_current->getParent();
}
}
$inside = true;
} elseif ($token['type'] == Zend_Markup_Token::TYPE_TAG && $inside) {
if ($token['name'] == 'break') {
// add the newline and continue parsing
$this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
} else {
// handle a list item
if ($token['name'] == 'list') {
$attributes = array();
if (isset($token['attributes']['list'])) {
$attributes['list'] = $token['attributes']['list'];
unset($token['attributes']['list']);
}
if ($this->_current->getName() != 'list') {
// the list isn't started yet, create it
$child = new Zend_Markup_Token('', Zend_Markup_Token::TYPE_TAG, 'list', $attributes, $this->_current);
$this->_current->addChild($child);
$this->_current = $child;
}
$token['name'] = 'li';
} elseif ($token['name'] == 'img' || $token['name'] == 'url') {
$inside = false;
}
// add the token
$child = new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_TAG, $token['name'], $token['attributes'], $this->_current);
$this->_current->addChild($child);
$this->_current = $child;
}
} else {
// simply add the token as text
$this->_current->addChild(new Zend_Markup_Token($token['tag'], Zend_Markup_Token::TYPE_NONE, '', array(), $this->_current));
}
}
}