Skip to content
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

feat: new command shield:extend #1141

Closed

Conversation

warcooft
Copy link
Contributor

@warcooft warcooft commented Jul 8, 2024

Description
This PRs provide a new command shield:extend to easily extend any controller.

The Command's Usage

shield:extend

The Command's Options

protected $options = [
        '-i' => 'The index of shield controllers to be extending in your app.',
        '-f' => 'Force overwrite ALL existing files in destination.',
    ];

Example:

this@PC playground % php spark shield:extend   

CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-07-09 05:32:31 UTC+07:00

List of the controller that will be extend:

  [1] LoginController
  [2] MagicLinkController
  [3] RegisterController

Please select one of these (1/2/3) : 3

  Created: APPPATH/Controllers/RegisterController.php
  After extending, don't forget to change the route. See https://shield.codeigniter.com/customization/route_config

Example when the controller already exists:

this@PC playground % php spark shield:extend        

CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-07-09 05:30:57 UTC+07:00

List of the controller that will be extend:

  [1] LoginController
  [2] MagicLinkController
  [3] RegisterController

Please select one of these (1/2/3) : 3
  File 'APPPATH/Controllers/RegisterController.php' already exists in destination. Overwrite? [n, y]: y

  Created: APPPATH/Controllers/RegisterController.php
  After extending, don't forget to change the route. See https://shield.codeigniter.com/customization/route_config

Or we can use the full option as below:

this@PC playground % php spark shield:extend -i 3 -f

CodeIgniter v4.5.3 Command Line Tool - Server Time: 2024-07-09 05:27:18 UTC+07:00


  Created: APPPATH/Controllers/RegisterController.php
  After extending, don't forget to change the route. See https://shield.codeigniter.com/customization/route_config

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the enhancement New feature or request label Jul 10, 2024
public function run(array $params)
{
$this->replacer = new ContentReplacer();
$this->sourcePath = __DIR__ . '/../../examples/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to have examples?
I think we should avoid maintaining both the original controller and the controller in Examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an example to provide a simple way to create an extended controller because in some cases we need to customize the controller. I did not copy all the methods from the source, only some parts that most likely need to be modified.

This is quite helpful for novice users like me, if you guys do not agree with this way, feel free to close this PRs.

@kenjis kenjis added the tests needed Pull requests that need tests label Jul 10, 2024
@kenjis
Copy link
Member

kenjis commented Jul 10, 2024

Also, please fix errors in GitHub Action checks, and add test code.
Reference: https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md

@warcooft warcooft closed this Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tests needed Pull requests that need tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants