/** * Return Enumerable instance as an object * * @return object Enumerable array converted to an object */ public function toObject() { return \Nerd\Arr::toObject($this->enumerable); }
/** * Set/get an option/attribute * * Simply sets or gets an option or attribute depending on whether or not a value * is passed. If setting the class attribute special handling is invoked. * * @param string Option or attribute name * @param mixed|null Option or attribute value or none * @return mixed If getting an option/attribute * @return chainable If setting an option/attribute */ public function option($option, $value = null) { if ($value === null) { if ($option === 'class') { return implode(' ', $this->classes); } return Arr::get($this->options, $option, false); } if ($option === 'class') { $new = explode(' ', trim($value)); $this->classes = array_merge($this->classes, $new); } else { Arr::set($this->options, $option, $value); } return $this; }
/** * @covers \Nerd\Arr::toObject */ public function testArrToObjectFail() { // Should fail on a normal array $obj = Arr::toObject([1, 2, 3]); $this->assertFalse(is_object($obj)); }
/** * Delete flash data using javascript dot notation * * @param string Flash data key * @returns void */ public function delete($key) { Arr::delete($_SESSION, "flash.{$key}"); }
/** * Retrieve data from the $_SERVER superglobal array * * @param string Dot notated path to data * @param mixed Default return value * @returns mixed */ public static function server($key = null, $default = null) { return $key === null ? $_SERVER : \Nerd\Arr::get($_SERVER, strtoupper($key), $default); }