示例#1
0
 /**
  * @covers BackBee\MetaData\MetaData::__construct
  */
 public function test__construct()
 {
     $metaWithoutName = new MetaData();
     $this->assertNull($metaWithoutName->getName());
     $metaWithName = new MetaData('test');
     $this->assertEquals('test', $metaWithName->getName());
 }
示例#2
0
 /**
  * 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;
 }
示例#3
0
 /**
  * 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);
     }
 }