duyler/duyler

Maintainers

Details

github.com/duyler/duyler

Source

Issues

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Language:Twig

Type:project

dev-master 2024-10-19 10:45 UTC

This package is auto-updated.

Last update: 2024-10-19 10:45:19 UTC


README

PHP Version

Event-driven architecture framework

Get started

Install with included docker config and without host php interpreter

curl -L -O https://github.com/duyler/duyler/archive/refs/heads/master.zip
unzip master.zip -d duyler
cd duyler
make build
make up

For show all available commands

make help

Install using local composer

composer create-project duyler/duyler
cd duyler
make up

Open http://localhost/

Create contract

// src/Contract/Page.php

<?php

declare(strict_types=1);

namespace App\Contact;

readonly class Page
{
    public function __construct(
        public string $title,
        public string $content,
    ) {}
}

Create action

// src/Action/GetPageAction.php

<?php

declare(strict_types=1);

namespace App\Action;

use App\Contract\Page;

class GetPageAction
{
    public function __invoke(): Page
    {
        return new Page(
            title: 'Home',
            content: 'Hello, World!',
        );
    }
}
// build/actions.php

<?php

declare(strict_types=1);

use Duyler\Builder\Build\Action\Action;

Action::create(id: 'Page.GetPage')
    ->handler(handler: \App\Action\GetPageAction::class)
    ->contract(\App\Contract\Page::class);

Create controller

// src/Controller/PageController

<?php

declare(strict_types=1);

namespace App\Controller;

use App\Contract\Page;
use Duyler\Web\Controller\BaseController;
use Psr\Http\Message\ResponseInterface;

class PageController extends BaseController
{
    public function __invoke(Page $page): ResponseInterface
    {
        return $this->json($page);
    }
}
// build/controllers.php

<?php

declare(strict_types=1);

use App\Controller\PageController;
use App\Contract\Page;
use Duyler\Web\Build\Attribute\Route;
use Duyler\Web\Build\Controller;
use Duyler\Web\Enum\HttpMethod;

Controller::build(PageController::class)
    ->actions(
        'Page.GetPage',
    )
    ->attributes(
        new Route(
            method: HttpMethod::Get,
            pattern: 'page',
        ),
    );

contract Page will be received automatically

make restart

Open http://localhost/page