francalek / datatype
Useful data types for PHP.
v0.1
2022-07-06 15:17 UTC
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^9
README
Requirements
This package works with PHP >= 7.1
Installation
The best way to install this package is using Composer:
$ composer require francalek/datatype
Usage
CountableIterator
This abstract class implements only \Countable and \Iterator interfaces and has own storage.
Data for iterating and counting must be in protected property $this->countableIterator
.
use Francalek\DataType\CountableIterator; class Sheeps extends CountableIterator { public function __construct(int $sheeps = 5) { $herd = array_fill(0, $sheeps, 'Sheep'); $this->countableIterator = $herd; } }
And now you can iterating through your class:
echo "I can't sleep :(\n"; $sheeps = new Sheeps(); foreach ($sheeps as $nr => $sheep) { echo $sheep.' '.(++$nr)."\n"; } exit("Chrrr...\n");
Or counting:
echo "I can't sleep :(\n"; $sheeps = new Sheeps(); echo "I have ".count($sheeps)." sheeps in total.\n"; exit("Chrrr...\n");
Run tests
To run tests:
$ git clone https://github.com/francalek/DataType.git $ cd DataType/ $ ./tests/run.sh # Or over Composer $ composer tests
Contribute
- If you found a bug or have an idea for a new feature, you can create new Issue.
- Fork this repository to start adding new features, fixing bugs or creating more tests.
- Don't forget send a pull request to get your changes in this package.
- Read full text of Contributing.
License
This package is licensed under the MIT License.