PHPackages                             comos/drapper - 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. comos/drapper

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

comos/drapper
=============

Data wrapper for PHP

0.2.0(9y ago)123MITPHPPHP &gt;5.5

Since Nov 19Pushed 9y ago4 watchersCompare

[ Source](https://github.com/Comos/drapper)[ Packagist](https://packagist.org/packages/comos/drapper)[ RSS](/packages/comos-drapper/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Comos Drapper
=============

[](#comos-drapper)

[![Build Status](https://camo.githubusercontent.com/307fc9ea9485e6ddce1bd1c1a8aaa9b829cdb36edf41b456cbfebdfc5f9e1f54/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f436f6d6f732f647261707065722e706e67)](http://travis-ci.org/Comos/drapper)

Introduction
------------

[](#introduction)

Defensive programming is a good and important practice. It demands people to concern about input validations, data type conversations and error handling. It's not easy. Sometimes, it makes programs elephantine. Drapper means Data-Wrapper. Its purpose is to simplify PHP data accessing but strength the robust. It could be figured out by following scenarios.

Scenarios
---------

[](#scenarios)

Loading data from JSON file
---------------------------

[](#loading-data-from-json-file)

For example, we have a json file named alex.json like this.

```
{
"id":1,
"name":"Alex",
"gender":null
}
```

We'd like read the file and access the `gender` field.

A matured phper would like to write like this.

```
$fileContents = file_get_contents('alex.json');
if (!fileContents === false) {
    //report the error
}
$data = json_decode($fileContents, true);
if (!is_array($data)) {
    //report the error
}
$gender = isset($data['gender']) ? $data['gender'] : 'private';
```

Finally, we get the gender, But it's not enough yet. We have to test the data type.

```
if (!is_string($gender) {
    // report the error
}

```

......

It's elephantine. If we use Drapper...

```
use Comos\Drapper\Loader;
$gender = Loader::fromJsonFile('alex.json')->str('gender', $defaultValue = 'private');

```

Only two lines. Even more you can use the full qualified class name to compress the codes to one line if you like.

In the scenario, Drapper checks existence, converts data type and handles defaulting strategy. If something is out of the fault-tolerant protocols, an exception would be thrown.

That's a one of scenarios. Actually, Drapper can do more.

### To wrapper an array directly

[](#to-wrapper-an-array-directly)

```
use Comos\Drapper\Bean;
$data = ['id'=>3, 'name'=>'alex'];
Bean::fromArray($data)->int('id');
```

### Reading field with default value

[](#reading-field-with-default-value)

```
use Comos\Drapper\Bean;

$defaultValue = 0.1;
$data = ['r0' => 0.2];
$bean = Bean::fromArray($data);
$r0 = $bean->float('r0', '');
```

Integration
-----------

[](#integration)

Drapper is easy to be integrated to your applications or libraries because of following reasons:

1. Build with Composer.
2. Follows the PSR-4.
3. Lightweight, has no more dependencies.

We recommend you to use Composer. That's the easiest way to integrate with drapper.

```
composer require comos/drapper
```

More informations
-----------------

[](#more-informations)

See [https://github.com/Comos/drapper/wiki](Wiki)

Or you could deploy Drapper to your include path. Then register a PSR-4 autoload callback to your application. See [PHP-FIG](http://php-fig.org).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Total

2

Last Release

3507d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65708d37f7a6414bbc8f851f3378588c829c42f26dc6a4bf9e64d9b585d9e3b2?d=identicon)[bigbigant](/maintainers/bigbigant)

---

Top Contributors

[![bigbigant](https://avatars.githubusercontent.com/u/10754591?v=4)](https://github.com/bigbigant "bigbigant (6 commits)")

### Embed Badge

![Health badge](/badges/comos-drapper/health.svg)

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

###  Alternatives

[php-forge/foxy

Fast, reliable, and secure Bun/NPM/Yarn/pnpm bridge for Composer

45126.3k4](/packages/php-forge-foxy)[laravel-enso/select

Server-side option and typeahead builders for Laravel Enso

2660.8k68](/packages/laravel-enso-select)

PHPackages © 2026

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