Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danielsdeboer/shaper
Abstract transformers for collections and arrays.
https://github.com/danielsdeboer/shaper
array collections php php7 shaper transform
Last synced: 2 months ago
JSON representation
Abstract transformers for collections and arrays.
- Host: GitHub
- URL: https://github.com/danielsdeboer/shaper
- Owner: danielsdeboer
- License: mit
- Created: 2017-11-30T14:53:01.000Z (about 7 years ago)
- Default Branch: trunk
- Last Pushed: 2024-08-07T16:04:05.000Z (5 months ago)
- Last Synced: 2024-08-07T22:38:34.153Z (5 months ago)
- Topics: array, collections, php, php7, shaper, transform
- Language: PHP
- Size: 37.1 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/danielsdeboer/shaper.svg?branch=master)](https://travis-ci.org/danielsdeboer/shaper)
[![Latest Stable Version](https://poser.pugx.org/aviator/shaper/v/stable)](https://packagist.org/packages/aviator/shaper)
[![License](https://poser.pugx.org/aviator/shaper/license)](https://packagist.org/packages/aviator/shaper)## Overview
Shaper provides an interface and abstract classes which can be extended to create array or collection shaper classes. These classes can then be reused to shape the same sort of iterable, eg when preparing for serialization.
### Installation
Via Composer:
```
composer require aviator/shaper
```### Testing
Via Composer:
```
composer test
```### Usage
Extend either the collection or array shaper and define a public method called `shaper()`:
```php
public function shaper ($item)
{
return [
'mutated_name' => ucfirst($item['name')
];
}
```This callback can do whatever you like. Once you've defined your class, you can instantiate it and call `shape()`, which maps over your iterable and applies the callback:
```php
$shaper = new MyArrayShaper($array);
$shaped = $shaper->shape();
```You can also set the iterable after instantiation:
```php
$shaper = new MyArrayShaper();// Returns null
$shaper->get();$shaper->set($yourArray);
// Returns the array
$shaper->get();
```## Other
### License
This package is licensed with the [MIT License (MIT)](LICENSE).