You are here

class WSDecoderJSON in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/WSDecoder/WSDecoderJSON.php \Drupal\wsdata\Plugin\WSDecoder\WSDecoderJSON

JSON Decoder.

Plugin annotation


@WSDecoder(
  id = "WSDecoderJSON",
  label = @Translation("JSON Decoder", context = "WSDecoder"),
)

Hierarchy

Expanded class hierarchy of WSDecoderJSON

1 string reference to 'WSDecoderJSON'
wsdata.wscall.fetch_individual_post.yml in modules/wsdata_example/config/install/wsdata.wscall.fetch_individual_post.yml
modules/wsdata_example/config/install/wsdata.wscall.fetch_individual_post.yml

File

src/Plugin/WSDecoder/WSDecoderJSON.php, line 16

Namespace

Drupal\wsdata\Plugin\WSDecoder
View source
class WSDecoderJSON extends WSDecoderBase {

  /**
   * {@inheritdoc}
   */
  public function decode($data) {
    if (!isset($data) || empty($data)) {
      return;
    }

    // Remove UTF-8 BOM if present, json_decode() does not like it.
    if (substr($data, 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
      $data = substr($data, 3);
    }
    $data = trim($data);
    return Json::decode($data);
  }

  /**
   * {@inheritdoc}
   */
  public function accepts() {
    return [
      'text/json',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
WSDecoderBase::$data public property Storage for decoded data.
WSDecoderBase::$error protected property Storage for error information.
WSDecoderBase::$languages protected property Languages which we have data for.
WSDecoderBase::addData public function Add data to an empty object or replace all existing data. Overrides WSDecoderInterface::addData
WSDecoderBase::getData public function Retrieve the value for the given data key. Overrides WSDecoderInterface::getData
WSDecoderBase::getError public function Retrieve error message, if any. Overrides WSDecoderInterface::getError
WSDecoderBase::isCacheable public function Returns whether or not the result on the decoder are cacheable.
WSDecoderBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
WSDecoderJSON::accepts public function Returns an array of the content type of the data this processor accepts. Overrides WSDecoderBase::accepts
WSDecoderJSON::decode public function Decode the web service response string into an array. Overrides WSDecoderBase::decode