Passed
Push — 6.5.0.0 ( 85bd4e...fe6596 )
by Christian
24:46 queued 09:10
created

InstallController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 23 1
A index() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Controller;
5
6
use App\Services\RecoveryManager;
7
use App\Services\StreamedCommandResponseGenerator;
8
use Shopware\Core\Framework\Log\Package;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpFoundation\StreamedResponse;
13
use Symfony\Component\Process\Process;
14
use Symfony\Component\Routing\Annotation\Route;
15
16
/**
17
 * @internal
18
 */
19
#[Package('core')]
20
class InstallController extends AbstractController
21
{
22
    public function __construct(
23
        private readonly RecoveryManager $recoveryManager,
24
        private readonly StreamedCommandResponseGenerator $streamedCommandResponseGenerator
25
    ) {
26
    }
27
28
    #[Route('/install', name: 'install', defaults: ['step' => 2])]
29
    public function index(): Response
30
    {
31
        return $this->render('install.html.twig');
32
    }
33
34
    #[Route('/install/_run', name: 'install_run', methods: ['POST'])]
35
    public function run(Request $request): StreamedResponse
36
    {
37
        $folder = $request->query->get('folder', 'shopware');
38
39
        $finish = function (Process $process) use ($request, $folder): void {
40
            echo json_encode([
41
                'success' => $process->isSuccessful(),
42
                'newLocation' => $request->getBasePath() . '/' . $folder . '/public/',
43
            ]);
44
        };
45
46
        return $this->streamedCommandResponseGenerator->run([
47
            $this->recoveryManager->getPhpBinary($request),
48
            $this->recoveryManager->getBinary(),
49
            'composer',
50
            'create-project',
51
            'shopware/production:dev-flex',
52
            '--no-interaction',
53
            '--no-ansi',
54
            '-v',
55
            $folder,
56
        ], $finish);
57
    }
58
}
59