How can I activate Suffix without using --suffix? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: How can I activate Suffix without using --suffix? (/showthread.php?tid=81857) |
How can I activate Suffix without using --suffix? - datamweb - 05-11-2022 Hello friends. How can I enable Suffix by default without using the command(php spark mycommand --suffix)? Is there anyone here who can help? RE: How can I activate Suffix without using --suffix? - kenjis - 05-11-2022 It seems $enabledSuffixing can only disable `--suffix` option. If you want to make a new command, implement it as you like. If you want to change the existing spark command behavior, it seems there is no easy way to do so. RE: How can I activate Suffix without using --suffix? - datamweb - 05-11-2022 Quote:If you want to make a new command, implement it as you like. In the my command I use the GeneratorTrait, so this method can not be used. RE: How can I activate Suffix without using --suffix? - kenjis - 05-11-2022 Override the method in your command class. RE: How can I activate Suffix without using --suffix? - datamweb - 05-11-2022 (05-11-2022, 01:17 AM)kenjis Wrote: Override the method in your command class. CodeIgniter4\system\Commands\Generators\ConfigGenerator.php Code: <?php CodeIgniter4\tests\system\Commands\ConfigGeneratorTest.php Code: <?php In this case, this test will be fielded. if change line https://github.com/codeigniter4/CodeIgniter4/blob/5ccb5036f1cb3cc17c831fe9a8d25d31d1e73dd4/system/CLI/GeneratorTrait.php#L76 to private $enabledSuffixing = false; and line https://github.com/codeigniter4/CodeIgniter4/blob/5ccb5036f1cb3cc17c831fe9a8d25d31d1e73dd4/system/CLI/GeneratorTrait.php#L211 to if (($this->enabledSuffixing || $this->getOption('suffix')) && ! strripos($class, $component)) { In this case, this test will be OK. That the user can easily change the value of $enabledSuffixing in command class. Do you have a specific reason for not changing it? RE: How can I activate Suffix without using --suffix? - paulbalandan - 05-17-2022 That one was added by me so I would answer. PHP Code: /** As you can see, the $enabledSuffixing flag controls whether or not the option flag --suffix makes any effect when passed to the spark call. This flag is enabled by default. Why I did this? Because of the original refactor of the Generator, no matter what I do the component suffix is always attaching to the name of the output. So I need a way that developers could control whether the `--suffix` flag has any effect. Changing the logic to your proposal would be a deviation from the original intent of $enabledSuffixing. That means to say, that line is not the right line to solve your use case. I propose this. 1. Add a protected method to the GeneratorTrait: PHP Code: protected function getSuffixedName(string $class, string $component): string 2. These lines (https://github.com/codeigniter4/CodeIgniter4/blob/8ddc566fb2d007f6a84192ee8ffcd07bb6bfe3df/system/CLI/GeneratorTrait.php#L211-L214) get changed to: PHP Code: $class = $this->getSuffixedName($class, $component); 3. In your own generator class, override the `getSuffixedName()` method: PHP Code: protected function getSuffixedName(string $class, string $component): string RE: How can I activate Suffix without using --suffix? - datamweb - 05-19-2022 Thanks @paulbalandan , the explanation was complete and clear. This works well. @kenjis Thank you too. |