/** * convert data into transformed array * * @param mixed $data * @param Item|Collection $resource * @param array|string $embeds * @return array */ public function convert($data, Item $resource, $embeds = []) { if (is_string($embeds)) { $embeds = $this->embedManager->getEmbedsFromParam($embeds); } $embeds = $this->embedManager->filter($this->availableEmbeds, $embeds); return $resource->transform($data, $embeds); }
public function testTransformWithEmbed() { $books = [new Book(['id' => 1, 'name' => 'Book1']), new Book(['id' => 2, 'name' => 'Book2']), new Book(['id' => 3, 'name' => 'Book3'])]; $author = new Author(['id' => 4, 'name' => 'James']); $author->books = $books; $embed = new Embed('books'); $item = new Item(new AuthorTransformer()); $this->assertEquals(['id' => 4, 'name' => 'James', 'books' => [['id' => 1, 'name' => 'Book1'], ['id' => 2, 'name' => 'Book2'], ['id' => 3, 'name' => 'Book3']]], $item->transform($author, [$embed])); }
public function testTranform() { $book = new Book(['id' => 1, 'name' => 'Book1']); $item = new Item(new BookTransformer()); $this->assertEquals(['id' => 1, 'name' => 'Book1'], $item->transform($book)); }