You are here

protected function EasyRdf_Parser_RdfXml::startState2 in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php \EasyRdf_Parser_RdfXml::startState2()

@ignore

1 call to EasyRdf_Parser_RdfXml::startState2()
EasyRdf_Parser_RdfXml::startElementHandler in vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php
@ignore

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Parser/RdfXml.php, line 377

Class

EasyRdf_Parser_RdfXml
A pure-php class to parse RDF/XML.

Code

protected function startState2($t, $a) {
  $s = $this
    ->getParentS();
  foreach (array(
    'p_x_base',
    'p_x_lang',
    'p_id',
    'o_is_coll',
  ) as $k) {
    unset($s[$k]);
  }

  /* base */
  if (isset($a[$this->xml . 'base'])) {
    $s['p_x_base'] = $s['x_base']
      ->resolve($a[$this->xml . 'base']);
  }
  $b = isset($s['p_x_base']) && $s['p_x_base'] ? $s['p_x_base'] : $s['x_base'];

  /* lang */
  if (isset($a[$this->xml . 'lang'])) {
    $s['p_x_lang'] = $a[$this->xml . 'lang'];
  }
  $l = isset($s['p_x_lang']) && $s['p_x_lang'] ? $s['p_x_lang'] : $s['x_lang'];

  /* adjust li */
  if ($t === $this->rdf . 'li') {
    $s['li_count']++;
    $t = $this->rdf . '_' . $s['li_count'];
  }

  /* set p */
  $s['p'] = $t;

  /* reification */
  if (isset($a[$this->rdf . 'ID'])) {
    $s['p_id'] = $a[$this->rdf . 'ID'];
  }
  $o = array(
    'value' => null,
    'type' => null,
    'x_base' => $b,
    'x_lang' => $l,
  );

  /* resource/rdf:resource */
  if (isset($a['resource'])) {
    $a[$this->rdf . 'resource'] = $a['resource'];
    unset($a['resource']);
  }
  if (isset($a[$this->rdf . 'resource'])) {
    $o['type'] = 'uri';
    $o['value'] = $b
      ->resolve($a[$this->rdf . 'resource']);
    $this
      ->add($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);

    /* type */
    if (isset($a[$this->rdf . 'type'])) {
      $this
        ->add($o['value'], $this->rdf . 'type', $a[$this->rdf . 'type'], 'uri', 'uri');
    }

    /* reification */
    if (isset($s['p_id'])) {
      $this
        ->reify($b
        ->resolve('#' . $s['p_id']), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
      unset($s['p_id']);
    }
    $this->state = 3;
  }
  elseif (isset($a[$this->rdf . 'nodeID'])) {

    /* named bnode */
    $o['value'] = $this
      ->remapBnode($a[$this->rdf . 'nodeID']);
    $o['type'] = 'bnode';
    $this
      ->add($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
    $this->state = 3;

    /* reification */
    if (isset($s['p_id'])) {
      $this
        ->reify($b
        ->resolve('#' . $s['p_id']), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
    }

    /* parseType */
  }
  elseif (isset($a[$this->rdf . 'parseType'])) {
    if ($a[$this->rdf . 'parseType'] === 'Literal') {
      $s['o_xml_level'] = 0;
      $s['o_xml_data'] = '';
      $s['p_xml_literal_level'] = 0;
      $s['ns'] = array();
      $this->state = 6;
    }
    elseif ($a[$this->rdf . 'parseType'] === 'Resource') {
      $o['value'] = $this->graph
        ->newBNodeId();
      $o['type'] = 'bnode';
      $o['hasClosingTag'] = 0;
      $this
        ->add($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
      $this
        ->pushS($o);

      /* reification */
      if (isset($s['p_id'])) {
        $this
          ->reify($b
          ->resolve('#' . $s['p_id']), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
        unset($s['p_id']);
      }
      $this->state = 2;
    }
    elseif ($a[$this->rdf . 'parseType'] === 'Collection') {
      $s['o_is_coll'] = true;
      $this->state = 4;
    }
  }
  else {

    /* sub-node or literal */
    $s['o_cdata'] = '';
    if (isset($a[$this->rdf . 'datatype'])) {
      $s['o_datatype'] = $a[$this->rdf . 'datatype'];
    }
    $this->state = 4;
  }

  /* any other attrs (skip rdf and xml) */
  foreach ($a as $k => $v) {
    if (strpos($k, $this->xml) === false && strpos($k, $this->rdf) === false || preg_match('/(\\_[0-9]+|value)$/', $k)) {
      if (strpos($k, ':')) {
        if (!$o['value']) {
          $o['value'] = $this->graph
            ->newBNodeId();
          $o['type'] = 'bnode';
          $this
            ->add($s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
        }

        /* reification */
        if (isset($s['p_id'])) {
          $this
            ->reify($b
            ->resolve('#' . $s['p_id']), $s['value'], $s['p'], $o['value'], $s['type'], $o['type']);
          unset($s['p_id']);
        }
        $this
          ->add($o['value'], $k, $v, $o['type'], 'literal');
        $this->state = 3;
      }
    }
  }
  $this
    ->updateS($s);
}