1. Go to this page and download the library: Download daggerhartlab/collections library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
daggerhartlab / collections example snippets
$collection = new \DaggerhartLab\Collections\Collection(['one', 'two', 'three']);
$collection->add('four');
foreach ($collection as $item) {
echo $item;
}
$type = '\\Big\\Long\\Fqn\\ExampleInterface';
$items = [
new \Big\Long\Fqn\ExampleModel(),
new \Big\Long\Fqn\ExampleAdvancedModel(),
new DateTime(),
];
$collection = new \DaggerhartLab\Collections\TypedCollection($type, $items);
// We don't expect the DateTime() to get registered.
assertEquals(2, $collection->count());
foreach ($collection as $item) {
assertInstanceOf($type, $item);
}
$registry = new \DaggerhartLab\Collections\Map\Map([
'one' => 1,
'two' => 'buckle my shoe',
'three' => 3,
]);
$registry->set('four', 'close the door');
echo $registry->get('two');
echo $registry['four'];
$type = '\\Big\\Long\\Fqn\\ExampleInterface';
$items = [
'example' => new \Big\Long\Fqn\ExampleModel(),
'advanced' => new \Big\Long\Fqn\ExampleAdvancedModel(),
'another' => new DateTime(),
];
$registry = new \DaggerhartLab\Collections\Map\TypedMap($type, $items);
$example = $registry->get('example');
echo $example->getTitle();