2017 © Pedro Peláez
 

library retailers

Work with Retailers: Interfaces, Traits, FilterIterator

image

germania-kg/retailers

Work with Retailers: Interfaces, Traits, FilterIterator

  • Wednesday, September 6, 2017
  • by germania-kg
  • Repository
  • 2 Watchers
  • 0 Stars
  • 139 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 22 % Grown

The README.md

Germania KG · Retailers

Packagist PHP version Build Status Scrutinizer Code Quality Code Coverage Build Status, (*1)

Installation with Composer

$ composer require germania-kg/retailers

Interfaces

RetailerNumberProviderInterface

public function getRetailerNumber()

RetailerNumberAwareInterface

extends RetailerNumberProviderInterface
public function setRetailerNumber( $id )

Traits

RetailerNumberProviderTrait

Objects using this trait will provide a retailer_number attribute and a getRetailerNumber getter method, as outlined here:, (*2)

public $retailer_number;
public function getRetailerNumber()

RetailerNumberAwareTrait

Objects using this trait will provide anything that RetailerNumberProviderInterface provides, and additionally a setter method setRetailerNumber which accepts anything; if RetailerNumberProviderInterface given here, getRetailerNumber method will be called to obtain the ID to use. Roughly outlined:, (*3)

use RetailerNumberProviderTrait;
public function setRetailerNumber( $id )

Examples

<?php
use Germania\Retailers\RetailerNumberProviderInterface;
use Germania\Retailers\RetailerNumberProviderTrait;

class Retailer implements RetailerNumberProviderInterface
{
    use RetailerNumberProviderTrait;

    public function __construct( $retailer_number )
    {
        $this->retailer_number = $retailer_number;
    }
}

$retailer = new Retailer( 99 );
echo $retailer->getRetailerNumber(); // 99
<?php
use Germania\Retailers\RetailerNumberAwareInterface;
use Germania\Retailers\RetailerNumberAwareTrait;

class MyOrder implements RetailerNumberAwareInterface
{
    use RetailerNumberAwareTrait;
}

$order = new MyOrder;
$order->setRetailerNumber( 34 );
echo $order->getRetailerNumber(); // 34

RetailerFilterIterator

The RetailerFilterIterator class accepts any Iterator collection and a retailer ID (or ID array) or RetailerNumberProviderInterface instance to filter for. Collection items not being an instance of RetailerNumberProviderInterface are always ignored., (*4)

Iterator:, (*5)

  • instances of RetailerNumberProviderInterface

Filter values:, (*6)

  • Integer or string ID
  • Array of integer or string IDs
  • One instance of RetailerNumberProviderInterface – also see issue #1

Example:, (*7)

<?php
use Germania\Retailers\RetailerFilterIterator;

// Prepare some RetailerNumberProviderInterface instances:
$order1 = new MyOrder; 
$order1->setRetailerNumber( 1 );

$order2 = new MyOrder; 
$order2->setRetailerNumber( 20 );

$order3 = new MyOrder; 
$order4->setRetailerNumber( 999 );

$orders = [
    $order1,
    $order2,    
    $order3
];


// ---------------------------------------
// Filter by ID or ID array:
// ---------------------------------------

// should be '1'
$filter = new RetailerFilterIterator( new \ArrayIterator( $orders ) , 20);
echo iterator_count($filter);

// should be '2'
$filter = new RetailerFilterIterator( new \ArrayIterator( $orders ), array(20, 999));
echo iterator_count($filter);


// ---------------------------------------
// Filter by RetailerNumberProviderInterface:
// ---------------------------------------

$retailer = new Retailer( 1 );
$filter = new RetailerFilterIterator( new \ArrayIterator( $orders ), $retailer);

// should be '1'
echo iterator_count($filter);

Roadmap

Version 2.1:, (*8)

  • Use Scalar type declarations; requires PHP 7.0+

Issues

  • The RetailerFilterIterator should also accept an array of RetailerNumberProviderInterface instances as filter value. See issue #1.

See full issues list., (*9)

Development

$ git clone https://github.com/GermaniaKG/Retailers.git
$ cd Retailers
$ composer install

Unit tests

Either copy phpunit.xml.dist to phpunit.xml and adapt to your needs, or leave as is. Run PhpUnit test or composer scripts like this:, (*10)

$ composer test
# or
$ vendor/bin/phpunit

The Versions

06/09 2017

dev-master

9999999-dev

Work with Retailers: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

06/09 2017

dev-develop

dev-develop

Work with Retailers: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

30/08 2017

1.1.3

1.1.3.0

Work with Retailers: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

30/08 2017

1.1.2

1.1.2.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

19/07 2017

1.1.1

1.1.1.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

05/07 2017

1.1.0

1.1.0.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

05/07 2017

1.0.0

1.0.0.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt