This package works with PHP >= 7.1
The best way to install this package is using Composer:
$ composer require francalek/datatypeThis 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");To run tests:
$ git clone https://github.com/francalek/DataType.git
$ cd DataType/
$ ./tests/run.sh
# Or over Composer
$ composer tests- 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.
This package is licensed under the MIT License.