You are here

public static function RestWSBaseFormat::getData in RESTful Web Services 7

Same name and namespace in other branches
  1. 7.2 restws.formats.inc \RestWSBaseFormat::getData()

Gets a simple PHP array using URI references for some wrapped data.

1 call to RestWSBaseFormat::getData()
RestWSBaseFormat::viewResource in ./restws.formats.inc
Gets the representation of a resource.

File

./restws.formats.inc, line 139
RESTful web services module formats.

Class

RestWSBaseFormat
A base for all simple formats that are just serializing/unserializing an array of property values.

Code

public static function getData($wrapper) {
  $data = array();
  $filtered = restws_property_access_filter($wrapper);
  foreach ($filtered as $name => $property) {
    try {
      if ($property instanceof EntityDrupalWrapper) {

        // For referenced entities only return the URI.
        if ($id = $property
          ->getIdentifier()) {
          $data[$name] = self::getResourceReference($property
            ->type(), $id);
        }
      }
      elseif ($property instanceof EntityValueWrapper) {
        $data[$name] = $property
          ->value();
      }
      elseif ($property instanceof EntityListWrapper || $property instanceof EntityStructureWrapper) {
        $data[$name] = self::getData($property);
      }
    } catch (EntityMetadataWrapperException $e) {

      // A property causes problems - ignore that.
    }
  }
  return $data;
}