PHP Classes

File: src/Highlights/HtmlHighlight.php

Recommend this page to a friend!
  Classes of Rodolfo Berrios Arce   Var-Dump   src/Highlights/HtmlHighlight.php   Download  
File: src/Highlights/HtmlHighlight.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,820 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\Highlights;

use
Chevere\Parameter\Interfaces\TypeInterface;
use
Chevere\VarDump\Highlights\Traits\AssertKeyTrait;
use
Chevere\VarDump\Interfaces\HighlightInterface;
use
Chevere\VarDump\Interfaces\VarDumperInterface;

final class
HtmlHighlight implements HighlightInterface
{
    use
AssertKeyTrait;

    private
string $class;

    public function
__construct(
        private
string $key
   
) {
       
$this->assertKey($key);
       
$this->class = $this->palette()[$this->key] ?? '';
    }

    public function
highlight(string $dump): string
   
{
        return <<<HTML
<span class="chv-dump-{$this->class}">{$dump}</span>
HTML;
    }

   
/**
     * @return array<string, string>
     */
   
public static function palette(): array
    {
        return [
           
TypeInterface::STRING => 'string',
           
TypeInterface::FLOAT => 'float',
           
TypeInterface::INT => 'int',
           
TypeInterface::BOOL => 'bool',
           
TypeInterface::NULL => 'null',
           
TypeInterface::OBJECT => 'object',
           
TypeInterface::ARRAY => 'array',
           
TypeInterface::RESOURCE => 'resource',
           
VarDumperInterface::FILE => 'file',
           
VarDumperInterface::CLASS_REG => 'class',
           
VarDumperInterface::OPERATOR => 'operator',
           
VarDumperInterface::FUNCTION => 'function',
           
VarDumperInterface::VARIABLE => 'variable',
           
VarDumperInterface::MODIFIER => 'modifier',
           
VarDumperInterface::EMPHASIS => 'emphasis',
        ];
    }
}