@param \Sonata\Component\Product\ProductInterface $product
@param string                                     $format

@return array
358263
public function getRawProduct(ProductInterface $product, $format = 'json')
    {
        return json_decode($this->serializer->serialize($product, $format), true);
    }
692973
protected function couldBeSupported(Format\FormatInterface $format)
    {
        return $format instanceof Format\Simple\Arj ||
            $format instanceof Format\Simple\Bz2    ||
            $format instanceof Format\Simple\Cab    ||
            $format instanceof Format\Simple\Chm    ||
            $format instanceof Format\Simple\Cpio   ||
            $format instanceof Format\Simple\Deb    ||
            $format instanceof Format\Simple\Dmg    ||
            $format instanceof Format\Simple\Gz     ||
            $format instanceof Format\Simple\Iso    ||
            $format instanceof Format\Simple\Lzh    ||
            $format instanceof Format\Simple\Lzma   ||
            $format instanceof Format\Simple\Msi    ||
            $format instanceof Format\Simple\Rar    ||
            $format instanceof Format\Simple\Rpm    ||
            $format instanceof Format\Simple\Tar    ||
            $format instanceof Format\Simple\Wim    ||
            $format instanceof Format\Simple\Xz     ||
            $format instanceof Format\Simple\Zip;
    }
527780
public function apply(TranscodeInterface $media, FormatInterface $format)
	{
		if ( ! $format instanceof FrameFormatInterface)
		{
			throw new \InvalidArgumentException('The filter resize can be used only with the format of the frame.');
		}
		
		$format = $media->getFormat();
		$dimension = new Dimension($format->getWidth(), $format->getHeight());
		
		if ($this->width && ! $this->height) // Resize to width
		{
			$this->height = $this->width / $dimension->getRatio();
		}
		
		if ( ! $this->width && $this->height) // Resize to height
		{
			$this->width = $this->height * $dimension->getRatio();
		}
		
		// If the dimensions are the same, there's no need to resize.
		if($dimension->getWidth() === $this->width && $dimension->getHeight() === $this->height)
		{
			return [];
		}
		
		return [
			'filter:v' => [
				'scale' => http_build_query([
					'w' => $this->width,
					'h' => $this->height
				], null, ':')
			]
		];
	}
981570
public function apply(TranscodeInterface $media, FormatInterface $format)
	{
		$options = [];
		
		foreach (clone $this->filters as $filter)
		{
			foreach ($filter->apply($media, $format) as $option => $value)
			{
				if (stripos($option, 'filter') !== false)
				{
					$option = 'filter';
				}
				
				$options[$option][] = $value;
			}
		}
		
		if (isset($options['filter']))
		{
			$option = [];
			
			foreach (array_merge_recursive(...$options['filter']) as $filter => $value)
			{
				$option[] = $filter.'='.implode(', '.$filter.'=', (array) $value);
			}
			
			$options['filter'] = implode('', $this->inputs).implode(', ', $option).implode('', $this->outputs);
		}
		
		return $options;
	}
136427
public function listProductFamily($productFamilyId)
    {
        $service = $this->getService();

        $response      = $service->request('product_families/' . (int)$productFamilyId . '/components', 'GET');
        $responseArray = $this->getResponseArray($response);

        if (!$this->isError()) {
            $this->_data = $this->_normalizeResponseArray($responseArray);
        } else {
            $this->_data = array();
        }

        return $this;
    }
968594
public function resolve(FormatInterface $format)
    {
        foreach ($this->renderers as $render) {

            if ($render->getFormat() === $format->getName()) {
                return $render;
            }
        }

        throw new \Exception('Render not found');
    }
1214371
public function getErrors($format = true)
    {
        if (!$format) {
            return $this->errors;
        }

        $formatted = array();

        foreach ($this->errors as $error) {
            $formatted[] = $this->getFormattedError($error);
        }

        return $formatted;
    }
