Skip to content

v-dem/queasy-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy Badge Build Status codecov Total Downloads License

Package v-dem/queasy-type

Classes supporting typed "arrays" to help keep code type-safe. For example, IntArray, not just array:

function giveMeInts(IntArray $ints)
{
    ...
}

Features

Classes allowing to use typed "arrays":

  • TypedArray - Base class, implements ArrayAccess, Iterator and Countable
  • IntArray
  • StringArray
  • FloatArray
  • ResourceArray
  • ObjectArray
  • ArrayArray

Requirements

  • PHP version 5.3 or higher

Installation

composer require v-dem/queasy-type:master-dev

Usage

For example, to create an array of integer values:

$intArray = new queasy\type\IntArray([10, 20, 30]);

$intArray[] = 40;
$intArray['key'] = 50;

unset($intArray[0]); // Will remove value 10

foreach ($intArray as $key => $value) {
    echo $key . ' => ' . $value . PHP_EOL;
}

echo 'Elements count: ' . count($intArray) . PHP_EOL;

$intArray[] = 'wrong'; // Throws InvalidArgumentException

To create a specialized class representing array of users:

class UsersArray extends TypedArray
{
    public function __construct(array $items = null)
    {
        parent::__construct(app\model\User::class, $items);
    }
}

About

QuEasy PHP Framework - Database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages