Passed
Pull Request — master (#593)
by Stefano
03:20
created

ExportController::model()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * BEdita, API-first content management framework
4
 * Copyright 2021 ChannelWeb Srl, Chialab Srl
5
 *
6
 * This file is part of BEdita: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published
8
 * by the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details.
12
 */
13
namespace App\Controller\Model;
14
15
use App\Controller\AppController;
16
use Cake\Http\Response;
17
18
/**
19
 * Export cotroller: download project model in JSON format
20
 *
21
 */
22
class ExportController extends AppController
23
{
24
    /**
25
     * Downloaded file name
26
     *
27
     * @var string
28
     */
29
    public const FILENAME = 'project_model.json';
30
31
    /**
32
     * Export project model JSON file
33
     *
34
     * @return \Cake\Http\Response
35
     */
36
    public function model(): Response
37
    {
38
        $content = $this->apiClient->get('/model/project', [], ['Accept' => 'application/json']);
39
40
        $response = $this->response->withStringBody(json_encode($content));
41
        $response = $response->withType('application/json');
42
43
        return $response->withDownload(self::FILENAME);
44
    }
45
}
46