public function apply()

in src/Facebook/InstantArticles/Transformer/Rules/GlobalRule.php [65:152]


    public function apply($transformer, $instantArticle, $node)
    {
        // Builds the author
        $authorUrl = $this->getProperty(self::PROPERTY_GLOBAL_AUTHOR_URL, $node);
        $authorName = $this->getProperty(self::PROPERTY_GLOBAL_AUTHOR_NAME, $node);
        $authorRoleContribution = $this->getProperty(self::PROPERTY_GLOBAL_AUTHOR_ROLE_CONTRIBUTION, $node);
        $authorDescription = $this->getProperty(self::PROPERTY_GLOBAL_AUTHOR_DESCRIPTION, $node);

        $header = $instantArticle->getHeader();
        if (!$header) {
            $header = Header::create();
            $instantArticle->withHeader($header);
        }

        if ($authorName) {
            $author = Author::create();
            $author->withName($authorName);
            $header->addAuthor($author);

            if ($authorRoleContribution) {
                $author->withRoleContribution($authorRoleContribution);
            }

            if ($authorDescription) {
                $author->withDescription($authorDescription);
            }

            if ($authorUrl) {
                $author->withURL($authorUrl);
            }
        } else {
            $transformer->addWarning(
                new InvalidSelector(
                    self::PROPERTY_GLOBAL_AUTHOR_NAME,
                    $instantArticle,
                    $node,
                    $this
                )
            );
        }

        // Treats title
        $articleTitle = $this->getProperty(self::PROPERTY_GLOBAL_TITLE, $node);
        if ($articleTitle) {
            $header->withTitle($transformer->transform(H1::create(), $articleTitle));
        } else {
            $transformer->addWarning(
                new InvalidSelector(
                    self::PROPERTY_GLOBAL_TITLE,
                    $instantArticle,
                    $node,
                    $this
                )
            );
        }

        // Treats Canonical URL
        $articleCanonicalUrl = $this->getProperty(self::PROPERTY_GLOBAL_CANONICAL_URL, $node);
        if ($articleCanonicalUrl) {
            $instantArticle->withCanonicalURL($articleCanonicalUrl);
        } else {
            $transformer->addWarning(
                new InvalidSelector(
                    self::PROPERTY_GLOBAL_CANONICAL_URL,
                    $instantArticle,
                    $node,
                    $this
                )
            );
        }

        // Treats Time Published
        $timePublished = $this->getProperty(self::PROPERTY_TIME_PUBLISHED, $node);
        if ($timePublished) {
            $header->withTime(Time::create(Time::PUBLISHED)->withDatetime($timePublished));
        }

        // Treats Header Image
        $articleHeaderImageURL = $this->getProperty(self::PROPERTY_GLOBAL_HEADER_IMAGE, $node);
        if ($articleHeaderImageURL) {
            $header->withCover(Image::create()->withURL($articleHeaderImageURL));
        }

        $body = $this->getProperty(self::PROPERTY_GLOBAL_BODY, $node);
        $transformer->transform($instantArticle, $body);

        return $instantArticle;
    }