• 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/CreateControllerCommand.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 CreateControllerCommand 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 controller name: ", "magneta");
×
NEW
19
        $controllerPrefix = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
×
20

NEW
21
        Cli::printer("Enter container: ", "magneta");
×
NEW
22
        $container = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
×
23

NEW
24
        if (!empty($container)) {
×
NEW
25
            if (!is_dir(Rudra::config()->get('app.path') . "/app/Containers/$container/")) {
×
NEW
26
                Cli::printer("⚠️  Container '$container' does not exist" . PHP_EOL, "light_yellow");
×
NEW
27
                return;
×
28
            }
29
            
NEW
30
            $this->writeFile(
×
NEW
31
                [Rudra::config()->get('app.path') . "/app/Containers/$container/Controller/", "{$controllerPrefix}Controller.php"],
×
NEW
32
                $this->createClass($controllerPrefix, $container)
×
NEW
33
            );
×
34

NEW
35
            $this->addRoute($container, $controllerPrefix);
×
36
        } else {
NEW
37
            $this->actionIndex();
×
38
        }
39
    }
40

41
    /**
42
     * Creates class data
43
     * ------------------
44
     * Создает данные класса
45
     *
46
     * @param string $controllerPrefix
47
     * @param string $container
48
     * @return string
49
     */
NEW
50
    private function createClass(string $controllerPrefix, string $container): string
×
51
    {
NEW
52
        $url = strtolower("$container/$controllerPrefix");
×
53

NEW
54
        if (Rudra::config()->get("attributes")) {
×
NEW
55
            return <<<EOT
×
NEW
56
            <?php
×
57
            
NEW
58
            namespace App\Containers\\{$container}\Controller;
×
59
            
NEW
60
            use App\Containers\\{$container}\\{$container}Controller;
×
61
            
NEW
62
            class {$controllerPrefix}Controller extends {$container}Controller
×
63
            {
NEW
64
                #[Routing(url: '{$url}', method: 'GET')]
×
65
                public function actionIndex(): void
66
                {
67
                    dd(__CLASS__);
68
                }
69
            }
70

NEW
71
            EOT;
×
72
        }
73

NEW
74
        return <<<EOT
×
NEW
75
<?php
×
76

NEW
77
namespace App\Containers\\{$container}\Controller;
×
78

NEW
79
use App\Containers\\{$container}\\{$container}Controller;
×
80

NEW
81
class {$controllerPrefix}Controller extends {$container}Controller
×
82
{
83
    /**
NEW
84
     * @Routing(url = '{$url}', method = 'GET')
×
85
     */
86
    public function actionIndex(): void
87
    {
88
        dd(__CLASS__);
89
    }
90
}
91

NEW
92
EOT;
×
93
    }
94

95
    /**
96
     * @param string $container
97
     * @param string $controllerPrefix
98
     * @return void
99
     */
NEW
100
    public function addRoute(string $container, string $controllerPrefix): void
×
101
    {
NEW
102
        $path   = Rudra::config()->get('app.path') . "/app/Containers/$container/routes.php";
×
NEW
103
        $routes = require_once $path;
×
NEW
104
        $namespace = "\App\Containers\\{$container}\\Controller\\{$controllerPrefix}Controller";
×
105

NEW
106
        if (!in_array($namespace, $routes)) {
×
NEW
107
            $contents = file_get_contents($path);
×
NEW
108
            $contents = str_replace("];", '', $contents);
×
NEW
109
            file_put_contents($path, $contents);
×
NEW
110
            $contents = <<<EOT
×
NEW
111
\t$namespace::class,
×
112
];
NEW
113
EOT;
×
NEW
114
            file_put_contents($path, $contents, FILE_APPEND | LOCK_EX);
×
115
        }
116
    }
117
}
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