/** * Set a configuration by key. Autobox the value if a default exists. * * @uses Titon\Utility\Hash * * @param string $key * @param mixed $value * @return $this */ public function set($key, $value = null) { if (($default = Hash::extract($this->_defaults, $key)) !== null) { if (is_float($default)) { $value = (double) $value; } else { if (is_numeric($default)) { $value = (int) $value; } else { if (is_bool($default)) { $value = (bool) $value; } else { if (is_string($default)) { $value = (string) $value; } else { if (is_array($default)) { $value = (array) $value; } } } } } } $this->_data = Hash::insert($this->_data, $key, $value); return $this; }
/** * Test that extract() will return a value based on the dot notated path. */ public function testExtract() { $data = $this->expanded; foreach ($this->collapsed as $key => $value) { $this->assertEquals($value, Hash::extract($data, $key)); } $this->assertEquals(null, Hash::extract(array(), 'some.path')); $this->assertEquals(null, Hash::extract($data, null)); $this->assertEquals(null, Hash::extract($data, 'fake.path')); $this->assertEquals($data['one']['two']['three'], Hash::extract($data, 'one.two.three')); $this->assertEquals($data['one']['two']['three']['four']['five']['six'], Hash::extract($data, 'one.two.three.four.five.six')); }