@param MediaInterface         $media
@param MediaProviderInterface $provider
@param string                 $context
@param string                 $format

@return bool
547720
protected function processMedia(MediaInterface $media, MediaProviderInterface $provider, $context, $format)
    {
        $this->log('Deleting thumbs for '.$media->getName().' - '.$media->getId());

        try {
            if ($format === $context.'_all') {
                $format = null;
            }

            $provider->removeThumbnails($media, $format);
        } catch (\Exception $e) {
            $this->log(sprintf('<error>Unable to remove thumbnails, media: %s - %s </error>',
                $media->getId(), $e->getMessage()));

            return false;
        }

        return true;
    }
521386
public function apply(TranscodeInterface $media, FormatInterface $format)
	{
		$options = [
			't'     => $this->getEffectType(),
			'st'    => (string) $this->getStartTime(),
			'curve' => $this->getCurve()
		];
		
		if ($this->getNumberSamples() !== null)
		{
			$options['ns'] = $this->getNumberSamples();
		}
		
		if ($this->getDuration() !== null)
		{
			$options['d'] = (string) $this->getDuration();
		}
		
		if ($this->getStartSample() !== null)
		{
			$options['ss'] = $this->getStartSample();
		}
		
		return [
			'filter:a' => [
				'afade' => http_build_query($options, null, ':')
			]
		];
	}
1238020
public function preSave(MediaInterface $media)
    {
        preg_match('/(?<=v(\=|\/))([-a-zA-Z0-9_]+)|(?<=youtu\.be\/)([-a-zA-Z0-9_]+)/', $media->getReference(), $matches);

        $media->setReference($matches[2]);

        if (!isset($media->old) || $media->old->getReference() !== $media->getReference()) {
            $this->updateMedadata($media);
        }
    }
1085449
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof ClientMethodContext) {
            return false;
        }

        $method = $context->getMethod();
        if (!preg_match($this->regex, $method->getMethodName())) {
            return false;
        }

        return $this->subRule->appliesToContext($context);
    }
842415
public function updateFocus(MediaInterface $media)
    {
        $originalFocusLeftPx = ($media->getFocusLeft() * $media->getWidth()) / 100;
        $newFocusLeftPx = $originalFocusLeftPx - $this->x;
        $newFocusLeft = ($newFocusLeftPx * 100) / $this->w;

        if ($newFocusLeft < 0) {
            $newFocusLeft = 0;
        }
        if ($newFocusLeft > 100) {
            $newFocusLeft = 100;
        }

        $media->setFocusLeft($newFocusLeft);

        $originalFocusTopPx = ($media->getFocusTop() * $media->getHeight()) / 100;
        $newFocusTopPx = $originalFocusTopPx - $this->y;
        $newFocusTop = ($newFocusTopPx * 100) / $this->h;

        if ($newFocusTop < 0) {
            $newFocusTop = 0;
        }
        if ($newFocusTop > 100) {
            $newFocusTop = 100;
        }

        $media->setFocusTop($newFocusTop);
    }
826989
public function createAction(Request $request, $provider = 'image')
    {
        $dispatcher = $this->get('event_dispatcher');
        $event = new ResponseEvent($request);
        $dispatcher->dispatch(OpiferMediaEvents::MEDIA_CONTROLLER_NEW, $event);

        if (null !== $event->getResponse()) {
            return $event->getResponse();
        }

        $mediaManager = $this->get('opifer.media.media_manager');
        $mediaProvider = $this->get('opifer.media.provider.pool')->getProvider($provider);

        $media = $mediaManager->createMedia();

        $form = $this->createForm(MediaType::class, $media, ['provider' => $mediaProvider]);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $mediaManager->save($media);

            $this->addFlash('success', sprintf('%s was succesfully created', $media->getName()));

            return $this->redirectToRoute('opifer_media_media_index');
        }

        return $this->render($this->container->getParameter('opifer_media.media_create_view'), [
            'form' => $form->createView(),
            'provider' => $mediaProvider,
        ]);
    }
