• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Jagepard / Rudra-Cli / 15920986328

27 Jun 2025 07:42AM UTC coverage: 4.771% (-95.2%) from 100.0%
15920986328

push

github

web-flow
Merge pull request #29 from Jagepard/wip

adds commands

0 of 479 new or added lines in 20 files covered. (0.0%)

24 of 503 relevant lines covered (4.77%)

0.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Command/CreateContainerCommand.php
1
<?php
2

3
namespace Rudra\Cli\Command;
4

5
use App\Ship\Utils\FileCreator;
6
use Rudra\Container\Facades\Rudra;
7
use Rudra\Cli\Command\ConsoleFacade as Cli;
8

9
class CreateContainerCommand extends FileCreator
10
{
11
    /**
12
     * Creates a file with Seed data
13
     * -----------------------------
14
     * Создает файл с данными Seed
15
     */
NEW
16
    public function actionIndex(): void
×
17
    {
NEW
18
        Cli::printer("Enter container name: ", "magneta");
×
NEW
19
        $container = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
×
NEW
20
        $className = $container . 'Controller';
×
21

NEW
22
        if (!empty($container)) {
×
NEW
23
            if (is_dir(Rudra::config()->get('app.path') . "/app/Containers/$container/")) {
×
NEW
24
                Cli::printer("⚠️  Container '$container' already exists" . PHP_EOL, "light_yellow");
×
NEW
25
                return;
×
26
            }
27

NEW
28
            $this->writeFile(
×
NEW
29
                [Rudra::config()->get('app.path') . "/app/Containers/$container/", "{$className}.php"],
×
NEW
30
                $this->createContainersController($className, $container)
×
NEW
31
            );
×
32

NEW
33
            $this->writeFile(
×
NEW
34
                [Rudra::config()->get('app.path') . "/app/Containers/$container/", "routes.php"],
×
NEW
35
                $this->createRoutes()
×
NEW
36
            );
×
37

NEW
38
            $this->writeFile(
×
NEW
39
                [Rudra::config()->get('app.path') . "/app/Containers/$container/", "config.php"],
×
NEW
40
                $this->createConfig()
×
NEW
41
            );
×
42

NEW
43
            $this->addConfig($container);
×
NEW
44
            $this->createDirectories(Rudra::config()->get('app.path') . "/app/Containers/$container/");
×
NEW
45
            Cli::printer("✅ Container '$container' was created" . PHP_EOL, "light_green");
×
46

47
        } else {
NEW
48
            $this->actionIndex();
×
49
        }
50
    }
51

52
    /**
53
     * Creates class data
54
     * ------------------
55
     * Создает данные класса
56
     *
57
     * @param string $className
58
     * @param string $container
59
     * @return string
60
     */
NEW
61
    private function createContainersController(string $className, string $container): string
×
62
    {
NEW
63
        return <<<EOT
×
NEW
64
<?php
×
65

NEW
66
namespace App\Containers\\{$container};
×
67

68
use App\Ship\ShipController;
69
use Rudra\Container\Facades\Rudra;
70
use Rudra\View\ViewFacade as View;
71
use Rudra\Controller\ContainerControllerInterface;
72

NEW
73
class {$container}Controller extends ShipController implements ContainerControllerInterface
×
74
{
75
    public function containerInit(): void
76
    {
77
        \$config = require_once "config.php";
78

79
        Rudra::binding()->set(\$config['contracts']);
80
        Rudra::waiting()->set(\$config['services']);
81

NEW
82
        View::setup(dirname(__DIR__) . "/{$container}/UI/tmpl", "{$container}_");
×
83

84
        data([
85
            "title" => __CLASS__,
86
        ]);
87
    }
88
}\r\n
NEW
89
EOT;
×
90
    }
91

92
    /**
93
     * Creates routes
94
     * ------------------
95
     * Создает файл маршрутизатора
96
     */
NEW
97
    private function createRoutes(): string
×
98
    {
NEW
99
        return <<<EOT
×
100
<?php
101

102
return [
103
];\r\n
NEW
104
EOT;
×
105
    }
106

107
    /**
108
     * Creates config file
109
     * -------------------
110
     * Создает файл конфигурации
111
     */
NEW
112
    private function createConfig(): string
×
113
    {
NEW
114
        return <<<EOT
×
115
<?php
116

117
return [
118
    'contracts' => [
119

120
    ],
121
    'services'  => [
122

123
    ]
124
];\r\n
NEW
125
EOT;
×
126
    }
127

128
    /**
129
     * Create UI directories
130
     * ---------------------
131
     * Создает каталоги для UI
132
     *
133
     * @param string $path
134
     * @return void
135
     */
NEW
136
    private function createDirectories(string $path): void
×
137
    {
NEW
138
        if (!is_dir($path . 'UI')) {
×
NEW
139
            mkdir($path . 'UI', 0755, true);
×
140
        }
141

NEW
142
        if (!is_dir($path . 'UI/tmpl')) {
×
NEW
143
            mkdir($path . 'UI/tmpl', 0755, true);
×
144
        }
145
    }
146

NEW
147
    public function addConfig(string $container): void
×
148
    {
NEW
149
        $path      = Rudra::config()->get('app.path') . "/config/setting.local.yml";
×
NEW
150
        $namespace = strtolower($container) . ": App\Containers\\{$container}\\";
×
NEW
151
        $contents  = <<<EOT
×
NEW
152
        \r\n    $namespace
×
NEW
153
EOT;
×
NEW
154
        file_put_contents($path, $contents, FILE_APPEND | LOCK_EX);
×
155
    }
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc