示例#1
0
 public function testAppendPrependAndSetThrowExceptionsWhenNonMetaValueProvided()
 {
     try {
         $this->helper->append('foo');
         $this->fail('Non-meta value should not append');
     } catch (ViewException $e) {
     }
     try {
         $this->helper->offsetSet(3, 'foo');
         $this->fail('Non-meta value should not offsetSet');
     } catch (ViewException $e) {
     }
     try {
         $this->helper->prepend('foo');
         $this->fail('Non-meta value should not prepend');
     } catch (ViewException $e) {
     }
     try {
         $this->helper->set('foo');
         $this->fail('Non-meta value should not set');
     } catch (ViewException $e) {
     }
 }
示例#2
0
文件: HeadMeta.php 项目: omusico/Base
 /**
  * If a description meta already exsists, extends it with $value->content,
  * else creates a new desctiprion meta.
  * @param \stdClass $value
  * @param string $position
  */
 public function updateDescription(\stdClass $value, $position = AbstractContainer::SET)
 {
     $descriptionExists = false;
     foreach ($this->getContainer() as $item) {
         if ($this->isDescription($item)) {
             switch ($position) {
                 case AbstractContainer::APPEND:
                     $descriptionString = implode(static::DELIMITER, array($item->content, $value->content));
                     break;
                 case AbstractContainer::PREPEND:
                     $descriptionString = implode(static::DELIMITER, array($value->content, $item->content));
                     break;
                 case AbstractContainer::SET:
                 default:
                     $descriptionString = $value->content;
                     break;
             }
             $item->content = $descriptionString;
             $descriptionExists = true;
         }
     }
     if (!$descriptionExists) {
         switch ($position) {
             case AbstractContainer::APPEND:
                 parent::append($value);
                 break;
             case AbstractContainer::PREPEND:
                 parent::prepend($value);
                 break;
             case AbstractContainer::SET:
             default:
                 parent::set($value);
                 break;
         }
     }
 }