1277382
public function create($context)
    {
        $providerManager = $this->providerService->getProviderManager($context);

        $media = $this->mediaManager->createMedia($context);

        $mediaProvider = $providerManager->getMediaProviderManager()->createMediaProvider();
        $mediaProvider->setMedia($media);

        return $mediaProvider;
    }
718733
public function isEditable(MediaInterface $media)
    {
        if (!$this->container->get('sonata.media.admin.media')->isGranted('EDIT', $media)) {
            return false;
        }

        return \in_array(strtolower($media->getExtension()), $this->validFormats, true);
    }
721492
public static function registerFormat( $format )
    {
        $object = new $format();
        if(!($object instanceof FormatInterface)) {
            return false;
        }

        foreach ( forward_static_call(array($format, 'getFormats')) as $type ) {
            array_push(self::$supported, $type);
            self::$formatMap[$type] = $format;
        }

        return true;
    }
527766
public function renderMedia(MediaInterface $media, array $options = array())
    {
        /** @var DisplayMediaInterface $strategy */
        foreach ($this->strategies as $strategy) {
            if ($strategy->support($media)) {
                return $strategy->renderMedia($media, $options);
            }
        }

        return $this->defaultStrategy->renderMedia($media, $options);
    }
1182287
public function renderMedia(MediaInterface $media, array $options)
    {
        $options = $this->validateOptions($options, __METHOD__);

        return $this->render(
            'OpenOrchestraMediaBundle:RenderMedia:image.html.twig',
            array(
                'media_url' => $this->getMediaFormatUrl($media, $options['format']),
                'media_alt' => $options['alt'],
                'id'        => $options['id'],
                'class'     => $options['class'],
                'style'     => $options['style'],
                'legend'    => $options['legend']
            )
        );
    }
602989
public function save(MediaInterface $media): MediaInterface
    {
        $data = $this->serializer()->serialize($media);

        if ($media->getId() !== 0) {
            $this->shopware()
                 ->put('/api/media/'.(string)$media->getId(), [], $data);
        } else {
            $response = $this->shopware()->post('/api/media', [], $data);
            $data     = json_decode((string)$response->getBody(), true);
            $media->setId((int)$data['data']['id']);
        }

        return $media;
    }
1354586
public function getFormByMediaProvider(MediaProviderInterface $mediaProvider, array $options = array())
    {
        $formName = $this->providerService->getProviderManager($mediaProvider->getMedia()->getContext())->getFormName();
        return $this->getForm($formName, $mediaProvider, $options);
    }
815040
protected function interpolateContext(string $format, array $context = []): string {
        $final = preg_replace_callback('/{([^\s][^}]+[^\s]?)}/', function ($matches) use ($context) {
            $field = trim($matches[1], '{}');
            if (array_key_exists($field, $context)) {
                return $context[$field];
            } else {
                return $matches[1];
            }
        }, $format);
        return $final;
    }
1246538
private function getJsonApiCacheKey(?string $format, array $context)
    {
        try {
            return md5($format.serialize($context));
        } catch (\Exception $exception) {
            // The context cannot be serialized, skip the cache
            return false;
        }
    }
314090
public function displayMediaForWysiwyg(MediaInterface $media, $format = '', $alt = '', $legend = '')
    {
        return $this->render(
            'OpenOrchestraMediaBundle:BBcode/WysiwygDisplay:thumbnail.html.twig',
            array(
                'media_url'    => $this->getFileUrl($media->getThumbnail()),
                'media_alt'    => $alt,
                'media_id'     => $media->getId(),
                'media_legend' => $legend
            )
        );
    }
1149934
public function getFormByContext($context, array $options = array())
    {
        $formName = $this->providerService->getProviderManager($context)->getFormName();
        $mediaProvider = $this->mediaService->create($context);

        return $this->getForm($formName, $mediaProvider, $options);
    }