PHP code example of dillonsmart / tetherphp

1. Go to this page and download the library: Download dillonsmart/tetherphp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dillonsmart / tetherphp example snippets


// routes/web.php
$router->get('/', Actions\Home\Index::class);

// app/Actions/Home/Index.php
class Index extends Action implements ActionInterface
{
    public function __construct(protected Request $request, Services $services)
    {
        $this->domain = new IndexDomain($services->env);
        $this->responder = new IndexResponder($request);
    }

    public function __invoke(): Response
    {
        return $this->respond($this->domain->handle());
    }
}

// app/Domains/Home/Index.php
class Index extends Domain
{
    public function __construct(private readonly Env $env)
    {
    }

    public function handle(): Page
    {
        return new Page(
            name: $this->env->get('APP_NAME', 'TetherPHP'),
            description: 'An application built with TetherPHP.',
        );
    }
}

// app/Responders/Home/Index.php
class Index extends Responder
{
    public function __invoke(Page $result): Response
    {
        return $this->view('pages.home.index', [
            'appName' => $result->name,
            'tagline' => $result->description,
        ]);
    }
}