Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Tests\Support\Database\Migrations;

use CodeIgniter\Database\Migration;
use Override;

class ExampleMigration extends Migration
{
protected $DBGroup = 'tests';

#[Override]
public function up(): void
{
$this->forge->addField('id');
Expand All @@ -30,6 +32,7 @@ public function up(): void
$this->forge->createTable('factories');
}

#[Override]
public function down(): void
{
$this->forge->dropTable('factories');
Expand Down
2 changes: 2 additions & 0 deletions admin/starter/tests/_support/Database/Seeds/ExampleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Tests\Support\Database\Seeds;

use CodeIgniter\Database\Seeder;
use Override;

class ExampleSeeder extends Seeder
{
#[Override]
public function run(): void
{
$factories = [
Expand Down
2 changes: 2 additions & 0 deletions app/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Override;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -34,6 +35,7 @@ abstract class BaseController extends Controller
*
* @return void
*/
#[Override]
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
// Load here all helpers you want to be available in your controllers that extend BaseController.
Expand Down
4 changes: 4 additions & 0 deletions docs/cli/cli_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ namespace App\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Override;

class AppInfo extends BaseCommand
{
protected $group = 'Demo';
protected $name = 'app:info';
protected $description = 'Displays basic application information.';

#[Override]
public function run(array $params)
{
// ...
Expand Down Expand Up @@ -85,11 +87,13 @@ namespace App\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Override;

class AppInfo extends BaseCommand
{
// ...

#[Override]
public function run(array $params)
{
CLI::write('PHP Version: ' . CLI::color(PHP_VERSION, 'yellow'));
Expand Down
2 changes: 2 additions & 0 deletions docs/cli/cli_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ namespace App\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Override;

class MyCommand extends BaseCommand
{
// ...

#[Override]
public function run(array $params)
{
// ...
Expand Down
41 changes: 41 additions & 0 deletions docs/cli/cli_modern_commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ namespace App\Commands;

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use Override;

#[Command(name: 'app:greet', description: 'Prints a greeting.', group: 'App')]
class AppGreet extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
$this->getOutput()->write('Hello!', 'green');
Expand Down Expand Up @@ -60,6 +62,7 @@ namespace App\Commands;

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use Override;

#[Command(
name: 'app:deploy',
Expand All @@ -69,6 +72,7 @@ use CodeIgniter\CLI\Attributes\Command;
)]
class AppDeploy extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
// Reachable as `php spark app:deploy`, `php spark app:ship`, or `php spark deploy`.
Expand All @@ -89,6 +93,7 @@ namespace App\Commands;

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use Override;

#[Command(
name: 'app:reindex',
Expand All @@ -98,6 +103,7 @@ use CodeIgniter\CLI\Attributes\Command;
)]
class AppReindex extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
// Not shown by `php spark list`, but `php spark app:reindex` still runs it.
Expand Down Expand Up @@ -134,6 +140,7 @@ namespace App\Commands;

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use Override;

#[Command(
name: 'app:status',
Expand All @@ -143,6 +150,7 @@ use CodeIgniter\CLI\Attributes\Command;
)]
class AppStatus extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
$this->getOutput()->write(json_encode(['status' => 'ok'], JSON_THROW_ON_ERROR));
Expand Down Expand Up @@ -181,10 +189,12 @@ namespace App\Commands;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Argument;
use Override;

#[Command(name: 'app:greet', description: 'Greets people.', group: 'App')]
class AppGreet extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this
Expand All @@ -208,6 +218,7 @@ class AppGreet extends AbstractCommand
));
}

#[Override]
protected function execute(array $arguments, array $options): int
{
// ...
Expand Down Expand Up @@ -238,10 +249,12 @@ namespace App\Commands;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Option;
use Override;

#[Command(name: 'app:publish', description: 'Publishes assets.', group: 'App')]
class AppPublish extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this
Expand Down Expand Up @@ -282,6 +295,7 @@ class AppPublish extends AbstractCommand
));
}

#[Override]
protected function execute(array $arguments, array $options): int
{
// ...
Expand Down Expand Up @@ -346,10 +360,12 @@ namespace App\Commands;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Option;
use Override;

#[Command(name: 'logs:clear', description: 'Clears logs.', group: 'Housekeeping')]
class ClearLogs extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this->addOption(new Option(
Expand All @@ -359,6 +375,7 @@ class ClearLogs extends AbstractCommand
));
}

