Exemple #1
0
 public function testObjectMapTest()
 {
     $set = [['author_id' => 1, 'name' => 'Jack London', 'birth' => '1/12/1876', 'post_id' => 3, 'title' => 'White Fang', 'body' => 'Dark spruce forest frowned on either side the frozen waterway.'], ['author_id' => 2, 'name' => 'Herman Melville', 'birth' => '8/1/1819', 'post_id' => 4, 'title' => 'Moby-Dick', 'body' => 'Call me Ishmael.']];
     $set = json_decode(json_encode($set));
     $results = $this->mapper->map(['Author', 'Post'], $set, $split = 'post_id');
     $this->assertCount(2, $results);
     $this->assertSame('White Fang', $results[0]['post']->getTitle());
     $this->assertSame('Moby-Dick', $results[1]['post']->getTitle());
 }
Exemple #2
0
 /**
  * Execute a query and map it to your requested types. Returns an array of your rows.
  * @param string|array $requestedTypes
  * @param string|object|Statement $sql
  * @param array $params
  * @param string|array $split
  * @throws \InvalidArgumentException
  * @return array
  */
 public function query($requestedTypes, $sql, $params = [], $split = [])
 {
     if (is_null($requestedTypes) || empty($requestedTypes)) {
         throw new \InvalidArgumentException('You must specify at least one type to map your results against.');
     }
     if (!$sql instanceof Statement) {
         $sql = $this->connection->prepare($sql);
     }
     $sql->execute($params);
     $results = $sql->fetchAll();
     return $this->mapper->map($requestedTypes, $results, $split);
 }