mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-23 05:45:06 +00:00
28 lines
583 B
PHP
28 lines
583 B
PHP
|
<?php
|
||
|
namespace MadLisp;
|
||
|
|
||
|
class Util
|
||
|
{
|
||
|
public static function makeHash(array $args): Hash
|
||
|
{
|
||
|
if (count($args) % 2 == 1) {
|
||
|
throw new MadLispException('uneven number of arguments for hash');
|
||
|
}
|
||
|
|
||
|
$data = [];
|
||
|
|
||
|
for ($i = 0; $i < count($args) - 1; $i += 2) {
|
||
|
$key = $args[$i];
|
||
|
$val = $args[$i + 1];
|
||
|
|
||
|
if (!is_string($key)) {
|
||
|
throw new MadLispException('invalid key for hash (not string)');
|
||
|
}
|
||
|
|
||
|
$data[$key] = $val;
|
||
|
}
|
||
|
|
||
|
return new Hash($data);
|
||
|
}
|
||
|
}
|