예제 #1
0
 /**
  * Execute the token
  *
  * @param  \Zend\Markup\Token $token
  * @return string
  */
 protected function _execute(Markup\Token $token)
 {
     // first return the normal text markups
     if ($token->getType() == Markup\Token::TYPE_NONE) {
         return $this->_filter($token->getTag());
     }
     // if the token doesn't have a notation, return the plain text
     if (!isset($this->_markups[$token->getName()])) {
         $oldToken = $this->_token;
         $return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
         $this->_token = $oldToken;
         return $return;
     }
     $name = $this->_getMarkupName($token);
     $markup = !$name ? false : $this->_markups[$name];
     $empty = is_array($markup) && array_key_exists('empty', $markup) && $markup['empty'];
     // check if the markup has content
     if (!$empty && !$token->hasChildren()) {
         return '';
     }
     // check for the context
     if (is_array($markup) && !in_array($markup['group'], $this->_groups[$this->_group])) {
         $oldToken = $this->_token;
         $return = $this->_filter($token->getTag()) . $this->_render($token) . $token->getStopper();
         $this->_token = $oldToken;
         return $return;
     }
     // check for the filter
     if (!isset($markup['filter']) || !$markup['filter'] instanceof Filter\Filter && $markup['filter'] !== false) {
         $this->_markups[$name]['filter'] = $this->getDefaultFilter();
     }
     // save old values to reset them after the work is done
     $oldFilter = $this->_filter;
     $oldGroup = $this->_group;
     $return = '';
     // set the filter and the group
     $this->_filter = $this->getFilter($name);
     if ($group = $this->_getGroup($token)) {
         $this->_group = $group;
     }
     // callback
     if (is_array($markup) && $markup['type'] & self::TYPE_CALLBACK) {
         // load the callback if the markup doesn't exist
         if (!$markup['callback'] instanceof TokenConverterInterface) {
             $class = $this->getPluginLoader()->load($name);
             $markup['callback'] = new $class();
             if (!$markup['callback'] instanceof TokenConverterInterface) {
                 throw new Exception("Callback for markup '{$name}' found, but it isn't valid.");
             }
             if (method_exists($markup['callback'], 'setRenderer')) {
                 $markup['callback']->setRenderer($this);
             }
         }
         if ($markup['type'] && !$empty) {
             $return = $markup['callback']->convert($token, $this->_render($token));
         } else {
             $return = $markup['callback']->convert($token, null);
         }
     } else {
         // replace
         if ($markup['type'] && !$empty) {
             $return = $this->_executeReplace($token, $markup);
         } else {
             $return = $this->_executeSingleReplace($token, $markup);
         }
     }
     // reset to the old values
     $this->_filter = $oldFilter;
     $this->_group = $oldGroup;
     return $return;
 }