示例#1
0
 /** @test */
 public function setThrowsExceptionOnNonArraySegment()
 {
     $data = array('foo' => 'bar');
     $this->setExpectedException('UnexpectedValueException', 'Non-array segment encountered');
     ArrayUtil::set($data, 'foo.bar', 'baz');
 }
 /**
  * Parse data coming from the database.
  *
  * @param  array $data
  *
  * @return array
  */
 public function parseReadData($data)
 {
     $results = array();
     foreach ($data as $row) {
         if (is_array($row)) {
             $key = $row['key'];
             $value = $row['value'];
         } elseif (is_object($row)) {
             $key = $row->key;
             $value = $row->value;
         } else {
             $msg = 'Expected array or object, got ' . gettype($row);
             throw new \UnexpectedValueException($msg);
         }
         ArrayUtil::set($results, $key, $value);
     }
     return $results;
 }