Skip to content

Commit e6adab6

Browse files
committed
Merge branch 'main' into guidelines-galore
# Conflicts: # .ai/laravel/core.blade.php # src/Console/InstallCommand.php
2 parents 1bc080a + ce38c04 commit e6adab6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1934
-776
lines changed

.ai/laravel/core.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Do Things the Laravel Way
2-
- Use `./artisan make:` commands to create new files (i.e. migrations, controllers, models, etc.). You can list available artisan commands with the `list-artisan-commands` tool.
2+
- Use `php artisan make:` commands to create new files (i.e. migrations, controllers, models, etc.). You can list available artisan commands with the `list-artisan-commands` tool.
33
- If you're creating a generic PHP class, use `artisan make:class`.
44

55
## Database
@@ -14,7 +14,7 @@
1414
- **Validation rule style**: Check sibling form requests to see if the project uses array or string based validation rules.
1515

1616
## Model Creation
17-
- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, use `list-artisan-commands` to check the available options to `./artisan make:model`
17+
- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, use `list-artisan-commands` to check the available options to `php artisan make:model`
1818

1919
## APIs and Eloquent Resources
2020
- For APIs, default to using Eloquent API Resources and API versioning, unless existing API routes do not, then you should follow existing convention.

.ai/pest/core.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Pest Tests
55
- All tests must be written using Pest.
66
- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files, these are core to the application.
7-
- Tests should test all of the the unhappy paths, happy paths, and weird paths.
7+
- Tests should test all of the unhappy paths, happy paths, and weird paths.
88
- Tests live in the `tests/Feature` and `tests/Unit` directories.
99
- Pest tests look and behave like this:
1010
<code-snippet name="Basic example Pest test" lang="php">

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ composer require laravel/boost --dev
3434

3535
Install the MCP server & guidelines
3636
```bash
37-
./artisan boost:install
37+
php artisan boost:install
3838
```
3939

4040
You're ready to go!

config/boost.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
declare(strict_types=1);
44

55
return [
6-
'project_purpose' => null,
7-
'browser_logs' => true,
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Boost Browser Logs Watcher Switch
10+
|--------------------------------------------------------------------------
11+
|
12+
| The following option may be used to enable or disable browser logs watcher
13+
| functionality which simply provides a single and convenient way to
14+
| enable or disable browser logs functionality in Boost.
15+
*/
16+
17+
'browser_logs_watcher' => env('BOOST_BROWSER_LOGS_WATCHER', true),
818
];

pint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"phpdoc_align": {
112112
"align": "left",
113113
"spacing": {
114-
"param": 2
114+
"param": 1
115115
}
116116
},
117117
"phpdoc_indent": true,

src/BoostServiceProvider.php

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
88
use Illuminate\Http\Request;
99
use Illuminate\Routing\Router;
10-
use Illuminate\Support\Facades\Blade;
1110
use Illuminate\Support\Facades\Log;
1211
use Illuminate\Support\Facades\Route;
1312
use Illuminate\Support\ServiceProvider;
13+
use Illuminate\View\Compilers\BladeCompiler;
1414
use Laravel\Boost\Mcp\Boost;
1515
use Laravel\Boost\Middleware\InjectBoost;
1616
use Laravel\Mcp\Server\Facades\Mcp;
@@ -21,18 +21,21 @@ class BoostServiceProvider extends ServiceProvider
2121
public function register(): void
2222
{
2323
$this->mergeConfigFrom(
24-
__DIR__.'/../config/boost.php', 'boost'
24+
__DIR__.'/../config/boost.php',
25+
'boost'
2526
);
2627

2728
$this->app->singleton(Roster::class, function () {
28-
$composerLockPath = base_path('composer.lock');
29-
$packageLockPath = base_path('package-lock.json');
29+
$lockFiles = [
30+
base_path('composer.lock'),
31+
base_path('package-lock.json'),
32+
base_path('bun.lockb'),
33+
base_path('pnpm-lock.yaml'),
34+
base_path('yarn.lock'),
35+
];
3036

3137
$cacheKey = 'boost.roster.scan';
32-
$lastModified = max(
33-
file_exists($composerLockPath) ? filemtime($composerLockPath) : 0,
34-
file_exists($packageLockPath) ? filemtime($packageLockPath) : 0
35-
);
38+
$lastModified = max(array_map(fn ($path) => file_exists($path) ? filemtime($path) : 0, $lockFiles));
3639

3740
$cached = cache()->get($cacheKey);
3841
if ($cached && isset($cached['timestamp']) && $cached['timestamp'] >= $lastModified) {
@@ -62,7 +65,7 @@ public function boot(Router $router): void
6265
$this->registerCommands();
6366
$this->registerRoutes();
6467
$this->registerBrowserLogger();
65-
$this->registerBladeDirectives();
68+
$this->callAfterResolving('blade.compiler', fn (BladeCompiler $bladeCompiler) => $this->registerBladeDirectives($bladeCompiler));
6669
$this->hookIntoResponses($router);
6770
}
6871

@@ -93,10 +96,17 @@ private function registerRoutes(): void
9396
/** @var \Illuminate\Log\Logger $logger */
9497
$logger = Log::channel('browser');
9598

96-
/** @var array{type: 'error'|'warn'|'info'|'log'|'table'|'window_error'|'uncaught_error'|'unhandled_rejection', timestamp: string, data: array<mixed>, url:string, userAgent:string} $log */
99+
/**
100+
* @var array{
101+
* type: 'error'|'warn'|'info'|'log'|'table'|'window_error'|'uncaught_error'|'unhandled_rejection',
102+
* timestamp: string,
103+
* data: array<mixed>,
104+
* url:string,
105+
* userAgent:string
106+
* } $log */
97107
foreach ($logs as $log) {
98108
$logger->write(
99-
level: $this->jsTypeToPsr3($log['type']),
109+
level: $this->mapJsTypeToPsr3Level($log['type']),
100110
message: $this->buildLogMessageFromData($log['data']),
101111
context: [
102112
'url' => $log['url'],
@@ -107,58 +117,53 @@ private function registerRoutes(): void
107117
}
108118

109119
return response()->json(['status' => 'logged']);
110-
})->name('boost.browser-logs')->withoutMiddleware(VerifyCsrfToken::class);
120+
})
121+
->name('boost.browser-logs')
122+
->withoutMiddleware(VerifyCsrfToken::class);
111123
}
112124

