コード例 #1
0
ファイル: HeadMetaTest.php プロジェクト: pnaq57/zf2demo
 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 プロジェクト: Andyyang1981/pi
 /**
  * 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);
 }
コード例 #3
0
ファイル: HeadMeta.php プロジェクト: omusico/Base
 /**
  * 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);
     }
 }