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

drago-ex / generator / 20589120020

30 Dec 2025 04:48AM UTC coverage: 81.818% (-2.2%) from 84.0%
20589120020

push

github

accgit
dev

24 of 32 new or added lines in 1 file covered. (75.0%)

198 of 242 relevant lines covered (81.82%)

1.64 hits per line

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

87.1
/src/Drago/Generator/DI/GeneratorExtension.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Drago\Generator\DI;
6

7
use Doctrine\Inflector\Inflector;
8
use Doctrine\Inflector\NoopWordInflector;
9
use Drago\Database\Entity;
10
use Drago\Generator\Command\DataClassCommand;
11
use Drago\Generator\Command\EntityCommand;
12
use Drago\Generator\Generator\DataClassGenerator;
13
use Drago\Generator\Generator\EntityGenerator;
14
use Drago\Generator\Options;
15
use Drago\Generator\Repository;
16
use Drago\Utils\ExtraArrayHash;
17
use Nette\DI\CompilerExtension;
18
use Nette\DI\Definitions\ServiceDefinition;
19
use Nette\Schema\Expect;
20
use Nette\Schema\Processor;
21
use Nette\Schema\Schema;
22
use Symfony\Component\Console\Command\Command;
23

24

25
final class GeneratorExtension extends CompilerExtension
26
{
27
        private bool $consoleMode;
28

29

30
        public function __construct(bool $consoleMode = false)
2✔
31
        {
32
                $this->consoleMode = $consoleMode;
2✔
33
        }
2✔
34

35

36
        public function getConfigSchema(): Schema
37
        {
38
                return Expect::structure([
2✔
39
                        'lower' => Expect::bool(false),
2✔
40
                        'path' => Expect::string(''),
2✔
41
                        'tableName' => Expect::string()->nullable(),
2✔
42
                        'primaryKey' => Expect::string()->nullable(),
2✔
43
                        'columnInfo' => Expect::bool(false),
2✔
44
                        'constant' => Expect::bool(true),
2✔
45
                        'constantSize' => Expect::bool(false),
2✔
46
                        'constantPrefix' => Expect::string()->nullable(),
2✔
47
                        'references' => Expect::bool(false),
2✔
48
                        'suffix' => Expect::string('Entity'),
2✔
49
                        'extendsOn' => Expect::bool(true),
2✔
50
                        'extends' => Expect::string(Entity::class),
2✔
51
                        'final' => Expect::bool(false),
2✔
52
                        'namespace' => Expect::string('App\Entity'),
2✔
53

54
                        // Data class
55
                        'pathDataClass' => Expect::string(''),
2✔
56
                        'constantDataClass' => Expect::bool(true),
2✔
57
                        'constantDataPrefix' => Expect::string()->nullable(),
2✔
58
                        'constantSizeDataClass' => Expect::bool(true),
2✔
59
                        'referencesDataClass' => Expect::bool(false),
2✔
60
                        'suffixDataClass' => Expect::string('Data'),
2✔
61
                        'extendsDataClass' => Expect::string(ExtraArrayHash::class),
2✔
62
                        'finalDataClass' => Expect::bool(false),
2✔
63
                        'namespaceDataClass' => Expect::string('App\Data'),
2✔
64
                ]);
65
        }
66

67

68
        public function loadConfiguration(): void
69
        {
70
                $builder = $this->getContainerBuilder();
2✔
71

72
                // Repository
73
                $builder->addDefinition($this->prefix('repository'))
2✔
74
                        ->setFactory(Repository::class);
2✔
75

76
                // Word inflector
77
                $builder->addDefinition($this->prefix('wordInflector'))
2✔
78
                        ->setFactory(NoopWordInflector::class);
2✔
79

80
                // Inflector
81
                $builder->addDefinition($this->prefix('inflector'))
2✔
82
                        ->setFactory(Inflector::class, [
2✔
83
                                '@' . $this->prefix('wordInflector'),
2✔
84
                                '@' . $this->prefix('wordInflector'),
2✔
85
                        ]);
86

87
                // Normalize config
88
                $processor = new Processor();
2✔
89
                $options = $processor->process(
2✔
90
                        Expect::from(new Options),
2✔
91
                        $this->config
2✔
92
                );
93

94
                // Entity generator
95
                $builder->addDefinition($this->prefix('entityGenerator'))
2✔
96
                        ->setFactory(EntityGenerator::class, [
2✔
97
                                '@' . $this->prefix('repository'),
2✔
98
                                $options,
2✔
99
                                '@' . $this->prefix('inflector'),
2✔
100
                        ]);
101

102
                // Data class generator
103
                $builder->addDefinition($this->prefix('dataClassGenerator'))
2✔
104
                        ->setFactory(DataClassGenerator::class, [
2✔
105
                                '@' . $this->prefix('repository'),
2✔
106
                                $options,
2✔
107
                                '@' . $this->prefix('inflector'),
2✔
108
                        ]);
109

110
                // CLI commands
111
                if ($this->consoleMode) {
2✔
NEW
112
                        $builder->addDefinition($this->prefix('entityCommand'))
×
NEW
113
                                ->setFactory(EntityCommand::class);
×
114

NEW
115
                        $builder->addDefinition($this->prefix('dataClassCommand'))
×
NEW
116
                                ->setFactory(DataClassCommand::class);
×
117
                }
118
        }
2✔
119

120

121
        public function beforeCompile(): void
122
        {
123
                if (!$this->consoleMode) {
2✔
124
                        return;
2✔
125
                }
126

NEW
127
                $builder = $this->getContainerBuilder();
×
NEW
128
                $commands = $builder->findByType(Command::class);
×
129

NEW
130
                foreach ($commands as $serviceName => $serviceDef) {
×
131
                        assert($serviceDef instanceof ServiceDefinition);
NEW
132
                        $serviceDef->addTag('console.command');
×
133
                }
134
        }
135
}
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