![]() |
Hello friends.
How can I enable Suffix by default without using the command(php spark mycommand --suffix)? Is there anyone here who can help?
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. 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.
Override the method in your command class.
(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/CodeIgni...it.php#L76 to private $enabledSuffixing = false; and line https://github.com/codeigniter4/CodeIgni...t.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?
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/CodeIgni...#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
Thanks @paulbalandan , the explanation was complete and clear. This works well.
@kenjis Thank you too. |
Welcome Guest, Not a member yet? Register Sign In |