CoreFiles by mySites.guru
JsonHtml.php68 lines, 1,384 bytes, from Joomla_5.0.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 5.0.0-alpha1
md5
d19446005cb51569378da6c6ec670d74
sha1
0675046d2272e43b2a10480fb06f6c1579f85ea4
sha256
ba15f595c3ae3f2a11dc319f92069d1bcc64081c4d9573c6181697428529748b
<?php

declare(strict_types=1);

namespace Jfcherng\Diff\Renderer\Html;

use Jfcherng\Diff\SequenceMatcher;

/**
 * HTML Json diff generator.
 */
class JsonHtml extends AbstractHtml
{
    /**
     * {@inheritdoc}
     */
    public const INFO = [
        'desc' => 'HTML Json',
        'type' => 'Html',
    ];

    /**
     * {@inheritdoc}
     */
    public const IS_TEXT_RENDERER = true;

    /**
     * {@inheritdoc}
     */
    public function getResultForIdenticalsDefault(): string
    {
        return '[]';
    }

    /**
     * {@inheritdoc}
     */
    protected function redererChanges(array $changes): string
    {
        if ($this->options['outputTagAsString']) {
            $this->convertTagToString($changes);
        }

        return json_encode($changes, $this->options['jsonEncodeFlags']);
    }

    /**
     * Convert tags of changes to their string form for better readability.
     *
     * @param array[][] $changes the changes
     */
    protected function convertTagToString(array &$changes): void
    {
        foreach ($changes as &$hunks) {
            foreach ($hunks as &$block) {
                $block['tag'] = SequenceMatcher::opIntToStr($block['tag']);
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function formatStringFromLines(string $string): string
    {
        return $this->htmlSafe($string);
    }
}

The same content is in 23 releases, Joomla 5.0.0-alpha1 to 5.1.0-beta1. See them all, or every version of this file.