You are here

protected function EasyRdf_Graph::checkValueParam in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php \EasyRdf_Graph::checkValueParam()

Check that a value parameter is valid, and convert it to an associative array if needed @ignore

6 calls to EasyRdf_Graph::checkValueParam()
EasyRdf_Graph::add in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Add data to the graph
EasyRdf_Graph::deleteLiteral in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Delete a literal value from a property of a resource
EasyRdf_Graph::deleteSingleProperty in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Delete a property (or optionally just a specific value)
EasyRdf_Graph::hasProperty in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Check to see if a property exists for a resource.
EasyRdf_Graph::resourcesMatching in vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an arry of resources matching a certain property and optional value.

... See full list

File

vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 500

Class

EasyRdf_Graph
Container for collection of EasyRdf_Resources.

Code

protected function checkValueParam(&$value) {
  if (isset($value)) {
    if (is_object($value)) {
      if (!method_exists($value, 'toRdfPhp')) {

        // Convert to a literal object
        $value = EasyRdf_Literal::create($value);
      }
      $value = $value
        ->toRdfPhp();
    }
    elseif (is_array($value)) {
      if (!isset($value['type'])) {
        throw new InvalidArgumentException("\$value is missing a 'type' key");
      }
      if (!isset($value['value'])) {
        throw new InvalidArgumentException("\$value is missing a 'value' key");
      }

      // Fix ordering and remove unknown keys
      $value = array(
        'type' => strval($value['type']),
        'value' => strval($value['value']),
        'lang' => isset($value['lang']) ? strval($value['lang']) : null,
        'datatype' => isset($value['datatype']) ? strval($value['datatype']) : null,
      );
    }
    else {
      $value = array(
        'type' => 'literal',
        'value' => strval($value),
        'datatype' => EasyRdf_Literal::getDatatypeForValue($value),
      );
    }
    if (!in_array($value['type'], array(
      'uri',
      'bnode',
      'literal',
    ), true)) {
      throw new InvalidArgumentException("\$value does not have a valid type (" . $value['type'] . ")");
    }
    if (empty($value['datatype'])) {
      unset($value['datatype']);
    }
    if (empty($value['lang'])) {
      unset($value['lang']);
    }
    if (isset($value['lang']) and isset($value['datatype'])) {
      throw new InvalidArgumentException("\$value cannot have both and language and a datatype");
    }
  }
}