tobento/service-support

Interfaces and classes for supporting applications.

1.0.3 2025-08-23 05:43 UTC

This package is auto-updated.

Last update: 2025-08-23 05:44:36 UTC


README

The Support Service provides interfaces and classes supporting applications.

Table of Contents

Getting started

Add the latest version of the support service running this command.

composer require tobento/service-support

Requirements

  • PHP 8.0 or greater

Documentation

Interfaces

Arrayable

use Tobento\Service\Support\Arrayable;

interface Arrayable
{
    /**
     * Get the object as an array.
     *
     * @return array
     */
    public function toArray(): array;    
}

Htmlable

use Tobento\Service\Support\Htmlable;

interface Htmlable
{
    /**
     * Get content as a string of HTML.
     *
     * @return string
     */
    public function toHtml(): string;
}

Jsonable

use Tobento\Service\Support\Jsonable;

interface Jsonable
{
    /**
     * Get the object as a JSON string.
     *
     * @param int $options
     * @return string
     */
    public function toJson(int $options = 0): string;    
}

Renderable

use Tobento\Service\Support\Renderable;

interface Renderable
{
    /**
     * Get the evaluated contents of the object.
     *
     * @return string
     */
    public function render(): string;    
}

Responsable

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Tobento\Service\Support\Responsable;

interface Responsable
{
    /**
     * Create a HTTP response that represents the object.
     *
     * @param ServerRequestInterface $request
     * @return ResponseInterface
     */
    public function toResponse(ServerRequestInterface $request): ResponseInterface;    
}

Html String

The HtmlString::class can be useful in certain situations where a string should not be escaped by another function.

use Tobento\Service\Support\HtmlString;

$htmlString = new HtmlString('<h1>foo</h1>');

// you may check if the string is empty or not:
var_dump($htmlString->isEmpty());
// bool(false)

Credits