PHPackages                             kachnitel/datasource-contracts - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. kachnitel/datasource-contracts

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

kachnitel/datasource-contracts
==============================

Interfaces and value objects defining the DataSource contract for admin-style list views

032↑1493.8%PHP

Since Mar 14Pushed 1mo agoCompare

[ Source](https://github.com/kachnitel/datasource-contracts)[ Packagist](https://packagist.org/packages/kachnitel/datasource-contracts)[ RSS](/packages/kachnitel-datasource-contracts/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

kachnitel/datasource-contracts
==============================

[](#kachniteldatasource-contracts)

Interfaces and value objects defining the DataSource contract for admin-style list views. Zero framework dependencies — pure PHP.

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

[](#installation)

```
composer require kachnitel/datasource-contracts
```

Implementing a custom data source
---------------------------------

[](#implementing-a-custom-data-source)

```
use Kachnitel\DataSourceContracts\ColumnMetadata;
use Kachnitel\DataSourceContracts\DataSourceInterface;
use Kachnitel\DataSourceContracts\FilterMetadata;
use Kachnitel\DataSourceContracts\FlatColumnGroupsTrait;
use Kachnitel\DataSourceContracts\PaginatedResult;

class ApiProductDataSource implements DataSourceInterface
{
    use FlatColumnGroupsTrait; // satisfies getColumnGroups() for non-grouped sources

    public function getIdentifier(): string { return 'api-products'; }
    public function getLabel(): string { return 'API Products'; }
    public function getIcon(): ?string { return 'cloud'; }

    public function getColumns(): array
    {
        return [
            'id'     => ColumnMetadata::create('id', 'ID', 'integer'),
            'name'   => ColumnMetadata::create('name'),
            'status' => ColumnMetadata::create('status'),
        ];
    }

    public function getFilters(): array
    {
        return [
            'name'   => FilterMetadata::text('name', 'Name'),
            'status' => FilterMetadata::enum('status', ['active', 'inactive']),
        ];
    }

    public function getDefaultSortBy(): string { return 'id'; }
    public function getDefaultSortDirection(): string { return 'DESC'; }
    public function getDefaultItemsPerPage(): int { return 25; }

    public function query(
        string $search, array $filters,
        string $sortBy, string $sortDirection,
        int $page, int $itemsPerPage,
    ): PaginatedResult {
        // call your API or DB ...
        return new PaginatedResult(items: $results, totalItems: $total, currentPage: $page, itemsPerPage: $itemsPerPage);
    }

    public function supportsAction(string $action): bool
    {
        return in_array($action, ['index', 'show'], true);
    }

    public function find(string|int $id): ?object { /* ... */ }
    public function getIdField(): string { return 'id'; }
    public function getItemId(object $item): string|int { return $item->id; }
    public function getItemValue(object $item, string $field): mixed { return $item->{$field} ?? null; }
}
```

Composite columns
-----------------

[](#composite-columns)

```
use Kachnitel\DataSourceContracts\ColumnGroup;

public function getColumnGroups(): array
{
    return [
        'id',
        new ColumnGroup(
            id: 'name',
            label: 'Full Name',
            columns: [
                'firstName' => ColumnMetadata::create('firstName', 'First'),
                'lastName'  => ColumnMetadata::create('lastName', 'Last'),
            ],
            subLabels: ColumnGroup::SUB_LABELS_ICON,
            header: ColumnGroup::HEADER_COLLAPSIBLE,
        ),
    ];
}
```

Available value objects
-----------------------

[](#available-value-objects)

ClassPurpose`ColumnMetadata`Describes a column (name, label, type, sortable, template, group)`ColumnGroup`Groups columns into a composite table cell`FilterMetadata`Describes a filter widget with factory methods per type`FilterEnumOptions`Enum/select filter options (values list or enum class)`PaginatedResult`Query result container with pagination helpers`PaginationInfo`Slim pagination state for display templatesInterfaces
----------

[](#interfaces)

InterfacePurpose`DataSourceInterface`Main contract for any tabular data source`DataSourceProviderInterface`Yields multiple data sources from one service`SearchAwareDataSourceInterface`Optional: advertise which columns are globally searchedRequirements
------------

[](#requirements)

- PHP 8.1+
- No other dependencies

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance59

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1206e3a106f8c82c1dd68d4304c951d6979f39e5806de2a7a72724d825f06b38?d=identicon)[kachnitel](/maintainers/kachnitel)

---

Top Contributors

[![kachnitel](https://avatars.githubusercontent.com/u/4067705?v=4)](https://github.com/kachnitel "kachnitel (1 commits)")

### Embed Badge

![Health badge](/badges/kachnitel-datasource-contracts/health.svg)

```
[![Health](https://phpackages.com/badges/kachnitel-datasource-contracts/health.svg)](https://phpackages.com/packages/kachnitel-datasource-contracts)
```

###  Alternatives

[phpdocumentor/type-resolver

A PSR-5 based resolver of Class names, Types and Structural Element Names

9.2k719.5M166](/packages/phpdocumentor-type-resolver)[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M342](/packages/league-container)[stella-maris/clock

A pre-release of the proposed PSR-20 Clock-Interface

7947.5M2](/packages/stella-maris-clock)[wptrt/wpthemereview

PHP\_CodeSniffer rules (sniffs) to verify theme compliance with the rules for theme hosting on wordpress.org

217736.5k29](/packages/wptrt-wpthemereview)[inpsyde/modularity

Modular PSR-11 implementation for WordPress plugins, themes or libraries.

54383.3k3](/packages/inpsyde-modularity)

PHPackages © 2026

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