|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Default controller for Api FILE rest calls |
|
4
|
|
|
*/ |
|
5
|
|
|
namespace Graviton\ArchiveBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Graviton\ArchiveBundle\Document\Archive; |
|
8
|
|
|
use Graviton\ArchiveBundle\Document\ArchiveMetadata; |
|
9
|
|
|
use Graviton\ArchiveBundle\Manager\ArchiveManager; |
|
10
|
|
|
use Graviton\RestBundle\Controller\RestController; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ArchiveController |
|
17
|
|
|
* @package Graviton\ArchiveBundle\Controller |
|
18
|
|
|
* |
|
19
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
21
|
|
|
* @link http://swisscom.ch |
|
22
|
|
|
*/ |
|
23
|
|
|
class ArchiveController extends RestController |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var ArchiveManager */ |
|
26
|
|
|
private $archiveManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param ArchiveManager $archiveManager File service manager |
|
30
|
|
|
*/ |
|
31
|
|
|
public function setArchiveManager(ArchiveManager $archiveManager) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->archiveManager = $archiveManager; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* respond with document if non json mime-type is requested |
|
38
|
|
|
* |
|
39
|
|
|
* @param Request $request Current http request |
|
40
|
|
|
* @param string $id id of file |
|
41
|
|
|
* |
|
42
|
|
|
* @return Response |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getAction(Request $request, $id) |
|
45
|
|
|
{ |
|
46
|
|
|
// If a json request, let parent handle it |
|
47
|
|
|
if (in_array('application/json', $request->getAcceptableContentTypes())) { |
|
48
|
|
|
return parent::getAction($request, $id); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** @var Archive $archive */ |
|
52
|
|
|
$archive = $this->findRecord($id); |
|
53
|
|
|
|
|
54
|
|
|
/** @var Response $response */ |
|
55
|
|
|
$response = $this->archiveManager->buildArchiveResponse( |
|
56
|
|
|
$this->getResponse(), |
|
57
|
|
|
$archive |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
return $response; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|