コード例 #1
0
ファイル: MetaDataBagTest.php プロジェクト: gobjila/BackBee
 /**
  * @covers BackBee\MetaData\MetaDataBag::jsonSerialize
  */
 public function testJsonSerialize()
 {
     $meta1 = new MetaData('test1');
     $meta1->setAttribute('name', 'test1');
     $meta1->setAttribute('content', 'content of test1');
     $meta1->setAttribute('lang', 'fr');
     $meta2 = new MetaData('test2');
     $meta2->setAttribute('name', 'test2');
     $meta2->setAttribute('content', 'content of test2');
     $meta2->setAttribute('lang', 'en');
     $bag = new MetaDataBag();
     $bag->add($meta1)->add($meta2);
     $expected = ['test1' => ['content' => 'content of test1', 'lang' => 'fr'], 'test2' => ['content' => 'content of test2', 'lang' => 'en']];
     $this->assertEquals($expected, $bag->jsonSerialize());
 }
コード例 #2
0
 /**
  * @covers BackBee\MetaData\MetaData::jsonSerialize
  */
 public function testJsonSerialize()
 {
     $meta = new MetaData();
     $meta->setAttribute('name', 'name value');
     $meta->setAttribute('content', 'content value');
     $expected = [['attr' => 'name', 'value' => 'name value'], ['attr' => 'content', 'value' => 'content value']];
     $this->assertEquals($expected, $meta->jsonSerialize());
 }
コード例 #3
0
ファイル: MetaDataBag.php プロジェクト: nietzcheson/BackBee
 /**
  * Adds a new matadata to the bag.
  *
  * @param \BackBee\MetaData\MetaData $metadata
  *
  * @return \BackBee\MetaData\MetaDataBag
  * @codeCoverageIgnore
  */
 public function add(MetaData $metadata)
 {
     $this->metadatas[$metadata->getName()] = $metadata;
     return $this;
 }
コード例 #4
0
ファイル: MetaDataResolver.php プロジェクト: gobjila/BackBee
 /**
  * Parses definition and resolve value for $metadata.
  *
  * @param array     $definition
  * @param MetaData  $metadata
  * @param Page|NULL $page
  */
 private function parseDefinition(array $definition, MetaData $metadata, Page $page = null)
 {
     foreach ($definition as $attrname => $attrvalue) {
         if (!is_array($attrvalue)) {
             $attrvalue = [$attrvalue];
         }
         if (!$metadata->isComputed($attrname)) {
             continue;
         }
         $scheme = '' === $metadata->getAttribute($attrname) ? reset($attrvalue) : $metadata->getAttribute($attrname);
         if ('title' === $metadata->getName() && null !== $page && null !== $page->getTitle() && array_key_exists('default', $attrvalue)) {
             $scheme = $page->getTitle();
         } elseif (array_key_exists('default', $attrvalue)) {
             $scheme = $attrvalue['default'];
         }
         if (null !== $page && null !== $page->getLayout() && array_key_exists('layout', $attrvalue) && array_key_exists($page->getLayout()->getUid(), $attrvalue['layout'])) {
             $scheme = $attrvalue['layout'][$page->getLayout()->getUid()];
         }
         if (null !== $page && null !== $page->getLayout() && array_key_exists('layout', $attrvalue) && array_key_exists($page->getLayout()->getLabel(), $attrvalue['layout'])) {
             $scheme = $attrvalue['layout'][$page->getLayout()->getLabel()];
         }
         $matches = [];
         $isComputed = true;
         if (null !== $page && preg_match(self::MATCH_PATTERN, $scheme)) {
             $value = $this->resolveScheme($scheme, $page);
         } elseif (preg_match(self::CONST_PATTERN, $scheme, $matches)) {
             $value = $this->resolveConst($matches[1], $page);
         } else {
             $value = $scheme;
             $scheme = null;
             $isComputed = false;
         }
         $metadata->setAttribute($attrname, $value, $scheme, $isComputed);
     }
 }