olivebbs / map
Generic map for PHP
This package's canonical repository appears to be gone and the package has been frozen as a result.
1.1.3
2023-06-30 17:49 UTC
Requires
- php: ^8.1
- php-ds/php-ds: ^1.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.14
- phpunit/phpunit: ^9.6
Suggests
- ext-ds: To use the Data structure extension instead of polyfill.
README
Very simple typed map class.
Includes IntCharMap and CharMap as examples. It is best to extend Olivebbs\Map\GenericMap
for your uses.
Example
use Olivebbs\Map\GenericMap;
use Olivebbs\Map\Enum\ValueType;
use Olivebbs\Map\Enum\KeyType;
final class MyStringMap extends GenericMap
{
public function __construct(array $values)
{
parent::__construct(KeyType::STRING, ValueType::STRING);
$this->map->putAll($values);
}
}
or
use Olivebbs\Map\GenericMap;
use Olivebbs\Map\Enum\ValueType;
use Olivebbs\Map\Enum\KeyType;
$myIntMap = new GenericMap(KeyType::INT, ValueType::INT);
Then use it.
$myIntMap[0] = 500;
unset($myIntMap[0]) // null