Вход Регистрация
Файл: vendor/intervention/image/src/Colors/Rgb/Decoders/NamedColorDecoder.php
Строк: 49
<?php

declare(strict_types=1);

namespace 
InterventionImageColorsRgbDecoders;

use 
InterventionImageColorsRgbNamedColor;
use 
InterventionImageInterfacesColorInterface;
use 
InterventionImageInterfacesDecoderInterface;

class 
NamedColorDecoder extends HexColorDecoder implements DecoderInterface
{
    
/**
     * {@inheritdoc}
     *
     * @see DecoderInterface::supports()
     */
    
public function supports(mixed $input): bool
    
{
        if (!
is_string($input)) {
            return 
false;
        }

        return 
$this->stringToColorName($input) === null false true;
    }

    
/**
     * Decode html color names.
     */
    
public function decode(mixed $input): ColorInterface
    
{
        return 
parent::decode($this->stringToColorName($input)?->toHex());
    }

    private function 
stringToColorName(string $input): ?NamedColor
    
{
        return 
NamedColor::tryFrom(strtolower($input));
    }
}
Онлайн: 4
Реклама