Welcome Guest, Not a member yet? Register   Sign In
How can I activate Suffix without using --suffix?
#6

(This post was last modified: 05-17-2022, 09:19 AM by paulbalandan.)

That one was added by me so I would answer.

PHP Code:
/**
   * Whether the `--suffix` option has any effect.
   *
   * @internal
   *
   * @var bool
   */
private $enabledSuffixing true

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 $classstring $component): string
{
        if (
$this->enabledSuffixing && $this->getOption('suffix') && ! strripos($class$component)) {
                
$class .= ucfirst($component);
        }

        return 
$class;


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 $classstring $component): string
{
        if (! 
strripos($class$component)) {
                
$class .= ucfirst($component);
        }

        return 
$class;

Reply


Messages In This Thread
RE: How can I activate Suffix without using --suffix? - by paulbalandan - 05-17-2022, 08:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB