You are here

class InstantArticleEncoder in Facebook Instant Articles 8.2

Same name and namespace in other branches
  1. 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'
fb_instant_articles.services.yml in ./fb_instant_articles.services.yml
fb_instant_articles.services.yml
1 service uses InstantArticleEncoder
serializer.fb_instant_articles.fbia.encoder in ./fb_instant_articles.services.yml
Drupal\fb_instant_articles\Encoder\InstantArticleEncoder

File

src/Encoder/InstantArticleEncoder.php, line 13

Namespace

Drupal\fb_instant_articles\Encoder
View 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

Namesort descending Modifiers Type Description Overrides
InstantArticleEncoder::$format protected static property The format that this encoder supports.
InstantArticleEncoder::encode public function
InstantArticleEncoder::supportsEncoding public function