2017 © Pedro Peláez
 

library salesmen

Work with Salesman IDs: Interfaces, Traits, FilterIterator

image

germania-kg/salesmen

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  • Friday, July 13, 2018
  • by germania-kg
  • Repository
  • 2 Watchers
  • 0 Stars
  • 80 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 20 Versions
  • 10 % Grown

The README.md

Germania KG · Salesmen

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

Installation

$ composer require germania-kg/salesmen

Interfaces

SalesmanIdProviderInterface

public function getSalesmanId()

SalesmanIdAwareInterface

extends SalesmanIdProviderInterface
public function setSalesmanId( $id )

Traits

SalesmanIdProviderTrait

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

public $salesman_id;
public function getSalesmanId()

SalesmanIdAwareTrait

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

use SalesmanIdProviderTrait;
public function setSalesmanId( $salesman )

Examples

<?php
use Germania\Salesmen\SalesmanIdProviderInterface;
use Germania\Salesmen\SalesmanIdProviderTrait;

class Salesman implements SalesmanIdProviderInterface
{
    use SalesmanIdProviderTrait;

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

$salesman = new Salesman( 99 );
echo $salesman->getSalesmanId(); // 99
<?php
use Germania\Salesmen\ SalesmanIdAwareInterface;
use Germania\Salesmen\SalesmanIdAwareTrait;

class MyOrder implements SalesmanIdAwareInterface
{
    use SalesmanIdAwareTrait;
}

$order  = new MyOrder;
$order->setSalesmanId( 34 );
echo $order->getSalesmanId(); // 34


SalesmanFilterIterator

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

Iterator:, (*5)

  • instances of SalesmanIdProviderInterface

Filter values:, (*6)

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

Example:, (*7)

<?php
use Germania\Salesmen\SalesmanFilterIterator;

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

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

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

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


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

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

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


// ---------------------------------------
// Filter by SalesmanIdProviderInterface:
// ---------------------------------------

$salesman = new Salesman( 1 );
$filter = new SalesmanFilterIterator( new \ArrayIterator( $orders ), $salesman);

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

Issues

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

Also see full issues list., (*8)

Development

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

Unit tests

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

$ composer test
# or
$ vendor/bin/phpunit

The Versions

13/07 2018

dev-develop

dev-develop

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

13/07 2018

dev-master

9999999-dev

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

13/07 2018

2.1.5

2.1.5.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

23/04 2018

2.1.4

2.1.4.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

19/04 2018

2.1.3

2.1.3.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/02 2018

2.1.2

2.1.2.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/02 2018

2.1.1

2.1.1.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/02 2018

2.1.0

2.1.0.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Requires

 

The Development Requires

by Carsten Witt

08/02 2018

2.0.0

2.0.0.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

07/02 2018

1.2.1

1.2.1.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

07/02 2018

1.2.0

1.2.0.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

30/08 2017

1.1.5

1.1.5.0

Work with Salesman IDs: Interfaces, Traits, FilterIterator

  Sources   Download

MIT

The Development Requires

by Carsten Witt

30/08 2017

1.1.4

1.1.4.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

30/08 2017

1.1.3

1.1.3.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

29/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

04/07 2017

1.1.0

1.1.0.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

03/07 2017

1.0.2

1.0.2.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

03/07 2017

1.0.1

1.0.1.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt

03/07 2017

1.0.0

1.0.0.0

  Sources   Download

proprietary

The Development Requires

by Carsten Witt