Skip to content

Commit 853b422

Browse files
author
ityaozm@gmail.com
committed
feat(config): Refactor application booting process and add console summary configuration
- Reorganize booting methods in `app.php` for better clarity and execution flow - Introduce a new configuration file `laravel-console-summary.php` to manage console command visibility - Add `intonate/tinker-zero` as a new dependency in `composer.json` - Update dependency analyzer to ignore errors for `intonate/tinker-zero` in production
1 parent d33a91d commit 853b422

10 files changed

Lines changed: 282 additions & 22 deletions

app/Exceptions/UnsupportedConfigActionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ final class UnsupportedConfigActionException extends InvalidArgumentException
2020
public static function make(string $action, int $code = 0, ?\Throwable $previous = null): self
2121
{
2222
return new self(
23-
\sprintf("The action($action) is not supported, that must be one of [%s].", implode(', ', ConfigCommand::ACTIONS)),
23+
\sprintf("The action [$action] is not supported, that must be one of [%s].", implode(', ', ConfigCommand::ACTIONS)),
2424
$code,
2525
$previous
2626
);

app/Exceptions/UnsupportedConfigFileTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class UnsupportedConfigFileTypeException extends InvalidArgumentException
1818
public static function make(string $file, int $code = 0, ?\Throwable $previous = null): self
1919
{
2020
return new self(
21-
\sprintf('The config file type(%s) is not supported', pathinfo($file, \PATHINFO_EXTENSION)),
21+
\sprintf('The config file type [%s] is not supported', pathinfo($file, \PATHINFO_EXTENSION)),
2222
$code,
2323
$previous
2424
);

app/Providers/AppServiceProvider.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
use Illuminate\Console\OutputStyle;
1717
use Illuminate\Support\ServiceProvider;
18-
use Symfony\Component\Console\Application;
18+
use LaravelZero\Framework\Application;
19+
use Symfony\Component\Console\Application as ConsoleApplication;
1920
use Symfony\Component\Console\Input\ArgvInput;
2021
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Logger\ConsoleLogger;
2123
use Symfony\Component\Console\Output\ConsoleOutput;
2224
use Symfony\Component\Console\Output\OutputInterface;
2325

@@ -47,11 +49,16 @@ static function (): OutputStyle {
4749
$consoleOutput = new ConsoleOutput;
4850

4951
// to configure all -v, -vv, -vvv options without memory-lock to Application run() arguments
50-
(fn () => $this->configureIO($argvInput, $consoleOutput))->call(new Application);
52+
(fn () => $this->configureIO($argvInput, $consoleOutput))->call(new ConsoleApplication);
5153

5254
return new OutputStyle($argvInput, $consoleOutput);
5355
}
5456
);
57+
58+
$this->app->singleton(
59+
ConsoleLogger::class,
60+
static fn (Application $app): ConsoleLogger => new ConsoleLogger($app->make(OutputStyle::class))
61+
);
5562
}
5663

5764
public function boot(): void

app/Support/helpers.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace App\Support;
1515

16+
use App\Exceptions\InvalidArgumentException;
1617
use Composer\Autoload\ClassLoader;
1718
use Illuminate\Support\Arr;
1819
use Illuminate\Support\Collection;
@@ -92,7 +93,7 @@ function make(array|string $name, array $parameters = []): mixed
9293
}
9394
}
9495

95-
throw new \InvalidArgumentException(\sprintf(
96+
throw new InvalidArgumentException(\sprintf(
9697
'The argument of abstract must be an array containing a `%s` element.',
9798
implode('` or `', $keys)
9899
));

bootstrap/app.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@
2525
use Illuminate\Validation\ValidationException;
2626
use Intonate\TinkerZero\TinkerZeroServiceProvider;
2727
use Psr\Log\LoggerInterface;
28-
use Symfony\Component\Console\Logger\ConsoleLogger;
2928

3029
return Application::configure(basePath: \dirname(__DIR__))
30+
->withSingletons([
31+
GeneratorManager::class,
32+
])
3133
->booting(static function (): void {
3234
ConfigManager::load();
3335
})
34-
// ->booted(static function (Application $app): void {
35-
// if (class_exists(TinkerZeroServiceProvider::class) && !$app->isProduction()) {
36-
// $app->register(TinkerZeroServiceProvider::class);
37-
// }
38-
// })
39-
->booted(static function (Application $app): void {
40-
// new ConsoleLogger(app(OutputStyle::class));
36+
->booting(static function (Application $app): void {
37+
if (class_exists(TinkerZeroServiceProvider::class) && !$app->isProduction()) {
38+
$app->register(TinkerZeroServiceProvider::class);
39+
}
40+
})
41+
->booting(static function (Application $app): void {
4142
$app->extend(
4243
LogManager::class,
4344
static fn (
@@ -46,9 +47,6 @@
4647
): LogManager => $logger instanceof LogManager ? $logger : new LogManager($app)
4748
);
4849
})
49-
->withSingletons([
50-
GeneratorManager::class,
51-
])
5250
->withExceptions(static function (Exceptions $exceptions): void {
5351
$exceptions->map(
5452
ValidationException::class,

composer-dependency-analyser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
)
6262
->ignoreErrorsOnPackages(
6363
[
64+
'intonate/tinker-zero',
6465
],
6566
[ErrorType::DEV_DEPENDENCY_IN_PROD]
6667
);

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"ergebnis/rector-rules": "^1.4",
7676
"friendsofphp/php-cs-fixer": "^3.75",
7777
"guanguans/monorepo-builder-worker": "^2.0",
78+
"intonate/tinker-zero": "^1.2",
7879
"ion-bazan/composer-diff": "^1.12",
7980
"larastan/larastan": "^3.4",
8081
"laravel/facade-documenter": "dev-main",
@@ -206,6 +207,7 @@
206207
"@phpmnd",
207208
"@style-lint",
208209
"@sk-check-conflicts",
210+
"@sk-check-commented-code",
209211
"@sk-finalize-classes-dry-run",
210212
"@composer-dependency-analyser",
211213
"@sk-spot-lazy-traits",
@@ -346,7 +348,7 @@
346348
"roave-no-leaks": "@php vendor/bin/roave-no-leaks",
347349
"sk": "@php vendor/bin/swiss-knife --ansi -v",
348350
"sk-alice-yaml-fixtures-to-php": "@sk alice-yaml-fixtures-to-php --help",
349-
"sk-check-commented-code": "@sk check-commented-code app/ --line-limit=20",
351+
"sk-check-commented-code": "@sk check-commented-code app/ bootstrap/ config/ resources/ tests/ --line-limit=20",
350352
"sk-check-conflicts": "@sk check-conflicts app/ bootstrap/ config/ resources/ tests/",
351353
"sk-dump-editorconfig": "@sk dump-editorconfig",
352354
"sk-finalize-classes": "@sk finalize-classes app/",

composer.lock

Lines changed: 207 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)