PHPackages                             ddruganov/yii2-api-essentials - 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. ddruganov/yii2-api-essentials

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ddruganov/yii2-api-essentials
=============================

Bunch of components to make one's development life eaisier

1.0.11(4y ago)0482PHP

Since Feb 4Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ddruganov/yii2-api-essentials)[ Packagist](https://packagist.org/packages/ddruganov/yii2-api-essentials)[ RSS](/packages/ddruganov-yii2-api-essentials/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (13)Used By (2)

yii2-api-essentials
===================

[](#yii2-api-essentials)

Bunch of small components to make one's yii2 api development life eaiser

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

[](#installation)

`composer require ddruganov/yii2-api-essentials`

Description
-----------

[](#description)

This package contains useful classes (filters, behaviors, helpers, etc) for api development:

- `behaviors\TimestampBehavior`: provides basic timestamping of an active record model with fields being 'created\_at' and 'updated\_at' (detects their existence automatically)
- `collectors\AbstractDataCollector`: a convient way to collect data for an api call
- `exceptions\ModelNotFoundException`: when a search for a model in database fails
- `exceptions\NotImplementedException`: when you need to write an implementation for a method but... later :D
- `forms\Form`: a container that performs validation of data and manipulates in a certain way; super useful for creating models without directly using an ActiveRecord; also used as a base for data collectors
- `http\actions\ApiAction`: base class for all api actions that provides a way to get all incoming data as one array; returns an `ExecutionResult` and a status code appropriate for that execution result;
- `http\actions\ClosureAction`: when the `ApiModelAction` is too overkill
- `http\actions\FormAction`: provides a way to separate validation and saving of data to reduce class bloat; uses `Form`
- `http\controllers\ApiController`: returns everything as json, measures every request timing and makes all api calls transactional
- `http\filters\TimerFilter`: measures the time that an action takes and dumps into the debug log
- `http\filters\TransactionFilter`: starts transaction before action, ends it after action; depends on `ExecutionResult` being successful
- `testing\UnitTest`: base unit test class; provides a convenient way to assert `ExecutionResult` state and a customizable faker generator
- `traits\Activity`: used in `ActiveQuery` to only get active models
- `traits\Pagination`: used in `ActiveQuery` to set a page in a list query and to get a page count
- `traits\Sorting`: used in `ActiveQuery` to sort models; deafult field is `created_at`
- `traits\SoftDelete`: used in `ActiveRecord`, when a model is deleted the `deleted_at` field is filled with `date('Y-m-d H:i:s')`
- `DateHelper`: bunch of useful methods for date manipulation
- `ExecutionResult`: basically a statically typed version of an array with a specific structure to ensure that all methods working with data return the same structure, but not limited to that

ApiController example
---------------------

[](#apicontroller-example)

```
class TestController extends ApiController
{
    public function actions()
    {
        return [
            'test1' => [
                'class' => ClosureAction::class,
                'closure' => function () {
                    Yii::debug('this is a closure action');
                    return ExecutionResult::success();
                }
            ],
            'test2' => [
                'class' => FormAction::class,
                'formClass' => TestCollector::class
            ],
            'test3' => [
                'class' => FormAction::class,
                'formClass' => TestForm::class
            ]
        ];
    }
}
```

`TestCollector` and `TestForm` extend the `forms\Form`

ActiveQuery traits example
--------------------------

[](#activequery-traits-example)

```
class SomeModelQuery extends ActiveQuery {
    use Activity, Pagination, Sorting;
}
```

ActiveRecord-related components example
---------------------------------------

[](#activerecord-related-components-example)

```
class SomeActiveRecord extends ActiveRecord {

    use SoftDelete;

    public function behaviors() {
        return [TimestampBehavior::class];
    }
}
```

Form example
------------

[](#form-example)

```
class SomeModelCreationForm extends Form {
    public ?string $name = null;
    public ?array $someRelatedModelIds = null;

    public function rules() {
        return [
            [['name','someRelatedModelIds'],'required'],
            [['name'],'string'],
            [['someRelatedModelIds'],'each', 'rule' => ['integer']]
        ];
    }

    protected function _run(): ExecutionResult {
        $model = new SomeModel();
        $model->setAttributes(['name' => $this->name]);
        if (!$model->save()) {
            return ExecutionResult::exception('Error saving model');
        }

        $result = $this->saveRelatedModelIds($model);
        if (!$result->isSuccessful()){
            return $result;
        }

        return ExecutionResult::success([
            'id' => $model->getId()
        ]);
    }

    private function saveRelatedModelIds(SomeModel $model) {
        ... bind related model ids here
    }
}
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

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

Total

12

Last Release

1528d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b68509a8d66d630b4f6a4faef3a5cb2cbea6b5c78321cc6940aa78554a95a27a?d=identicon)[ddruganov](/maintainers/ddruganov)

---

Top Contributors

[![ddruganov](https://avatars.githubusercontent.com/u/12191677?v=4)](https://github.com/ddruganov "ddruganov (32 commits)")

### Embed Badge

![Health badge](/badges/ddruganov-yii2-api-essentials/health.svg)

```
[![Health](https://phpackages.com/badges/ddruganov-yii2-api-essentials/health.svg)](https://phpackages.com/packages/ddruganov-yii2-api-essentials)
```

###  Alternatives

[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15312.0M36](/packages/magento-magento2-functional-testing-framework)[verbb/formie

The most user-friendly forms plugin for Craft.

102393.6k60](/packages/verbb-formie)[solspace/craft-freeform

The most flexible and user-friendly form building plugin!

54681.3k17](/packages/solspace-craft-freeform)[blackfire/player

A powerful web crawler and web scraper with Blackfire support

49517.1k](/packages/blackfire-player)[directorytree/dummy

439.9k](/packages/directorytree-dummy)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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