-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: Add isAvailable() method to AbstractCommand
#10228
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
Open
patel-vansh
wants to merge
9
commits into
codeigniter4:4.8
Choose a base branch
from
patel-vansh:feat/is-available-method
base: 4.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3c7a418
feat: Add `isAvailable()` method to AbstractCommand
patel-vansh 3c1bd8a
Add docs and changelog
patel-vansh f5f4946
cs-fix
patel-vansh 37d1d5b
fix some english and references
patel-vansh 626aa09
apply suggestions
patel-vansh 0558c64
Add period
patel-vansh 2bd8c64
apply suggestions
patel-vansh e05b978
Added more tests
patel-vansh afd53b9
Revert PHPStorm's auto styled code
patel-vansh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This file is part of CodeIgniter 4 framework. | ||
| * | ||
| * (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
| * | ||
| * For the full copyright and license information, please view | ||
| * the LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace CodeIgniter\CLI\Exceptions; | ||
|
|
||
| use CodeIgniter\Exceptions\RuntimeException; | ||
|
|
||
| /** | ||
| * Exception thrown when a command is found but is not currently available for execution. | ||
| */ | ||
| final class CommandNotAvailableException extends RuntimeException | ||
| { | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/_support/Commands/Modern/UnavailableFixtureCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * This file is part of CodeIgniter 4 framework. | ||
| * | ||
| * (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
| * | ||
| * For the full copyright and license information, please view | ||
| * the LICENSE file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Tests\Support\Commands\Modern; | ||
|
|
||
| use CodeIgniter\CLI\AbstractCommand; | ||
| use CodeIgniter\CLI\Attributes\Command; | ||
|
|
||
| #[Command(name: 'test:unavailable', description: 'Fixture command to test runtime availability checks.', group: 'Tests')] | ||
| final class UnavailableFixtureCommand extends AbstractCommand | ||
| { | ||
| public static bool $initializeCalled = false; | ||
| public static bool $interactCalled = false; | ||
| public static bool $executeCalled = false; | ||
| public static bool $available = true; | ||
|
|
||
| public static function reset(): void | ||
| { | ||
| self::$initializeCalled = false; | ||
| self::$interactCalled = false; | ||
| self::$executeCalled = false; | ||
| self::$available = true; | ||
| } | ||
|
|
||
| protected function isAvailable(): bool | ||
| { | ||
| return self::$available; | ||
| } | ||
|
|
||
| protected function initialize(array &$arguments, array &$options): void | ||
| { | ||
| self::$initializeCalled = true; | ||
| } | ||
|
|
||
| protected function interact(array &$arguments, array &$options): void | ||
| { | ||
| self::$interactCalled = true; | ||
| } | ||
|
|
||
| protected function execute(array $arguments, array $options): int | ||
| { | ||
| self::$executeCalled = true; | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| namespace App\Commands; | ||
|
|
||
| use CodeIgniter\CLI\AbstractCommand; | ||
| use CodeIgniter\CLI\Attributes\Command; | ||
|
|
||
| #[Command(name: 'dev:only', description: 'A dev only command', group: 'Dev')] | ||
| class DevOnly extends AbstractCommand | ||
| { | ||
| protected function isAvailable(): bool | ||
| { | ||
| // Only allow this command in the development environment | ||
| return ENVIRONMENT === 'development'; | ||
| } | ||
|
|
||
| protected function execute(array $arguments, array $options): int | ||
| { | ||
| // ... | ||
|
|
||
| return EXIT_SUCCESS; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.