1254010
public function createProductMedia(ApiProductInterface $product, $locale)
    {
        $media = [];
        // We have to replace the media with a media obtained from the mediaManager since the urls and the
        // dimensions are added by the mediaManager.
        // TODO: implement proxy object who is responsible for generating the urls
        foreach ($product->getEntity()->getMedia() as $medium) {
            $media[] = $this->mediaManager->getById($medium->getId(), $locale);
        }
        $product->setMedia($media);
    }
316349
public function getSupportedInputFormats(string $given_output_format): array
    {
        $result = [];
        foreach ($this->converters as $formats) {
            list($input_format, $output_format) = $formats;
            if ($given_output_format === $output_format) {
                $result[] = $input_format;
            }
        }

        return $result;
    }
1202150
public function get($productId, array $fields = array())
    {
        $params = array();
        if (!empty($fields)) {
            $params['fields'] = $fields;
        }
        $endpoint = '/admin/products/'.$productId.'.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createObject(Product::class, $response['product']);
    }
25745
public function renderPropertiesAction(ProductInterface $product)
    {
        $provider = $this->get('sonata.product.pool')->getProvider($product);

        return $this->render(sprintf('%s:properties.html.twig', $provider->getBaseControllerName()), [
            'product' => $product,
        ]);
    }
853585
public function getFormatter(FormatInterface $format)
    {
        switch ($format->getType()) {
            case 'csv':
                if ($format instanceof CsvFormatInterface) {
                    return new CsvFormatter($format);
                } else {
                    throw new InvalidArgumentException(
                        "Format indicates it is csv but does not implement CsvFormatInterface"
                    );
                }

            // fallthrough
            case 'json':
                if ($format instanceof JsonFormatInterface) {
                    return new JsonFormatter($format);
                } else {
                    throw new InvalidArgumentexception(
                        "Format indicates it is json but does not implement JsonFormatInterface"
                    );
                }

            // fallthrough
            default:
                throw new InvalidArgumentException("Supplied format: {$format->getType()} is unknown");
        }
    }
220873
public function getPostInstructions($format = 'plain')
    {
        $content = [];

        if (\count($this->postInstructions) == 0) {
            return null;
        }

        ksort($this->postInstructions);

        foreach ($this->postInstructions as $version => $instructions) {
            $content[] = sprintf("## %s", $version);
            foreach ($instructions as $instruction) {
                $content[] = sprintf("%s", $instruction);
            }
        }

        $content = implode("\n\n", $content);

        if ($format === 'html') {
            $content = Markdown::defaultTransform($content);
        }

        return $content;
    }
211077
private function getMatchQueryParams(ProductCondition $productCondition)
    {
        $fieldName          = $this->getSearchFieldName($productCondition);
        $queryText          = $productCondition->getValue();
        $minimumShouldMatch = "100%";

        return ['field' => $fieldName, 'queryText' => $queryText, 'minimumShouldMatch' => $minimumShouldMatch];
    }
944359
public function indexAction(ProductInterface $product, ProductTranslation $translation)
    {
        $apiProduct = $this->getProductFactory()->createApiEntity($product, $translation->getLocale());

        return $this->render(
            $this->getProductViewTemplate(),
            [
                'product' => $apiProduct,
                'urls' => $this->getAllRoutesOfProduct($product),
            ]
        );
    }
27190
public function getProductByMetadata(string $productNumber, array $context) : array
    {
        Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0');
        Assert::that($context)->notEmpty();

        return (array)$this->master->doRequest(
            'POST',
            sprintf('/admin/WEBAPI/Endpoints/v1_0/ProductService/{KEY}/%s', rawurlencode($productNumber)),
            $context
        );
    }
693151
public function getProductCode(ProductInterface $product)
    {
        foreach ($this->products as $code => $productDescription) {
            $className = $productDescription->getManager()->getClass();
            if ($product instanceof $className) {
                return $code;
            }
        }
    }