113125
/**
114126
* Build a string message for the log based on various input types. Single dimensional, and multi:
115-
* "data":[{"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
127+
* "data":[
128+
* {"message":"Unhandled Promise Rejection","reason":{"name":"TypeError","message":"NetworkError when attempting to fetch resource.","stack":""}}]
116129
*
117-
* @param array<mixed> $data
130+
* @param array<mixed> $data
118131
*/
119132
protected function buildLogMessageFromData(array $data): string
120133
{
121134
$messages = [];
122135

123-
foreach ($data as $key => $value) {
124-
if (is_array($value)) {
125-
$nestedMessage = $this->buildLogMessageFromData($value);
126-
if ($nestedMessage !== '') {
127-
$messages[] = $nestedMessage;
128-
}
129-
} elseif (is_string($value) || is_numeric($value)) {
130-
$messages[] = (string) $value;
131-
} elseif (is_bool($value)) {
132-
$messages[] = $value ? 'true' : 'false';
133-
} elseif (is_null($value)) {
134-
$messages[] = 'null';
135-
} elseif (is_object($value)) {
136-
$messages[] = json_encode($value);
137-
}
136+
foreach ($data as $value) {
137+
$messages[] = match (true) {
138+
is_array($value) => $this->buildLogMessageFromData($value),
139+
is_string($value), is_numeric($value) => (string) $value,
140+
is_bool($value) => $value ? 'true' : 'false',
141+
is_null($value) => 'null',
142+
is_object($value) => json_encode($value),
143+
};
138144
}
139145

140146
return implode(' ', $messages);
141147
}
142148

143149
protected function registerBrowserLogger(): void
144150
{
145-
// Register a custom log channel for browser logs
146-
config(['logging.channels.browser' => [
147-
'driver' => 'single',
148-
'path' => storage_path('logs/browser.log'),
149-
'level' => env('LOG_LEVEL', 'debug'),
150-
'days' => 14,
151-
]]);
151+
config([
152+
'logging.channels.browser' => [
153+
'driver' => 'single',
154+
'path' => storage_path('logs/browser.log'),
155+
'level' => env('LOG_LEVEL', 'debug'),
156+
'days' => 14,
157+
],
158+
]);
152159
}
153160

154-
protected function registerBladeDirectives(): void
161+
protected function registerBladeDirectives(BladeCompiler $bladeCompiler): void
155162
{
156-
Blade::directive('boostJs', function () {
157-
return '<?php echo \\Laravel\\Boost\\Services\\BrowserLogger::getScript(); ?>';
158-
});
163+
$bladeCompiler->directive('boostJs', fn () => '<?php echo \\Laravel\\Boost\\Services\\BrowserLogger::getScript(); ?>');
159164
}
160165

161-
private function jsTypeToPsr3(string $type): string
166+
private function mapJsTypeToPsr3Level(string $type): string
162167
{
163168
return match ($type) {
164169
'warn' => 'warning',
@@ -173,7 +178,7 @@ private function jsTypeToPsr3(string $type): string
173178

174179
private function hookIntoResponses(Router $router): void
175180
{
176-
if (config('boost.browser_logs', true) === false) {
181+
if (! config('boost.browser_logs_watcher', true)) {
177182
return;
178183
}
179184

src/Concerns/MakesHttpRequests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function get(string $url): Response
3030
}
3131

3232
/**
33-
* @param array<string, mixed> $json
33+
* @param array<string, mixed> $json
3434
*/
3535
public function json(string $url, array $json): Response
3636
{

0 commit comments

Comments
 (0)