示例#1
0
 /**
  * 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;
 }
示例#2
0
 /**
  * Test that insert() adds data to the array based on the dot notated path.
  */
 public function testInsert()
 {
     $data = array();
     foreach ($this->collapsed as $key => $value) {
         $data = Hash::insert($data, $key, $value);
     }
     $this->assertEquals($this->expanded, $data);
     $this->assertEquals(array(), Hash::insert(array(), '', 'value'));
 }