2017 © Pedro Peláez
 

library items

A library for items with arbitrary data.

image

blesta/items

A library for items with arbitrary data.

  • Wednesday, May 25, 2016
  • by clphillips
  • Repository
  • 3 Watchers
  • 1 Stars
  • 237 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

blesta/items

A library for creating a collection of items that store arbitrary data., (*1)

Installation

Install via composer:, (*2)

composer require blesta/items:~1.0

Basic Usage

Item

Item stores generic data, typically user-defined arrays or object data., (*3)

$item = new Item();

Set fields onto the item:, (*4)

$fields = [
    'key' => 'item1',
    'value' => 'Item'
];
$item->setFields($fields);
$item->setField('custom', 'ABC123');
$item->removeField('value');
print_r($item->getFields());

Output is a standard class object of the fields:, (*5)

stdClass Object (
    [key] => item1
    [custom] => ABC123
)

ItemMap

ItemMap combines the values from one Item with the keys of another Item. The result is a new Item consisting of only the mapped keys that have item values., (*6)

// Create the item
$fields = [
    'domain' => 'domain.com',
    'amount' => 100.0000,
    'override_amount' => 150.0000,
    'custom' => 'ABC123'
];
$item = new Item();
$item->setFields($fields);

// Create an item to use for field mapping
$mapFields = [
    'value' => 'domain',
    'price' => ['override_amount', 'amount']
    'type' => 'generic'
];
$mapItem = new Item();
$mapItem->setFields($mapFields);

$map = new ItemMap();
$newItem = $map->combine($item, $mapItem);
print_r($newItem->getFields());

The fields set on the new item are only those keys from $mapItem that exist in $item after performing the mapping:, (*7)

stdClass Object (
    [value] => domain.com
    [price] => 150.0000
)

ItemCollection

$collection = new ItemCollection();

$item1 = new Item();
$item2 = new Item();
$collection->append($item1)->append($item2);
$total = $collection->count(); // 2

$collection->remove($item1);
$total = $collection->count(); // 1

foreach ($collection as $item) {
    print_r($item->getFields()); // stdClass object of fields
}

The Versions

25/05 2016

dev-master

9999999-dev

A library for items with arbitrary data.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Tyson Phillips

25/05 2016

1.0.0

1.0.0.0

A library for items with arbitrary data.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Tyson Phillips

25/05 2016

dev-itemcollection-use-iteminterface

dev-itemcollection-use-iteminterface

A library for items with arbitrary data.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Tyson Phillips

25/05 2016

dev-use-iteminterface

dev-use-iteminterface

A library for items with arbitrary data.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Tyson Phillips