class InstantArticleEncoder in Facebook Instant Articles 8.2
Same name and namespace in other branches
- 3.x src/Encoder/InstantArticleEncoder.php \Drupal\fb_instant_articles\Encoder\InstantArticleEncoder
Facebook Instant Article encoder class.
Takes a \Facebook\InstantArticles\Elements\InstantArticle object and encodes it as a string.
Hierarchy
- class \Drupal\fb_instant_articles\Encoder\InstantArticleEncoder implements \Symfony\Component\Serializer\Encoder\EncoderInterface
Expanded class hierarchy of InstantArticleEncoder
1 string reference to 'InstantArticleEncoder'
1 service uses InstantArticleEncoder
File
- src/
Encoder/ InstantArticleEncoder.php, line 13
Namespace
Drupal\fb_instant_articles\EncoderView source
class InstantArticleEncoder implements EncoderInterface {
/**
* The format that this encoder supports.
*
* @var string
*/
protected static $format = 'fbia';
/**
* {@inheritdoc}
*/
public function supportsEncoding($format) {
return $format === static::$format;
}
/**
* {@inheritdoc}
*/
public function encode($data, $format, array $context = []) {
// This encoder strictly supports only a single Instant Article object.
if (is_array($data)) {
$data = reset($data);
}
/** @var \Facebook\InstantArticles\Elements\InstantArticle $data */
return $data
->render();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InstantArticleEncoder:: |
protected static | property | The format that this encoder supports. | |
InstantArticleEncoder:: |
public | function | ||
InstantArticleEncoder:: |
public | function |