Download src/Plugin/Application/CommandHandlers/InstallPluginCommandHandler.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Plugin/Application/CommandHandlers/InstallPluginCommandHandler.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Plugin/Application/CommandHandlers/InstallPluginCommandHandler.php
-
curl -L -o InstallPluginCommandHandler.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Plugin/Application/CommandHandlers/InstallPluginCommandHandler.php
1.65 kB
| declare(strict_types=1); | |
| namespace Plugin\Application\CommandHandlers; | |
| use Easy\Container\Attributes\Inject; | |
| use Plugin\Application\Commands\InstallPluginCommand; | |
| use Plugin\Domain\Context; | |
| use Plugin\Domain\Exceptions\PluginNotFoundException; | |
| use Plugin\Domain\Repositories\PluginRepositoryInterface; | |
| use Plugin\Domain\ValueObjects\Status; | |
| use Plugin\Infrastructure\Helpers\ComposerHelper; | |
| use RuntimeException; | |
| use Shared\Infrastructure\CacheManager; | |
| use Symfony\Component\Console\Output\BufferedOutput; | |
| class InstallPluginCommandHandler | |
| { | |
| public function __construct( | |
| private PluginRepositoryInterface $repo, | |
| private ComposerHelper $helper, | |
| private CacheManager $cache, | |
| #[Inject('config.dirs.plugins')] | |
| private string $pluginsDir | |
| ) { | |
| } | |
| public function handle(InstallPluginCommand $cmd): void | |
| { | |
| try { | |
| $pw = $this->repo->ofName($cmd->name); | |
| } catch (PluginNotFoundException $th) { | |
| $pw = null; | |
| } | |
| $output = new BufferedOutput(); | |
| if ($pw) { | |
| $code = $this->helper->reinstall($cmd->name->value, $output); | |
| } else { | |
| $code = $this->helper->require($cmd->name->value, $output); | |
| } | |
| if ($code !== 0) { | |
| throw new RuntimeException( | |
| "Failed to install plugin with following code: " . $output->fetch() | |
| ); | |
| } | |
| // Set status to inactive | |
| $context = new Context($this->pluginsDir . '/' . $cmd->name->value); | |
| $context->setStatus(Status::INACTIVE); | |
| // Clear cache | |
| $this->cache->clearCache(); | |
| } | |
| } | |