public static function compile (array $metadata, Component $parent, $prepend = false)
  {
    foreach ($metadata as $item) {
      if (!$item instanceof self) {
        $parent->addChild ($item->cloneWithContext ($parent->context), $prepend);
        continue;
      }
      $tag      = $item->getTagName ();
      $propName = lcfirst ($tag);
      // Insert metadata
      if ($parent->props && !($parent instanceof self) && $parent->props->defines ($propName)) {
        if ($parent->props->getTypeOf ($propName) == type::collection) {
          $comp =
            new self ($parent->context, $tag, $parent->props->getRelatedTypeOf ($propName), $item->props->getAll (),
              $item->bindings);
          if ($prepend)
            array_unshift ($parent->props->$propName, $comp);
          else array_push ($parent->props->$propName, $comp);
        }
        else {
          $comp = new self ($parent->context, $tag, $parent->props->getTypeOf ($propName), $item->props->getAll (),
            $item->bindings);
          $parent->props->set ($propName, $comp);
        }
      }
      // Insert content
      else {
        $comp = $tag === 'Text'
          ? Text::from ($parent->context, $item->value)
          : $parent->context->createComponentFromTag ($tag, $parent, $item->props->getAll (), $item->bindings);
        $parent->addChild ($comp, $prepend);
      }
      // Now, compile the children.
      if ($item->hasChildren ())
        self::compile ($item->getChildren (), $comp);
    };
  }
public static function compile (array $metadata, Component $parent, $prepend = false)
  {
    foreach ($metadata as $item) {
      if (!$item instanceof self) {
        $parent->addChild ($item->cloneWithContext ($parent->context), $prepend);
        continue;
      }
      $tag      = $item->getTagName ();
      $propName = lcfirst ($tag);
      // Insert metadata
      if ($parent->props && !($parent instanceof self) && $parent->props->defines ($propName)) {
        if ($parent->props->getTypeOf ($propName) == type::collection) {
          $comp =
            new self ($parent->context, $tag, $parent->props->getRelatedTypeOf ($propName), $item->props->getAll (),
              $item->bindings);
          if ($prepend)
            array_unshift ($parent->props->$propName, $comp);
          else array_push ($parent->props->$propName, $comp);
        }
        else {
          $comp = new self ($parent->context, $tag, $parent->props->getTypeOf ($propName), $item->props->getAll (),
            $item->bindings);
          $parent->props->set ($propName, $comp);
        }
      }
      // Insert content
      else {
        $comp = $tag === 'Text'
          ? Text::from ($parent->context, $item->value)
          : $parent->context->createComponentFromTag ($tag, $parent, $item->props->getAll (), $item->bindings);
        $parent->addChild ($comp, $prepend);
      }
      // Now, compile the children.
      if ($item->hasChildren ())
        self::compile ($item->getChildren (), $comp);
    };
  }
public static function compile ( array $ metadata , Component $ parent , $ prepend = false ) { foreach ( $ metadata as $ item ) { if ( ! $ item instanceof self ) { $ parent -> addChild ( $ item -> cloneWithContext ( $ parent -> context ) , $ prepend ) ; continue ; } $ tag = $ item -> getTagName ( ) ; $ propName = lcfirst ( $ tag ) ; // Insert metadata if ( $ parent -> props && ! ( $ parent instanceof self ) && $ parent -> props -> defines ( $ propName ) ) { if ( $ parent -> props -> getTypeOf ( $ propName ) == type :: collection ) { $ comp = new self ( $ parent -> context , $ tag , $ parent -> props -> getRelatedTypeOf ( $ propName ) , $ item -> props -> getAll ( ) , $ item -> bindings ) ; if ( $ prepend ) array_unshift ( $ parent -> props -> $ propName , $ comp ) ; else array_push ( $ parent -> props -> $ propName , $ comp ) ; } else { $ comp = new self ( $ parent -> context , $ tag , $ parent -> props -> getTypeOf ( $ propName ) , $ item -> props -> getAll ( ) , $ item -> bindings ) ; $ parent -> props -> set ( $ propName , $ comp ) ; } } // Insert content else { $ comp = $ tag === 'Text' ? Text :: from ( $ parent -> context , $ item -> value ) : $ parent -> context -> createComponentFromTag ( $ tag , $ parent , $ item -> props -> getAll ( ) , $ item -> bindings ) ; $ parent -> addChild ( $ comp , $ prepend ) ; } // Now, compile the children. if ( $ item -> hasChildren ( ) ) self :: compile ( $ item -> getChildren ( ) , $ comp ) ; } ; }
Converts an array of Metadata trees to actual content that can be rendered.

@param self[]    $metadata The metadata to be converted.
@param Component $parent   The content will be assigned to this component and will inherit its context.
@param bool      $prepend  When true, children are prepended to the existing content, or the the beginning of a
collection property.
Converts an array of Metadata trees to actual content that can be rendered .