protected function 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 drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Add data to the graph
EasyRdf_Graph::delete in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Delete a property (or optionally just a specific value)
EasyRdf_Graph::deleteLiteral in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Delete a literal value from a property of a resource
EasyRdf_Graph::hasProperty in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Check to see if a property exists for a resource.
EasyRdf_Graph::resourcesMatching in drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php
Get an arry of resources matching a certain property and optional value.

... See full list

File

drupal/core/vendor/easyrdf/easyrdf/lib/EasyRdf/Graph.php, line 490

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, 'toArray')) {
        $value = $value
          ->toArray();
      }
      else {
        throw new InvalidArgumentException("\$value should respond to the method toArray()");
      }
    }
    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");
    }
  }
}