2017 © Pedro Peláez
 

library generic-collection-php

Realization of generic collection

image

kartavik/generic-collection-php

Realization of generic collection

  • Sunday, July 15, 2018
  • by KartaviK
  • Repository
  • 2 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Generic collection (Under development)

Latest Stable Version Latest Unstable Version Total Downloads License, (*1)

Scrutinizer Code Quality Build Status codecov, (*2)

Strongly typed generic collection implementation, (*3)

Installation

Use composer to install:, (*4)

composer require kartavik/typed-collection

Usage

Dynamic

  • internal types
<?php

use kartavik\Support\Collection;
use kartavik\Support\Strict;

$items = [1, 2, 3, 4,];
$collection = new Collection(Strict::integer(), $items); // Return instance of typed collection
$collection = Collection::{'integer'}($items); // Work same as constructor

// Another examples

// string
Collection::{Strict::STRING}(['str1', 'str2']);

// float
Collection::{Strict::FLOAT}([12.3, 23.5, 3., 54.321,]);

// array
Collection::{Strict::ARRAYABLE}([[1, 2], ['str1'], [123.456]]);

// boolean
Collection::{Strict::BOOLEAN}([true, false]);

// object
Collection::{Strict::OBJECT}([new stdClass(), new Exception()]);
  • User types
<?php

use kartavik\Support\Collection;
use kartavik\Support\Strict;

// You can put name of class to static call
// In this case collection can take only stdClass
// It will work with any declared classes
$collection = Collection::{stdClass::class}([]);

// you can also do it with constructor
$collection = new Collection(Strict::object(stdClass::class), []);

// Strict class also support static call for class name
$strict = Strict::{stdClass::class}();
$collection = new Collection($strict, []);

Extend

StringCollection.php:, (*5)

<?php

use kartavik\Support;

class StringCollection extends Support\Collection
{
    public function __construct(array $items)
    {
        // do something

        parent::__construct(Support\Strict::string(), $items);
    }
}

Where is strong type?

Class Strict help collection to validate type of elements;, (*6)

If you will try in any moment put to the collection element that is not of element type you will get Exception\Validation, (*7)

If you will try set some specific type you will catch Exception\UnprocessedType, (*8)

Authors:

License

MIT, (*9)

The Versions

15/07 2018

dev-master

9999999-dev

Realization of generic collection

  Sources   Download

MIT

The Development Requires

by Avatar KartaviK

collection generic designer

15/07 2018

v1.1

1.1.0.0

Realization of generic collection

  Sources   Download

MIT

The Development Requires

by Avatar KartaviK

collection generic designer

14/07 2018

v1.0

1.0.0.0

Realization of generic collection

  Sources   Download

MIT

The Development Requires

by Avatar KartaviK

collection generic designer