public static function escape($string)
    {
        Arguments::define(
            Boa::either(
                Boa::either(
                    Boa::instance(SafeHtmlWrapper::class),
                    Boa::instance(SafeHtmlProducerInterface::class)
                ),
                Boa::string()
            )
        )->check($string);

        if ($string instanceof SafeHtmlWrapper) {
            return $string;
        } elseif ($string instanceof SafeHtmlProducerInterface) {
            $result = $string->getSafeHtml();

            if ($result instanceof SafeHtmlWrapper) {
                return $result;
            } elseif ($result instanceof SafeHtmlProducerInterface) {
                return static::escape($result);
            }

            throw new CoreException(vsprintf(
                'Object of class %s implements SafeHtmlProducerInterface'
                . ' but it returned an unsafe type: %s',
                [get_class($string), TypeHound::fetch($result)]
            ));
        }

        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
    }
public static function escape($string)
    {
        Arguments::define(
            Boa::either(
                Boa::either(
                    Boa::instance(SafeHtmlWrapper::class),
                    Boa::instance(SafeHtmlProducerInterface::class)
                ),
                Boa::string()
            )
        )->check($string);

        if ($string instanceof SafeHtmlWrapper) {
            return $string;
        } elseif ($string instanceof SafeHtmlProducerInterface) {
            $result = $string->getSafeHtml();

            if ($result instanceof SafeHtmlWrapper) {
                return $result;
            } elseif ($result instanceof SafeHtmlProducerInterface) {
                return static::escape($result);
            }

            throw new CoreException(vsprintf(
                'Object of class %s implements SafeHtmlProducerInterface'
                . ' but it returned an unsafe type: %s',
                [get_class($string), TypeHound::fetch($result)]
            ));
        }

        return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
    }
public static function escape ( $ string ) { Arguments :: define ( Boa :: either ( Boa :: either ( Boa :: instance ( SafeHtmlWrapper :: class ) , Boa :: instance ( SafeHtmlProducerInterface :: class ) ) , Boa :: string ( ) ) ) -> check ( $ string ) ; if ( $ string instanceof SafeHtmlWrapper ) { return $ string ; } elseif ( $ string instanceof SafeHtmlProducerInterface ) { $ result = $ string -> getSafeHtml ( ) ; if ( $ result instanceof SafeHtmlWrapper ) { return $ result ; } elseif ( $ result instanceof SafeHtmlProducerInterface ) { return static :: escape ( $ result ) ; } throw new CoreException ( vsprintf ( 'Object of class %s implements SafeHtmlProducerInterface' . ' but it returned an unsafe type: %s' , [ get_class ( $ string ) , TypeHound :: fetch ( $ result ) ] ) ) ; } return htmlspecialchars ( $ string , ENT_QUOTES , 'UTF-8' ) ; }
Escape the provided string.

@param SafeHtmlWrapper|SafeHtmlProducerInterface|string $string

@throws CoreException
@throws InvalidArgumentException
@return SafeHtmlWrapper|string
Escape the provided string .