Renders the file (link).

@param MediaInterface $file
@param array          $params
@return string
@throws \InvalidArgumentException
768024
public function renderFile(MediaInterface $file, array $params = [])
    {
        if (in_array($file->getType(), [MediaTypes::FILE, MediaTypes::ARCHIVE])) {
            throw new \InvalidArgumentException('Expected media with "file" or "archive" type.');
        }

        $params = array_replace([
            'attr' => [
                'id' => 'image-' . $file->getId(),
            ],
        ], $params);

        return $this->elementTemplate->renderBlock('image', [
            'attr'   => $params['attr'],
            'href'   => $this->getDownloadUrl($file),
            'title'  => $file->getTitle(),
        ]);
    }
875366
public function generateThumbnail(MediaInterface $media)
    {
        $thumbnailName = $this->generateAlternative(
            $media->getFilesystemName(),
            self::THUMBNAIL_PREFIX,
            $this->thumbnailFormat
        );

        $media->setThumbnail($thumbnailName);
    }
367835
public function render($option, $params = array())
	{
		$client = (isset($this->app['client']->alias) ? $this->app['client']->alias : $this->app['client']->name);

		// Load template language files.
		$lang = $this->app['language'];
		if ($this->app->has('template'))
		{
			$template = $this->app['template']->template;

			$lang->load('tpl_' . $template, PATH_APP . DIRECTORY_SEPARATOR . 'bootstrap' . DIRECTORY_SEPARATOR . $client . DIRECTORY_SEPARATOR . 'language', null, false, true);
			$lang->load('tpl_' . $template, $this->app['template']->path, null, false, true);
		}

		if (empty($option))
		{
			// Throw 404 if no component
			$this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'));
		}

		$option = $this->canonical($option);

		// Record the scope
		$scope = $this->app->has('scope') ? $this->app->get('scope') : null;

		// Set scope to component name
		$this->app->set('scope', $option);

		// Build the component path.
		$file   = substr($option, 4);

		// Get component path
		define('PATH_COMPONENT', $this->path($option) . DIRECTORY_SEPARATOR . $client);
		define('PATH_COMPONENT_SITE', $this->path($option) . DIRECTORY_SEPARATOR . 'site');
		define('PATH_COMPONENT_ADMINISTRATOR', $this->path($option) . DIRECTORY_SEPARATOR . 'admin');

		// Legacy compatibility
		// @TODO: Deprecate this!
		define('JPATH_COMPONENT', PATH_COMPONENT);
		define('JPATH_COMPONENT_SITE', PATH_COMPONENT_SITE);
		define('JPATH_COMPONENT_ADMINISTRATOR', PATH_COMPONENT_ADMINISTRATOR);

		$path      = PATH_COMPONENT . DIRECTORY_SEPARATOR . $file . '.php';
		$namespace = '\\Components\\' . ucfirst(substr($option, 4)) . '\\' . ucfirst($client) . '\\Bootstrap';
		$found     = false;

		// Make sure the component is enabled
		if ($this->isEnabled($option))
		{
			// Check to see if the class is autoload-able
			if (class_exists($namespace))
			{
				$found = true;
				$path  = $namespace;

				// Infer the appropriate language path and load from there
				$file  = with(new \ReflectionClass($namespace))->getFileName();
				$bits  = explode(DIRECTORY_SEPARATOR, $file);
				$local = implode(DIRECTORY_SEPARATOR, array_slice($bits, 0, -1));

				// Load local language files
				$lang->load($option, $local, null, false, true);
			}
			else if (file_exists($path))
			{
				$found = true;

				// Load local language files
				$lang->load($option, PATH_COMPONENT, null, false, true);
			}
		}

		// Make sure we found something
		if (!$found)
		{
			$this->app->abort(404, $lang->translate('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND_OR_ENABLED'));
		}

		// Load base language file
		$lang->load($option, PATH_APP, null, false, true);

		// Handle template preview outlining.
		$contents = null;

		// Execute the component.
		$contents = $this->execute($path);

		// Revert the scope
		$this->app->forget('scope');
		$this->app->set('scope', $scope);

		return $contents;
	}
656639
public function url($file, array $params)
    {
        $cacheFileSrc = $this->make($file, $params);

        return $cacheFileSrc ? $cacheFileSrc : null;
    }
926112
public function generateAlternatives(MediaInterface $media)
    {
        if ($media->getFilesystemName() != '') {
            $filePath = $this->tmpDir . DIRECTORY_SEPARATOR . $media->getFilesystemName();
            $this->fileSystem->remove(array($filePath));
        }
    }
1188327
protected function renderMediasWidget(Collection $medias, array $options = [])
    {
        $medias = array_map(function($m) {
            /** @var \Ekyna\Bundle\MediaBundle\Model\MediaSubjectInterface $m */
            return $m->getMedia();
        }, $medias->toArray());

        return $this->renderBlock('show_widget_medias', [
            'medias' => $medias
        ]);
    }
