Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
/ shaper Public archive

Abstract transformers for collections and arrays.

License

Notifications You must be signed in to change notification settings

danielsdeboer/shaper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Stable Version License

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():

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:

$shaper = new MyArrayShaper($array);
$shaped = $shaper->shape();

You can also set the iterable after instantiation:

$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).