/** * @dataProvider data * @covers \Nerd\Arr::set */ public function testArrSet($users) { $this->assertCount(2, $users); // Add a key and test count again Arr::set($users, 'NewUser', 'testdata'); $this->assertCount(3, $users); }
/** * 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; }
/** * Set an item to flash data using javascript dot notation * * @param string Flash data key * @param mixed Data to write to flash * @return void */ public function set($key, $data) { Arr::set($_SESSION, "flash.{$key}", array('aged' => false, 'value' => $data)); }