1047923
public function renderMedia($mediaId, array $options = array())
    {
        $media = $this->getMedia($mediaId);

        if ($media) {
            return $this->displayMediaManager->renderMedia($media, $options);
        }

        return '';
    }
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']
            )
        );
    }
666018
public function media(Filesystem $files, $file)
    {
        $filename = __DIR__.'/../../../public/'.$file;
        $mimeType = strpos($filename, '.css') !== false ? 'text/css' : 'application/javascript';
        $lastModified = $files->lastModified($filename);
        $eTag = sha1_file($filename);
        $headers = [
            'content-type' => $mimeType,
            'last-modified' => date('D, d M Y H:i:s ', $lastModified).'GMT',
        ];

        if (@strtotime($this->request->server('HTTP_IF_MODIFIED_SINCE')) === $lastModified ||
            trim($this->request->server('HTTP_IF_NONE_MATCH'), '"') === $eTag
        ) {
            $response = $this->responseFactory->make(null, 304, $headers);
        } else {
            $response = $this->responseFactory->stream(function () use ($filename) {
                $out = fopen('php://output', 'wb');
                $file = fopen($filename, 'rb');
                stream_copy_to_stream($file, $out, filesize($filename));
                fclose($out);
                fclose($file);
            }, 200, $headers);
        }

        return $response->setEtag($eTag);
    }
128241
public function render($view, array $parameters = [], Response $response = null)
    {
        $parameters['media_pool'] = $this->get('sonata.media.pool');
        $parameters['persistent_parameters'] = $this->admin->getPersistentParameters();

        return parent::renderWithExtraParams($view, $parameters, $response);
    }
320341
protected function generateOutputFile($template, $file, array $parameters)
    {
        $template = sprintf('%s/%s', static::LANGUAGE, $template);
        $content = $this->render($template, $parameters);
        $ext = static::EXTENSION;
        $addNewLine = static::LANGUAGE !== 'json-schema';
        return new OutputFile(
            "{$this->compileOptions->getOutput()}/{$file}$ext",
            trim($content) . ($addNewLine ? PHP_EOL : '')
        );
    }
193303
public function modify(FileNodeInterface $file, array $options = [])
    {
        if (!$this->canModify($file) || !($file instanceof LocalFileNodeInterface)) {
            throw new InvalidArgumentException("The supplied file: '$file' does not implement LocalFileNodeInterface'");
        }

        $file->setCompression($this->getCompression($file));

        return $file;
    }
1301489
public static function make($path, $file = '', $params = null)
    {
        static::$instance or static::$instance = static::$di->getShared('view');
        return static::$instance->render($path, $file, $params)->getContent();
    }
1049308
protected function loadFile($file)
    {
        if (!stream_is_local($file)) {
            throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
        }

        if (!file_exists($file)) {
            throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
        }

        if (null === $this->jsonParser) {
            $this->jsonParser = new Json();
        }

        return $this->validate($this->jsonParser->decode(file_get_contents($file), true), $file);
    }
966960
private function generateFileThumb(MediaInterface $media)
    {
        $extension   = $media->guessExtension();
        $thumbPath   = sprintf('/%s/%s.jpg', $this->thumbsDirectory, $extension);
        $destination = $this->webRootDirectory . $thumbPath;

        if (file_exists($destination)) {
            return $thumbPath;
        }

        $backgroundColor = MediaTypes::getColor($media->getType());

        $iconPath = sprintf('%s/%s.png', $this->iconsSourcePath, $extension);
        if (! file_exists($iconPath)) {
            $iconPath = $this->iconsSourcePath.'/default.png';
        }

        $this->checkDir(dirname($destination));
        try {
            $palette = new RGB();
            $thumb = $this->imagine->create(new Box(120, 90), $palette->color($backgroundColor));

            $icon = $this->imagine->open($iconPath);
            $iconSize = $icon->getSize();
            $start = new Point(120/2 - $iconSize->getWidth()/2, 90/2 - $iconSize->getHeight()/2);

            $thumb->paste($icon, $start);
            $thumb->save($destination);

            return $thumbPath;
        } catch (ImagineException $e) {
            // Image thumb generation failed
        }

        return null;
    }
613669
protected function render(array $data = [], $file = null) : Response
    {
        if ($file === null) {
            $file = $this->getTemplateFile();
        }

        // Relative path from the controller?
        if (substr($file, 0, 1) !== '/') {
            $file = $this->getTemplateFile($file);
        }

        $data += [
            'base_url' => 'http://' . $this->request->getHost(),
            '_messages' => $this->messages,
        ];
        $this->messages = [];

        return new Response($this->renderView($file, $data));
    }
380917
public function renderField(Field $field, array $params = [])
    {
        $params = $this->getRenderFieldBlockParameters($field, $params);

        return $this->fieldBlockRenderer->renderContentFieldView(
            $field->innerField,
            $field->fieldTypeIdentifier,
            $params
        );
    }