-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExampleDI.php
More file actions
69 lines (62 loc) · 1.74 KB
/
ExampleDI.php
File metadata and controls
69 lines (62 loc) · 1.74 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* FOSSBilling.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license Apache-2.0
*
* Copyright FOSSBilling 2022
* This software may contain code previously used in the BoxBilling project.
* Copyright BoxBilling, Inc 2011-2021
*
* This source file is subject to the Apache-2.0 License that is bundled
* with this source code in the file LICENSE
*/
namespace Box\Mod\Example\Commands;
use Pimple\Container;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'example:clear',
description: 'Clear your cache for example',
hidden: false
)]
class ExampleDI extends Command implements \FOSSBilling\InjectionAwareInterface
{
protected ?Container $di = null;
/**
* @param Container $di
* @return void
*/
public function setDi(Container $di): void
{
$this->di = $di;
}
/**
* @return Container|null
*/
public function getDi(): ?Container
{
return $this->di;
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$service = $this->di['mod_service']('system');
try {
$service->clearCache();
} catch (\Exception $e) {
$output->writeln('<error>An error occurred: ' . $e->getMessage() . '</error>');
return Command::FAILURE;
} finally {
$output->writeln('<info>Successfully cleared the cache.</info>');
return Command::SUCCESS;
}
}
}