Skip to content

Commit 498ff89

Browse files
committed
Guards Tinker command execution
Adds a check to ensure the `tinker` command is only executed within a Laravel application. This prevents the command from running in non-Laravel contexts, which would lead to errors and unexpected behavior.
1 parent a3c2fa5 commit 498ff89

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Commands/Tinker.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ protected function configure(): void
2323

2424
protected function execute(InputInterface $input, OutputInterface $output): int
2525
{
26+
if (!$this->isLaravelApplication()) {
27+
IO::writeln(Styles::red('This command can only be run in a Laravel application.'));
28+
return 1;
29+
}
30+
2631
IO::writeln([Styles::brefHeader(), '']);
2732

2833
$brefCloudConfig = $this->parseStandardOptions($input);
@@ -48,4 +53,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4853
return 1;
4954
}
5055
}
56+
57+
protected function isLaravelApplication(): bool
58+
{
59+
$composerContent = file_get_contents('composer.json');
60+
if ($composerContent === false) {
61+
return false;
62+
}
63+
64+
$composerJson = json_decode($composerContent, true);
65+
$requires = $composerJson['require'] ?? [];
66+
$requiresDev = $composerJson['require-dev'] ?? [];
67+
return isset($requires['laravel/framework']) || isset($requiresDev['laravel/framework']);
68+
}
5169
}

0 commit comments

Comments
 (0)