PHP Classes

File: src/Formats/HtmlFormat.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Var-Dump   src/Formats/HtmlFormat.php   Download  
File: src/Formats/HtmlFormat.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Var-Dump
Show the value of a variable in colored way
Author: By
Last change:
Date: 18 days ago
Size: 1,737 bytes
 

Contents

Class file image Download
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace
Chevere\VarDump\Formats;

use
Chevere\VarDump\Highlights\HtmlHighlight;
use
Chevere\VarDump\Interfaces\FormatInterface;
use
Chevere\VarDump\Interfaces\VarDumperInterface;

class
HtmlFormat implements FormatInterface
{
    public const
HTML_INLINE_PREFIX = '<span class="chv-dump-inline"></span>';

    public const
HTML_EMPHASIS = '<em>%s</em>';

    public const
HTML_DETAILS_OPEN = '<details class="chv-dump-details"%s>';

    public const
HTML_DETAILS_CLOSE = '</details>';

    public const
HTML_SUMMARY = '<summary class="chv-dump-summary"></summary>';

    public function
indent(int $indent): string
   
{
       
// @infection-ignore-all
       
return str_repeat(' ' . self::HTML_INLINE_PREFIX . ' ', $indent);
    }

    public function
emphasis(string $string): string
   
{
        return
sprintf(
           
self::HTML_EMPHASIS,
            (new
HtmlHighlight(VarDumperInterface::EMPHASIS))
                ->
highlight($string)
        );
    }

    public function
filterEncodedChars(string $string): string
   
{
        return
htmlspecialchars($string);
    }

    public function
highlight(string $key, string $string): string
   
{
        return (new
HtmlHighlight($key))->highlight($string);
    }

    public function
detailsOpen(bool $open): string
   
{
        return
sprintf(self::HTML_DETAILS_OPEN, $open ? ' open' : '') . self::HTML_SUMMARY;
    }

    public function
detailsClose(): string
   
{
        return
self::HTML_DETAILS_CLOSE;
    }
}