PHPackages                             gdnacho/poob - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gdnacho/poob

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

gdnacho/poob
============

Input/Output DTO generator, validator, and OpenAPI docs generator.

1.2.1(2mo ago)019↓90%MITPHPPHP ^8.2

Since Mar 30Pushed 2mo agoCompare

[ Source](https://github.com/GDNacho/poob)[ Packagist](https://packagist.org/packages/gdnacho/poob)[ RSS](/packages/gdnacho-poob/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (18)Versions (11)Used By (0)

Poob
====

[](#poob)

**Poob** – Input/Output DTO generator, validator, and OpenAPI docs generator.

Quickly create Input DTOs, Output DTOs, and Field definitions using Symfony Validator. Input DTOs are automatically validated through a value resolver, as well as OpenAPI docs generation.

The goal is to provide a less opinionated micro-framework than API Platform, and a bundle like Nelmio/ApiDocBundle without the annotation boilerplate.

---

Features
--------

[](#features)

- Generate Input DTOs (`poob:make:input-dto `)
- Generate Output DTOs (`poob:make:output-dto `)
- Generate Field definitions (`poob:make:field `)
- Automatic request validation using a value resolver (`RequestInputResolver`)
- Organizes generated classes under `/src/Api`:
    - `/InputDto`
    - `/OutputDto`
    - `/Field`
- Generate API docs (`poob:make:docs`)

---

Installation
------------

[](#installation)

Add Poob to your Symfony project via Composer:

```
composer require gdnacho/poob
```

Then initialize (This will create the directories /src/Api and /config/packages/poob\_api.yaml):

```
php bin/console poob:init
```

Usage
-----

[](#usage)

### Controller

[](#controller)

```
use App\Api\InputDto\UsernameInput;
use App\Api\OutputDto\UsernameOutput;
use App\Repository\UserRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;

#[Route('/api/users', name: 'app_user_get')]
public function getUser(
    UsernameInput $data,
    UserRepository $userRepository
): JsonResponse {
    // Find the user entity using the input DTO
    $user = $userRepository->findOneBy(['username' => $data->username]);

    // Return a response DTO, serialized to JSON automatically
    return $this->json(
        $user ? UsernameOutput::from($user) : ['error' => 'User not found']
    );
}
```

- `$data` is automatically populated from the request and validated, using the UsernameInput DTO.
    - For GET requests, Poob reads the query parameters.
    - For POST, PUT, PATCH, or other request methods, Poob parses and validates the JSON request body.
- If validation fails, the value resolver throws a `ValidationException`, which can be handled by an event listener.
- The `from()` method from the Output DTO takes any object and serializes it. This example, thus, responds:

```
{
    "username": "string"
}
```

Optionally, you can also map requests directly to an unvalidated array if the parameter is named `$requestData`:

```
public function getUser(
    array $requestData,
    UserRepository $userRepository
): JsonResponse {
}
```

### Input DTO

[](#input-dto)

```
// src/Api/InputDto/UsernameInput.php
class UsernameInput
{
    #[Field\UsernameField]
    public $username;

    /**
     * This method runs after attribute validation and allows
     * implementing custom logic that depends on multiple fields, or mutate data as needed.
     */
    public function extra(): void
    {
    }
}
```

### Field

[](#field)

```
// src/Api/Field/UsernameField.php
#[\Attribute]
class UsernameField extends Assert\Compound
{
    protected function getConstraints(array $options): array
    {
        return [
            new Assert\NotBlank(),
            new Assert\Type('string'),
            new Assert\Length(min: 2, max: 24),
            new Assert\Regex(
                pattern: '/^[A-Za-z0-9_]+$/',
                message: 'Username may only contain letters, numbers, and underscores.'
            ),
        ];
    }
}
```

### Output DTO

[](#output-dto)

```
// src/Api/OutputDto/UsernameOutput.php
class UsernameOutput extends OutputDto
{
    public function __construct(
        public $username,
    ) {
    }
}
```

#### Output DTO Helpers

[](#output-dto-helpers)

All Output DTOs should extend OutputDto. This provides two convenient static methods:

- `from(object $source): static`: Creates a new DTO from any object, such as entities.
- `collection(iterable $items): array`: Converts a list of objects into an array of DTOs. Uses from() internally for each item.

API Docs generation
-------------------

[](#api-docs-generation)

You may generate rudimentary OpenAPI documentation for your API with the `poob:make:docs` command. Poob will scan all your routes (With a prefix of `/api` by default) and Input DTOs schema and validation rules to generate it. $ref is not yet supported.

You can configure your API docs in `config/packages/poob_api.yaml`:

```
poob:
  docs:
    title: 'Poob API'
    version: '1.0.0'
    description: ''

    servers:
      - url: 'http://localhost:8000'
        description: 'Local'
      - url: 'https://api.example.com'
        description: 'Production'

    default_responses:
      '200':
        description: OK

    path_prefix: '/api'
    output: '%kernel.project_dir%/openapi.yaml'
```

### Description &amp; Summary attributes

[](#description--summary-attributes)

You may use these attributes atop controllers for the API docs generation:

```
#[Route('/api/user/{id}', methods: ['GET'], name: 'app_user_get')]
#[Summary('Get user')] // Adds a summary
public function get(string $id, ListUserInput $data): JsonResponse
```

You can also use description for properties in InputDTOs:

```
class CreateUserInput extends InputDto
{
    #[Field\UsernameField]
    #[Description('Username must be 3-24 characters long')] // Adds a description
    public string $username;
}
```

Full CRUD controller example
----------------------------

[](#full-crud-controller-example)

```
final class UserController extends AbstractController
{
    public function __construct(
        private UserRepository $repo,
    ) {
    }

    #[Route('/api/user/{id}', methods: ['GET'], name: 'app_user_get')]
    #[Summary('Get user')]
    public function get(string $id, ListUserInput $data): JsonResponse
    {
        $user = $this->repo->find($id);
        if (!$user) {
            return $this->json(['error' => 'Not found'], 404);
        }

        return $this->json(ListUserOutput::from($user));
    }

    #[Route('/api/user', methods: ['GET'], name: 'app_user_list')]
    #[Summary('List user')]
    public function list(ListUserInput $data): JsonResponse
    {
        $users = $this->repo->findByFilters($data);

        return $this->json(ListUserOutput::collection($users));
    }

    #[Route('/api/user', methods: ['POST'], name: 'app_user_create')]
    #[Summary('Create user')]
    public function create(CreateUserInput $data, EntityManagerInterface $em): JsonResponse
    {
        $user = new User();
        $user->setUsername($data->username);
        $user->setAge($data->age);
        $user->setEmail($data->email ?? null);

        $em->persist($user);
        $em->flush();

        return $this->json(CreateUserOutput::from($user), 201);
    }

    #[Route('/api/user/{id}', methods: ['PATCH'], name: 'app_user_update')]
    #[Summary('Update user')]
    public function update(string $id, UpdateUserInput $data, EntityManagerInterface $em): JsonResponse
    {
        $user = $this->repo->find($id);
        if (!$user) {
            return $this->json(['error' => 'Not found'], 404);
        }

        if ($data->username !== null) $user->setUsername($data->username);
        if ($data->age !== null) $user->setAge($data->age);
        if ($data->email !== null) $user->setEmail($data->email);
        $em->flush();

        return $this->json(CreateUserOutput::from($user));
    }

    #[Route('/api/user/{id}', methods: ['DELETE'], name: 'app_user_delete')]
    #[Summary('Delete user')]
    public function delete(string $id, EntityManagerInterface $em): JsonResponse
    {
        $user = $this->repo->find($id);
        if (!$user) {
            return $this->json(['error' => 'Not found'], 404);
        }

        $em->remove($user);
        $em->flush();

        return $this->json('', 204);
    }
}
```

Contributing
------------

[](#contributing)

Poob is just a small package with not a lot of thought put into it, mostly for me to use in my own projects. Regardless, contributions as small as just submitting issues are welcome.

*"u gota get a groov!!!"*

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance85

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

10

Last Release

79d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/58c991600b0767a5d76d0b18cb199e47f0ccd254af5c8145156e29ec6dcba971?d=identicon)[gdnacho](/maintainers/gdnacho)

---

Top Contributors

[![GDNacho](https://avatars.githubusercontent.com/u/51422057?v=4)](https://github.com/GDNacho "GDNacho (15 commits)")

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/gdnacho-poob/health.svg)

```
[![Health](https://phpackages.com/badges/gdnacho-poob/health.svg)](https://phpackages.com/packages/gdnacho-poob)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M521](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)[chameleon-system/chameleon-base

The Chameleon System core.

1027.9k4](/packages/chameleon-system-chameleon-base)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
