Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace Command arguments with MakerParams #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

jrushlow
Copy link
Collaborator

@jrushlow jrushlow commented Jun 1, 2020

Currently every maker abuses the intended usage of Command arguments - which were meant to be values that are passed to a command. E.g.

$> some-command --arg=value

Command arguments can either be required or optional. But, due to the way all current Makers use Command arguments as questions - they are all optional in regards to their intended usage.

This PR introduces a new MakerParam object that is stored in AbstractMaker::makerParams with a getMakerParamValue() and setMakerParam() *open to suggestions on naming conventions

As a side affect of declaring arguments first, then setting them. Makers rely heavily on what is essentially a null|mixed return type for $input->getArgument(). An example would be passing arguments to a template - then the template has a conditional for that argument. In the example below, a value for $my-var may not exist depending on the flow of interact()

// MakeX

public function generate(..Generator $generator): void
{
    $generator->generateController('Some\\Name\\', 'template.tpl.php', [
        'my-var' => $input->getArgument('x')
    ]);
}

// template.tpl.php
<? if ($some-other-arg): ?> 
    ...
<? else: ?>
    <?= $my-var ?>
<? endif; ?>

While we would ideally like to get away from having to declare an argument, set a value, then get that value; this PR does not fully address that situation. One could use a conditional in the generate method or the newly introduced $this->getMakerParamValue() could return null if that argument doesn't exist. The latter does not feel right IMO. As such, we are declaring all of the arguments first in configure() so we don't run into a NotFoundException or the like in generate(). Open to ideas on this part...

The MakeRegistrationForm maker was used to demonstrate the new feature. Other makers would be able to be converted in the future.

@jrushlow jrushlow changed the title Introduce MakerArgumentCollection as a replacement for Command arguments Replace Command arguments with MakerParams Jun 14, 2020
@jrushlow
Copy link
Collaborator Author

Shelving this PR for now - experimenting with maker properties in upcoming docker feature instead...

@jrushlow jrushlow closed this Jun 29, 2020
@jrushlow jrushlow deleted the feature/argument-collection branch May 3, 2022 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant