/** * Sets an array of variables. * * @param string $collection The key. * @param mixed $value The value. * @param self */ public function set($collection, $value = null) { if (func_num_args() === 1) { return parent::merge($collection, true); } $this->_data[$collection] = $value; return $this; }
/** * The constructor * * @param string $name The header name * @param array $value The header value */ public function __construct($name = '', $value = '') { if (func_num_args() === 1) { $value = $name; $name = ''; } $value = is_array($value) ? join(',', $value) : $value; $this->_name = $name; $this->_plain = $value; if (!empty($this->_plain)) { $data = array_map('trim', explode(',', $this->_plain)); } else { $data = []; } parent::__construct($data); }
expect($collection->to('array'))->toBe(['hello']); }); it("converts objects using handlers", function () { $handlable = Double::classname(); $handlers = [$handlable => function ($value) { return 'world'; }]; $collection = new Collection([new $handlable()]); expect($collection->to('array', compact('handlers')))->toBe(['world']); }); it("doesn't convert unsupported objects", function () { $collection = new Collection([(object) 'an object']); expect($collection->to('array'))->toEqual([(object) 'an object']); }); it("converts nested collections", function () { $collection = new Collection([1, 2, 3, new Collection([4, 5, 6])]); expect($collection->to('array'))->toBe([1, 2, 3, [4, 5, 6]]); }); it("converts mixed nested collections & arrays", function () { $collection = new Collection([1, 2, 3, [new Collection([4, 5, 6])]]); expect($collection->to('array'))->toBe([1, 2, 3, [[4, 5, 6]]]); }); it("throws an exception with unsupported format", function () { $closure = function () { $collection = new Collection(); $collection->to('xml'); }; expect($closure)->toThrow(new InvalidArgumentException("Unsupported format `xml`.")); }); }); });
/** * Unsets an offset. * * @param string $offset The offset to unset. */ public function offsetUnset($name) { return parent::offsetUnset(strtolower($name)); }