Browse code

Implement API authentication and replace test api command to show Shopware status

Benjamin Roth authored on20/10/2024 22:11:52
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,62 @@
1
+<?php
2
+
3
+declare(strict_types=1);
4
+
5
+/*
6
+ * This file is part of vonRotenberg Shopware API Bundle.
7
+ *
8
+ * (c) vonRotenberg
9
+ *
10
+ * @license proprietary
11
+ */
12
+
13
+namespace vonRotenberg\ShopwareApiBundle\Command;
14
+
15
+use Contao\CoreBundle\Framework\ContaoFramework;
16
+use Contao\System;
17
+use Symfony\Component\Console\Command\Command;
18
+use Symfony\Component\Console\Input\InputInterface;
19
+use Symfony\Component\Console\Output\OutputInterface;
20
+use Symfony\Component\Console\Style\SymfonyStyle;
21
+use vonRotenberg\ShopwareApiBundle\API\Shopware;
22
+
23
+class ShopwareSystemStatus extends Command
24
+{
25
+    protected static $defaultName = 'shopware:system-status';
26
+
27
+    protected $framework;
28
+
29
+    public function __construct(ContaoFramework $framework)
30
+    {
31
+        $this->framework = $framework;
32
+
33
+        parent::__construct();
34
+    }
35
+
36
+    protected function configure(): void
37
+    {
38
+        $this
39
+            ->setName(self::$defaultName)
40
+            ->setDescription('Show Shopware status')
41
+        ;
42
+    }
43
+    protected function execute(InputInterface $input, OutputInterface $output): int
44
+    {
45
+        $this->framework->initialize();
46
+
47
+        $io = new SymfonyStyle($input, $output);
48
+        $io->title('Shopware system status');
49
+
50
+        /** @var Shopware $Shopware */
51
+        $Shopware = System::getContainer()->get(Shopware::class);
52
+
53
+        if ($Shopware->isShopwareRunning())
54
+        {
55
+            $io->success('Shopware system is running');
56
+        } else {
57
+            $io->error('Shopware system is not running properly');
58
+        }
59
+
60
+        return 0;
61
+    }
62
+}