class JsonSchemaEncoder in Schemata 8
Encodes data into json_schema.
Simply respond to application/vnd.api+json format requests using encoder.
Hierarchy
- class \Drupal\serialization\Encoder\JsonEncoder extends \Symfony\Component\Serializer\Encoder\JsonEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInterface, \Symfony\Component\Serializer\Encoder\DecoderInterface
- class \Drupal\schemata_json_schema\Encoder\JsonSchemaEncoder
Expanded class hierarchy of JsonSchemaEncoder
1 string reference to 'JsonSchemaEncoder'
- schemata_json_schema.services.yml in schemata_json_schema/
schemata_json_schema.services.yml - schemata_json_schema/schemata_json_schema.services.yml
1 service uses JsonSchemaEncoder
File
- schemata_json_schema/
src/ Encoder/ JsonSchemaEncoder.php, line 13
Namespace
Drupal\schemata_json_schema\EncoderView source
class JsonSchemaEncoder extends JsonEncoder {
/**
* The formats that this Encoder supports.
*
* @var string
*/
protected $baseFormat = 'schema_json';
/**
* The decorated encoder.
*
* @var \Symfony\Component\Serializer\Encoder\EncoderInterface
*/
protected $innerEncoder;
/**
* Create a JsonSchemaEncoder instance.
*
* @param \Symfony\Component\Serializer\Encoder\EncoderInterface $inner_encoder
*/
public function __construct(EncoderInterface $inner_encoder) {
parent::__construct();
$this->innerEncoder = $inner_encoder;
}
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
$parts = explode(':', $format, 2);
if (count($parts) < 2 || empty($parts[1])) {
// Require sub type.
return FALSE;
}
list($base, $encoded) = $parts;
// Verify the correct base and that the sub type is supported by inner.
return $base === $this->baseFormat && $this->innerEncoder
->supportsEncoding($encoded);
}
/**
* {@inheritdoc}
*/
public function supportsDecoding($format) {
// We don't decode have a decoding system for json_schema.
// @TODO: Implement conversion of json_schema to typed data.
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
JsonEncoder:: |
protected static | property | The formats that this Encoder supports. | |
JsonEncoder:: |
private | function | Instantiates a JsonDecode instance. | |
JsonEncoder:: |
private | function | Instantiates a JsonEncode instance. | |
JsonSchemaEncoder:: |
protected | property | The formats that this Encoder supports. | |
JsonSchemaEncoder:: |
protected | property | The decorated encoder. | |
JsonSchemaEncoder:: |
public | function |
Checks whether the deserializer can decode from given format. Overrides JsonEncoder:: |
|
JsonSchemaEncoder:: |
public | function |
Checks whether the serializer can encode to given format. Overrides JsonEncoder:: |
|
JsonSchemaEncoder:: |
public | function |
Create a JsonSchemaEncoder instance. Overrides JsonEncoder:: |