codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
351 stars 123 forks source link

feat: new command shield:extend #1141

Open warcooft opened 2 weeks ago

warcooft commented 2 weeks ago

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:

kenjis commented 2 weeks ago

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