assegaiphp/attributes

A small library defining the core attributes of the AssegaiPHP framework.

10.1 2025-02-02 18:41 UTC

This package is auto-updated.

Last update: 2025-02-02 18:44:43 UTC


README

Assegai Logo

A progressive PHP framework for building effecient and scalable server-side applications.

Description

The attributes library is a collection of common PHP 8 attributes that can be used in your Assegai application.

Installation

You can install the package via composer:

$ composer require assegaiphp/attributes

Usage

Use the Injectable attribute to mark a class as injectable.

<?php

use Assegai\Attributes\Injectable;

#[Injectable]
class MyService {
  public function __construct() {
    // Do something
  }
}

Then you can use your service in your application like this:

<?php

use Assegai\Attributes\Controller;
use Assegai\Core\Attributes\Http\Get;
use Assegai\Core\Attributes\Param;

#[Controller('my-controller')]
class MyController
{
    public function __construct(protected MyService $myService) {
    }
    
    #[Get]
    public function findAll(): array {
       return $this->myService->findAll();
    }
    
    #[Get(':id')]
    public function findById(#[Param('id')] int $id) {
      return $this->myService->findById($id);
    }
}