PHPackages                             fabricio872/api-modeller-bundle - 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. [API Development](/categories/api)
4. /
5. fabricio872/api-modeller-bundle

ActiveSymfony-bundle[API Development](/categories/api)

fabricio872/api-modeller-bundle
===============================

Symfony bundle for translating foreign API to Doctrine-like models

v0.0.8(4y ago)02.7kMITPHPPHP ^7.4|^8.0

Since Nov 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/Fabricio872/api-modeller-bundle)[ Packagist](https://packagist.org/packages/fabricio872/api-modeller-bundle)[ RSS](/packages/fabricio872-api-modeller-bundle/feed)WikiDiscussions main Synced today

READMEChangelog (8)Dependencies (6)Versions (9)Used By (0)

[![GitHub tag (latest by date)](https://camo.githubusercontent.com/0429b8464cc64760ffda5af7fc45571e81bd590d41969a29cd0125dfee29d201/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c65)](https://camo.githubusercontent.com/0429b8464cc64760ffda5af7fc45571e81bd590d41969a29cd0125dfee29d201/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c65)[![GitHub last commit](https://camo.githubusercontent.com/16d6cb0318baa6dba2e02b65f71ad9c7947269c0b49afb811db6c8689b422f05/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c65)](https://camo.githubusercontent.com/16d6cb0318baa6dba2e02b65f71ad9c7947269c0b49afb811db6c8689b422f05/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c65)[![PHP Composer Test and Tag](https://github.com/Fabricio872/api-modeller-bundle/actions/workflows/php-composer.yml/badge.svg)](https://github.com/Fabricio872/api-modeller-bundle/actions/workflows/php-composer.yml)[![Packagist Downloads](https://camo.githubusercontent.com/d6963fb864f2ad268fc3b586548940d2ca1e58f0938287ebc699cf8dc952080e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f466162726963696f3837322f6170692d6d6f64656c6c6572)](https://camo.githubusercontent.com/d6963fb864f2ad268fc3b586548940d2ca1e58f0938287ebc699cf8dc952080e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f466162726963696f3837322f6170692d6d6f64656c6c6572)[![GitHub Repo stars](https://camo.githubusercontent.com/4bf465dd4e2975d041d57d8f9a7b60138cd3d38fe25ac4f213d34c05f024322e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c653f7374796c653d736f6369616c)](https://camo.githubusercontent.com/4bf465dd4e2975d041d57d8f9a7b60138cd3d38fe25ac4f213d34c05f024322e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f466162726963696f3837322f6170692d6d6f64656c6c65722d62756e646c653f7374796c653d736f6369616c)

Valuable partners:

[![PhpStorm logo](https://camo.githubusercontent.com/1e31d98d23a59aa7fddbdae1155126adeac9ad6cded9a478fc8c5d377942c433/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f50687053746f726d2e737667)](https://camo.githubusercontent.com/1e31d98d23a59aa7fddbdae1155126adeac9ad6cded9a478fc8c5d377942c433/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f50687053746f726d2e737667)

Installation
============

[](#installation)

Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md)of the Composer documentation.

Applications that use Symfony Flex
----------------------------------

[](#applications-that-use-symfony-flex)

Open a command console, enter your project directory and execute:

```
$ composer require fabricio872/api-modeller-bundle
```

Applications that don't use Symfony Flex
----------------------------------------

[](#applications-that-dont-use-symfony-flex)

### Step 1: Download the Bundle

[](#step-1-download-the-bundle)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require fabricio872/api-modeller-bundle
```

### Step 2: Enable the Bundle

[](#step-2-enable-the-bundle)

Then, enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project:

```
// config/bundles.php

return [
    // ...
    Fabricio872\ApiModeller\ApiModellerBundle::class => ['all' => true],
];
```

Usage
=====

[](#usage)

> This bundle uses models with Annotations similar to Doctrine Entities.
>
> Usually they are in a directory `src/ApiModels` but they are not required to be there as long as they have correct namespace

Example model with single Resource
----------------------------------

[](#example-model-with-single-resource)

This is example of a model for receiving list of users from some API

```
// src/ApiModels/Users.php

use Fabricio872\ApiModeller\Annotations\Resource;

/**
 * @Resource(
 *     endpoint="{{api_url}}/api/users",
 *     method="GET",
 *     type="json",
 *     options={
 *          "headers"={
 *              "accept"= "application/json"
 *          }
 *     }
 * )
 */
class Users
{
    public $page;
    public $per_page;
    public $total;
    public $total_pages;
    public $data;
}
```

> endpoint parameter is endpoint which will be called.
>
> The variable `{{api_url}}` is Twig global variable configured in twig config (example in [Global variables configuration](#global-variables-configuration) section)

> method parameter is method with which the request will be done
>
> default: `GET`

> type parameter defines format of the received data
>
> currently supported: `json`, `"xml'`
>
> default: `json`

> options parameter is array that is directly passed (but can be altered as explained in [setOptions](#setoptions) section) to [symfony/http-client](https://github.com/symfony/http-client) request method as 3. parameter so use [this documentation](https://symfony.com/doc/current/http_client.html)

Example model with multiple Resources
-------------------------------------

[](#example-model-with-multiple-resources)

To define multiple resources you need to wrap multiple Resource annotation into single Resources annotation with identifier at beginning. This identifier is then used while calling this endpoint as described in section [setIdentifier](#setidentifier)

```
// src/ApiModels/Users.php

use Fabricio872\ApiModeller\Annotations\Resource;
use Fabricio872\ApiModeller\Annotations\Resources;

/**
 * @Resources({
 *      "multiple"= @Resource(
 *          endpoint="{{api_url}}/api/users",
 *          method="GET",
 *          type="json",
 *          options={
 *              "headers"={
 *                  "accept"= "application/json"
 *              }
 *          }
 *      ),
 *      "single"= @Resource(
 *          endpoint="{{api_url}}/api/users/{{id}}",
 *          method="GET",
 *          type="json",
 *          options={
 *              "headers"={
 *                  "accept"= "application/json"
 *              }
 *          }
 *      ),
 * })
 */
class Users
{
    public $page;
    public $per_page;
    public $total;
    public $total_pages;
    public $data;
}
```

Global variables configuration
------------------------------

[](#global-variables-configuration)

```
# config/packages/twig.yaml

twig:
    ...
    globals:
        api_url: 'https://reqres.in'
```

Calling the API
---------------

[](#calling-the-api)

> This bundle can be initialized from symphony's dependency container so in your controller you can call it like this:

### Calling with single resource

[](#calling-with-single-resource)

This controller dumps model or collection of models form [this example](#example-model-with-single-resource) with namespace Users::class and sets query parameter `page` to 2

```
// src/Controller/SomeController.php

    /**
     * @Route("/", name="some_controller")
     */
    public function index(Modeller $modeller): Response
    {
        dump($modeller->getData(
            Repo::new(Users::class)
                ->setOptions([
                    "query" => [
                        "page" => 2
                    ]
                ])
        ));

        return $this->render('some_controller/index.html.twig', [
            'controller_name' => 'SomeController',
        ]);
    }
```

### Calling with multiple resources

[](#calling-with-multiple-resources)

This controller dumps model or collection of models form [this example](#example-model-with-multiple-resources) with namespace `Users::class`and fills the `{{id}}` variable from model with number 2

noticed that now method setIdentifier is required

```
// src/Controller/SomeController.php

    /**
     * @Route("/", name="some_controller")
     */
    public function index(Modeller $modeller): Response
    {
        dump($modeller->getData(
            Repo::new(Users::class)
                ->setParameters([
                    "id" => 2
                ])
                ->setIdentifier("single")
        ));

        return $this->render('some_controller/index.html.twig', [
            'controller_name' => 'SomeController',
        ]);
    }
```

> The modeller accepts Repo object which requires namespace of model you want to build and has optional setters:
>
> - `setOptions()`
> - `setParameters()`
> - `setIdentifier()`

### setOptions

[](#setoptions)

This method accepts array of options that will be merged with options configured in a model (and will override overlapped parameters) to [symfony/http-client](https://github.com/symfony/http-client) request method as 3. parameter so use [this documentation](https://symfony.com/doc/current/http_client.html)

### setParameters

[](#setparameters)

This method accepts array and sets twig variables (same as if you render a template but here the template is endpoint parameter from model) to url configuration and can override global twig variables

### setIdentifier

[](#setidentifier)

This method is required in case when you use multiple Resources for single model as shown in [this example](#example-model-with-multiple-resources)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~30 days

Recently: every ~42 days

Total

8

Last Release

1472d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/29705379?v=4)[Fabricio872](/maintainers/Fabricio872)[@Fabricio872](https://github.com/Fabricio872)

---

Top Contributors

[![Fabricio872](https://avatars.githubusercontent.com/u/29705379?v=4)](https://github.com/Fabricio872 "Fabricio872 (10 commits)")

---

Tags

apisymfonylibrarymodelSymfony Bundle

###  Code Quality

Code StyleECS

### Embed Badge

![Health badge](/badges/fabricio872-api-modeller-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/fabricio872-api-modeller-bundle/health.svg)](https://phpackages.com/packages/fabricio872-api-modeller-bundle)
```

PHPackages © 2026

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