Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

DownloadRedirectionController.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\MVC\Symfony\Controller\Content;
8
9 use eZ\Publish\API\Repository\ContentService;
10 use eZ\Publish\API\Repository\Values\Content\Content;
11 use eZ\Publish\API\Repository\Values\Content\Field;
12 use eZ\Publish\Core\MVC\Symfony\Controller\Controller;
13 use eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator;
14 use InvalidArgumentException;
15 use Symfony\Component\HttpFoundation\RedirectResponse;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\Routing\RouterInterface;
18
19 class DownloadRedirectionController extends Controller
20 {
22 private $contentService;
23
25 private $router;
26
28 private $routeReferenceGenerator;
29
30 public function __construct(ContentService $contentService, RouterInterface $router, RouteReferenceGenerator $routeReferenceGenerator)
31 {
32 $this->contentService = $contentService;
33 $this->router = $router;
34 $this->routeReferenceGenerator = $routeReferenceGenerator;
35 }
36
48 public function redirectToContentDownloadAction($contentId, $fieldId, Request $request)
49 {
50 $content = $this->contentService->loadContent($contentId);
51 $field = $this->findFieldInContent($fieldId, $content);
52
53 $params = [
54 'content' => $content,
55 'fieldIdentifier' => $field->fieldDefIdentifier,
56 'language' => $field->languageCode,
57 ];
58
59 if ($request->query->has('version')) {
60 $params['version'] = $request->query->get('version');
61 }
62
63 $downloadUrl = $this->router->generate(
64 $this->routeReferenceGenerator->generate(
65 'ez_content_download',
66 $params
67 )
68 );
69
70 return new RedirectResponse($downloadUrl, 302);
71 }
72
81 protected function findFieldInContent($fieldId, Content $content)
82 {
83 foreach ($content->getFields() as $field) {
84 if ($field->id == $fieldId) {
85 return $field;
86 }
87 }
88 throw new InvalidArgumentException("Field with id $fieldId not found in Content with id {$content->id}");
89 }
90 }
eZ\Publish\API\Repository\Values\Content\Content
Definition: Publish/API/Repository/Values/Content/Content.php:21
eZ\Publish\API\Repository\Values\Content\Content\getFields
getFields()
This method returns the complete fields collection.
eZ\Publish\API\Repository\Values\Content\Field
Definition: API/Repository/Values/Content/Field.php:21
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController
Definition: DownloadRedirectionController.php:20
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\$router
$router
Definition: DownloadRedirectionController.php:25
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\__construct
__construct(ContentService $contentService, RouterInterface $router, RouteReferenceGenerator $routeReferenceGenerator)
Definition: DownloadRedirectionController.php:30
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\findFieldInContent
findFieldInContent($fieldId, Content $content)
Finds the field with id $fieldId in $content.
Definition: DownloadRedirectionController.php:81
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\redirectToContentDownloadAction
redirectToContentDownloadAction($contentId, $fieldId, Request $request)
Used by the REST API to reference downloadable files.
Definition: DownloadRedirectionController.php:48
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\$routeReferenceGenerator
$routeReferenceGenerator
Definition: DownloadRedirectionController.php:28
eZ\Publish\Core\MVC\Symfony\Controller\Content\DownloadRedirectionController\$contentService
$contentService
Definition: DownloadRedirectionController.php:22
eZ\Publish\Core\MVC\Symfony\Controller\Controller
Definition: Publish/Core/MVC/Symfony/Controller/Controller.php:16
eZ\Publish\Core\MVC\Symfony\Routing\Generator\RouteReferenceGenerator
Definition: RouteReferenceGenerator.php:17
eZ\Publish\API\Repository\ContentService
Definition: API/Repository/ContentService.php:27
eZ\Publish\Core\MVC\Symfony\Controller\Content
Definition: DownloadController.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.