Beispiel #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) {
     }
 }
Beispiel #2
0
 /**
  * Append an element
  *
  * @param \stdClass $value
  * @return void
  */
 public function append($value)
 {
     if ('name' == $value->type) {
         $container = $this->getContainer();
         $content = '';
         foreach ($container->getArrayCopy() as $index => $item) {
             if ($item->name == $value->name) {
                 $content = $item->content;
                 $this->offsetUnset($index);
             }
         }
         if ($content) {
             $separator = 'description' == $value->name ? ' ' : ', ';
             $value->content = $content . $separator . $value->content;
         }
     }
     return parent::append($value);
 }
Beispiel #3
0
 /**
  * If a keywords meta already exsists, extends it with $value->content,
  * else creates a new keywords meta.
  * @param \stdClass $value
  * @param string $position
  */
 public function updateKeywords(\stdClass $value, $position = AbstractContainer::SET)
 {
     $keywordsExists = false;
     foreach ($this->getContainer() as $item) {
         if (empty($value->content)) {
             return false;
         }
         if ($this->isKeywords($item)) {
             switch ($position) {
                 case AbstractContainer::APPEND:
                     $keywordsString = implode(', ', array($item->content, $value->content));
                     break;
                 case AbstractContainer::PREPEND:
                     $keywordsString = implode(', ', array($value->content, $item->content));
                     break;
                 case AbstractContainer::SET:
                 default:
                     $keywordsString = $value->content;
                     break;
             }
             $item->content = $keywordsString;
             $keywordsExists = true;
         }
     }
     if (!$keywordsExists) {
         parent::append($value);
     }
 }