/** * @param array|Dictionary|Traversable $array * * @throws \InvalidArgumentException */ function __construct($array = null) { parent::__construct(); if ($array === null) { $this->array = []; return; } if ($array instanceof Dictionary) { $this->array = $array->array; return; } if ($array instanceof Traversable) { $array = iterator_to_array($array, true); } if (is_array($array)) { $this->array = array(); foreach ($array as $key => $value) { if ($value instanceof KeyValuePair) { $this->array[is_object($value->getKey()) ? spl_object_hash($value->getKey()) : $value->getKey()] = $value; } else { $this->array[is_object($key) ? spl_object_hash($key) : $key] = new KeyValuePair($key, $value); } } return; } throw new InvalidArgumentException('You must give an array or a Traversable'); }
/** * @param array|Traversable $array * * @throws \InvalidArgumentException */ function __construct($array = null) { parent::__construct(); if ($array === null) { $this->array = array(); } else { if (is_array($array)) { $this->array = array_values($array); } else { if ($array instanceof Traversable) { $this->array = iterator_to_array($array, false); } else { throw new InvalidArgumentException('You must give an array or a Traversable'); } } } }
/** * @param string|string[] $string * * @throws \InvalidArgumentException */ function __construct($string = null) { parent::__construct(); if (is_array($string)) { $this->string = implode($string); } else { if ($string instanceof Stringer) { $this->string = $string->string; } else { if (is_string($string)) { $this->string = $string; } else { if ($string === null) { $this->string = ''; } else { throw new InvalidArgumentException('You must give a string or a char array'); } } } } }