PHPackages                             alexrili/vephar - 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. alexrili/vephar

ActiveLibrary[API Development](/categories/api)

alexrili/vephar
===============

Small abstraction of api requests and transform responses in collections

v2.0.0(3y ago)11.8k1MITPHPPHP &gt;=7.2

Since Feb 26Pushed 3y ago2 watchersCompare

[ Source](https://github.com/alexrili/vephar)[ Packagist](https://packagist.org/packages/alexrili/vephar)[ Docs](https://github.com/alexrili/vephar)[ RSS](/packages/alexrili-vephar/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (1)

vephar
======

[](#vephar)

**vephar** vephar is a simple library that transform you arrays in collections/resources(objects).

[![Latest Version on Packagist](https://camo.githubusercontent.com/ad9b1548bddb66d6089908fb862622196e94eeeef26112b9ca768ca840ec4743/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c657872696c692f7665706861722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexrili/vephar)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/fb38248be8d4af860c1091790274fd2e38b09959973e8fb15122e2b121ed81a3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616c657872696c692f7665706861722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/alexrili/vephar)[![Coverage Status](https://camo.githubusercontent.com/bd0e535066ad36547ef4d85b7f6d62400afd369e8ec58667bf9822ceef52c0dd/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616c657872696c692f7665706861722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alexrili/vephar/code-structure)[![Quality Score](https://camo.githubusercontent.com/ab87b93c2f97607b4dd2d4d18c6022825c97456564c921f3381602090e9d4ec8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616c657872696c692f7665706861722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/alexrili/vephar)[![Total Downloads](https://camo.githubusercontent.com/3865a08b7199c193972070a2b43abfa5ad7de4837c0e6aec27cf049aec456b88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c657872696c692f7665706861722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/alexrili/vephar)

### Install

[](#install)

Via Composer

```
  composer require alexrili/vephar
```

### Start vephar

[](#start-vephar)

Vephar provides you a simple method called `response_to_object` out of the box.

```
$yourArray = [];
// simple way, just pass your array data, and vephar will make the magic :)
$response = response_to_object($yourArray);
// passing your own custom contract classes
$response = response_to_object($yourArray, YourCustomContractClass::class);
// passing your own custom contract classes and your custom collection classes
$response = response_to_object($yourArray, YourCustomContractClass::class, YourCustomContractCollection::class);
```

OR you can call like this

```
use Hell\Vephar\Response;

$yourArray = [];
$vephar = new Response();
$response = $vephar->make($yourArray);
$response = $vephar->make($yourArray, YourCustomContractClass::class);
$response = $vephar->make($yourArray, YourCustomContractClass::class, YourCustomContractCollection::class);
```

OR by calling static method called toObject

```
use Hell\Vephar\Response;

$response = Response::toObject($yourArray);
$response = Response::toObject($yourArray, YourCustomContractClass::class);
$response = Response::toObject($yourArray, YourCustomContractClass::class, YourCustomContractCollection::class);
```

### Usage (Automatic way)

[](#usage-automatic-way)

The **vephar** will transform your arrays(and the nested as well) in collections of resources automatically. Every index of your array will be a new attribute of your new collection/resource(object).

```
use Hell\Vephar\Response;

#can be a response from api request
$array = [
	"title" => "my title",
	"EMAIL" => "my@email.com",
	"nested_Array" => [
		"address" => "street 10",
		"postal_code" => 1234
	],
	"true_array" => [
		123,
		10,
		15
	]
]
# Instantiating (recommended)
$response = response_to_object($array)
```

```
#Return for collection will be
class Hell\Vephar\Collection#73 (1) {
  protected $items =>
  array(1) {
    [0] =>
    class Hell\Vephar\Resource#71 (4) {
      public $title =>
      string(8) "my title"
      public $email =>
      string(12) "my@email.com"
      public $nestedArray =>
      class Hell\Vephar\Resource#72 (2) {
	    public $address =>
	    string(9) "street 10"
	    public $postalCode =>
	    int(1234)
	  }
      public $trueArray =>
      array(3) {
	    [0] =>
	    int(123)
	    [1] =>
	    int(10)
	    [2] =>
	    int(15)
	  }
    }
  }
}

```

```
#return for a single resource will be
class Hell\Vephar\Resource#74 (4) {
  public $title =>
  string(8) "my title"
  public $email =>
  string(12) "my@email.com"
  public $nestedArray =>
  class Hell\Vephar\Resource#72 (2) {
    public $address =>
    string(9) "street 10"
    public $postalCode =>
    int(1234)
  }
  public $trueArray =>
  array(3) {
    [0] =>
    int(123)
    [1] =>
    int(10)
    [2] =>
    int(15)
  }
}

```

### Usage (Custom way)

[](#usage-custom-way)

The **vephar** also allows you to assign your own collection and resource contracts to it.

> **Important**:When you use your own contracts you need to explicitly say to if vephar should or not make somthings like going deeper or not into your nested arrays or change the pattern of you attribute names to camelCase etc.

```
namespace Hell\Vephar\Fake;

use Hell\Vephar\Contracts\CollectionContract;

class CustomCollection extends CollectionContract
{
     // This will tell the vephar to goo deeper or not.
     // The default is false  means should not go.
    protected $keepDigging = false;

    // This will tell the vephar to change your attributes names to camelCase.
    // The default is false  means will respect whatever you write
    protected $toCamelCase = false;

    // This will tell the vephar that you will set the attributes by your self.
    // The default is false  means will the vephar will put values automatically
    // intou your attributes if they existes on the input data.
    protected $setters = false;
}
```

```
namespace Hell\Vephar\Fake;

use Hell\Vephar\Contracts\ResourceContract;

class CustomResource extends ResourceContract
{
	/**
	* @bool
	*/
	protected $setters = true;
	/**
	* @bool
	*/
	protected $keepDigging = true;
	/**
	* @var
	*/
	public $name;

	/**
	* @var
	*/
	public $email;

	/**
	* @param mixed $email
	*/
	public function setName($name): void
	{
		$this->name = $name;
	}

	/**
	* @param mixed $email
	*/
	public function setEmail($email): void
	{
		$this->email = $email;
	}
  }
```

```
#can be a response from api request
$array = [
	"title" => "my title",
	"EMAIL" => "my@email.com",
	"nested_Array" => [
		"address" => "street 10",
		"postal_code" => 1234
	],
	"true_array" => [
		123,
		10,
		15
	]
]

$vephar = response_to_object($array, CustomResourceClass::class, CustomCollectionClass:class);
```

*In this case the response will be your own custom classes*

```
#Return for collection will be
class Hell\Vephar\CustomCollection#73 (1) {
  protected $items =>
  array(1) {
    [0] =>
    class Hell\Vephar\Resource#71 (4) {
      public $name =>
      null(0) null
      public $email =>
      string(12) "my@email.com"
    }
  }
}

```

```
#return for a single resource will be
class Hell\Vephar\CustomResource#74 (4) {
  public $name =>
  null(0) null
  public $email =>
  string(12) "my@email.com"
}

```

### Change log

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

### Testing

[](#testing)

```
$ composer test
```

### Contributing

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

### Security

[](#security)

If you discover any security related issues, please email alexrili instead of using the issue tracker.

### Credits

[](#credits)

- [Alex Ribeiro](https://github.com/alexrili)
- [All Contributors](../../contributors)

### License

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity54

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

Total

4

Last Release

1241d ago

Major Versions

v1.1.2 → v2.0.02022-12-15

PHP version history (2 changes)v1.0.1PHP ~7.2

v1.1.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ddf3f4bf799ee959bf1cca781d67a3dd0442b5992ac5af495d6921af961926b?d=identicon)[alexrili](/maintainers/alexrili)

---

Top Contributors

[![alexrili](https://avatars.githubusercontent.com/u/1238430?v=4)](https://github.com/alexrili "alexrili (36 commits)")

---

Tags

laravelpayload-transform-libphpalexrilivephar

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/alexrili-vephar/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

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