aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands/DI/Reset.php
blob: 646bfb6eaa2addeebb12000023acb961732d3f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace Studip\Cli\Commands\DI;

use Studip\DIContainer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Reset extends Command
{
    protected static $defaultName = 'di:reset';

    protected function configure(): void
    {
        $this->setDescription('Resets the compiled DI container');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $file = DIContainer::getCompilationPath() . '/' . DIContainer::getCompilationClass() . '.php';

        if (file_exists($file) && !unlink($file)) {
            $output->writeln('<error>Could not removed compiled file.</error>');
            return Command::FAILURE;
        }

        return Command::SUCCESS;
    }
}