duyler/duyler

Maintainers

Details

github.com/duyler/duyler

Source

Issues

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 1

Language:Twig

Type:project

v0.1.1 2024-02-17 10:42 UTC

This package is auto-updated.

Last update: 2024-07-05 00:51:34 UTC


README

Duyler

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

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\Framework\Build\Action\Action;

Action::build(id: 'Page.GetPage', handler: \App\Action\GetPageAction::class)
    ->externalAccess(true)
    ->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\AbstractController;
use Psr\Http\Message\ResponseInterface;

class PageController extends AbstractController
{
    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\Method;

Controller::build(PageController::class)
    ->contracts([Page::class])
    ->attributes(
        new Route(
            method: Method::Get,
            pattern: 'page',
        ),
    );

contract Page will be received automatically

make rebuild

Open http://localhost/page