/** * @param Product $product Instance of Product object to convert to array * @throws TransformationFailedException Throws exception if Product object not given * * @return array Returns array of product segments */ public function transform($product) { if ($product === null) { return []; // For chaining, see symfony docs } if (!$product instanceof Product) { throw new TransFailExeption("Parameter 1 must be instance of Message\\Mothership\\Commerce\\Product\\Product."); } $properties = ['name' => $product->getName(), 'brand' => $product->getBrand(), 'category' => $product->getCategory(), 'description' => $product->getDescription(), 'prices' => []]; foreach ($product->getPrices() as $key => $pricing) { $properties['prices'][$key] = $product->getPrice($key); } /* * TODO: Extend to enumerate $properties[units] fully */ return $properties; }