Skip to content

Commit

Permalink
Add an example for DI
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianGabs committed Jun 26, 2024
1 parent 21a349d commit 844d90b
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/Console/ExampleDI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?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\Console;

use Pimple\Container;
use CristianG\PimpleConsole\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


class ExampleDI extends Command implements \FOSSBilling\InjectionAwareInterface

Check failure on line 25 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Class Box\Mod\Example\Console\ExampleDI extends unknown class CristianG\PimpleConsole\Command.
{
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;
}

/**
* @return void
*/
protected function configure(): void
{
$this->setName('example:clear');

Check failure on line 51 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Call to an undefined method Box\Mod\Example\Console\ExampleDI::setName().
$this->setDescription('Clear your cache in example');

Check failure on line 52 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Call to an undefined method Box\Mod\Example\Console\ExampleDI::setDescription().
parent::configure();

Check failure on line 53 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Box\Mod\Example\Console\ExampleDI::configure() calls parent::configure() but Box\Mod\Example\Console\ExampleDI does not extend any class.
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int

Check failure on line 61 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Parameter $input of method Box\Mod\Example\Console\ExampleDI::execute() has invalid type Symfony\Component\Console\Input\InputInterface.

Check failure on line 61 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Parameter $output of method Box\Mod\Example\Console\ExampleDI::execute() has invalid type Symfony\Component\Console\Output\OutputInterface.
{
$service = $this->di['mod_service']('system');
try {
$service->clearCache();
} catch (\Exception $e) {
$this->error("An error occurred: ".$e->getMessage());

Check failure on line 67 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Call to an undefined method Box\Mod\Example\Console\ExampleDI::error().
return Command::FAILURE;

Check failure on line 68 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Access to constant FAILURE on an unknown class CristianG\PimpleConsole\Command.
} finally {
$this->info("Successfully cleared the cache.");

Check failure on line 70 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Call to an undefined method Box\Mod\Example\Console\ExampleDI::info().
return Command::SUCCESS;

Check failure on line 71 in src/Console/ExampleDI.php

View workflow job for this annotation

GitHub Actions / PHPStan - FOSSBilling Release

Access to constant SUCCESS on an unknown class CristianG\PimpleConsole\Command.
}
}
}

0 comments on commit 844d90b

Please sign in to comment.