#[Override]
protected function interact(array &$arguments, array &$options): void
{
// hasUnboundOption() resolves --force, -f, and --no-force in one call,
Expand All @@ -376,6 +393,7 @@ class ClearLogs extends AbstractCommand
$options['force'] = null;
}

#[Override]
protected function execute(array $arguments, array $options): int
{
if ($this->getValidatedOption('force') === false) {
Expand Down Expand Up @@ -406,10 +424,12 @@ use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Argument;
use CodeIgniter\CLI\PromptsForMissingInputInterface;
use Override;

#[Command(name: 'app:greet', description: 'Greets people.', group: 'App')]
class AppGreet extends AbstractCommand implements PromptsForMissingInputInterface
{
#[Override]
protected function configure(): void
{
$this->addArgument(new Argument(
Expand All @@ -419,11 +439,13 @@ class AppGreet extends AbstractCommand implements PromptsForMissingInputInterfac
));
}

#[Override]
protected function getArgumentPromptLabels(): array
{
return ['name' => 'Who should be greeted?'];
}

#[Override]
protected function execute(array $arguments, array $options): int
{
$this->getOutput()->write(sprintf('Hello, %s!', $arguments['name']), 'green');
Expand Down Expand Up @@ -477,16 +499,19 @@ namespace App\Commands;

use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use Override;

#[Command(name: 'dev:only', description: 'A dev only command', group: 'Dev')]
class DevOnly extends AbstractCommand
{
#[Override]
protected function isAvailable(): bool
{
// Only allow this command in the development environment
return ENVIRONMENT === 'development';
}

#[Override]
protected function execute(array $arguments, array $options): int
{
// ...
Expand Down Expand Up @@ -526,17 +551,20 @@ use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Argument;
use CodeIgniter\CLI\Input\Option;
use Override;

#[Command(name: 'app:demo', description: 'Demonstrates accessors.', group: 'App')]
class AppDemo extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this
->addArgument(new Argument(name: 'name', required: true))
->addOption(new Option(name: 'loud', negatable: true, default: false));
}

#[Override]
protected function execute(array $arguments, array $options): int
{
// Directly from the parameters:
Expand Down Expand Up @@ -572,10 +600,12 @@ namespace App\Commands;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Table;
use Override;

#[Command(name: 'app:report', description: 'Prints a report.', group: 'App')]
class AppReport extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
$output = $this->getOutput();
Expand Down Expand Up @@ -621,10 +651,12 @@ use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Table;
use CodeIgniter\CLI\Verbosity;
use Override;

#[Command(name: 'app:sync', description: 'Synchronizes the records.', group: 'App')]
class AppSync extends AbstractCommand
{
#[Override]
protected function execute(array $arguments, array $options): int
{
$output = $this->getOutput();
Expand Down Expand Up @@ -708,10 +740,12 @@ namespace App\Commands;
use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Argument;
use Override;

#[Command(name: 'app:greet', description: 'Greets people.', group: 'App')]
class AppGreet extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this
Expand All @@ -722,6 +756,7 @@ class AppGreet extends AbstractCommand
->addUsage('app:greet "Bob the Builder"');
}

#[Override]
protected function execute(array $arguments, array $options): int
{
// ...
Expand Down Expand Up @@ -797,6 +832,7 @@ namespace App\Commands;

use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
use Override;
use Throwable;

class Publish extends BaseCommand
Expand All @@ -811,6 +847,7 @@ class Publish extends BaseCommand
'--dry-run' => 'Print the plan without writing anything.',
];

#[Override]
public function run(array $params)
{
try {
Expand Down Expand Up @@ -853,11 +890,13 @@ use CodeIgniter\CLI\AbstractCommand;
use CodeIgniter\CLI\Attributes\Command;
use CodeIgniter\CLI\Input\Argument;
use CodeIgniter\CLI\Input\Option;
use Override;
use Throwable;

#[Command(name: 'app:publish', description: 'Publishes something.', group: 'App')]
class Publish extends AbstractCommand
{
#[Override]
protected function configure(): void
{
$this
Expand All @@ -866,13 +905,15 @@ class Publish extends AbstractCommand
->addOption(new Option(name: 'dry-run', description: 'Print the plan without writing anything.'));
}

#[Override]
protected function interact(array &$arguments, array &$options): void
{
if ($arguments === []) {
$arguments[] = $this->getPrompt()->ask('What should I publish?', null, 'required');
}
}

#[Override]
protected function execute(array $arguments, array $options): int
{
try {
Expand Down
Loading
Loading