Skip to content

Commit

Permalink
Merge branch 'roots:main' into fse
Browse files Browse the repository at this point in the history
  • Loading branch information
dsturm committed Jan 31, 2024
2 parents eedd288 + f467dce commit a5b4d59
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 84 deletions.
37 changes: 18 additions & 19 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@
"php": ">=8.1",
"ext-json": "*",
"ext-mbstring": "*",
"illuminate/cache": "^10.33",
"illuminate/config": "^10.33",
"illuminate/console": "^10.33",
"illuminate/container": "^10.33",
"illuminate/contracts": "^10.33",
"illuminate/database": "^10.33",
"illuminate/encryption": "^10.33",
"illuminate/events": "^10.33",
"illuminate/filesystem": "^10.33",
"illuminate/http": "^10.33",
"illuminate/log": "^10.33",
"illuminate/queue": "^10.33",
"illuminate/routing": "^10.33",
"illuminate/support": "^10.33",
"illuminate/validation": "^10.33",
"illuminate/view": "^10.33",
"illuminate/cache": "^10.43",
"illuminate/config": "^10.43",
"illuminate/console": "^10.43",
"illuminate/container": "^10.43",
"illuminate/contracts": "^10.43",
"illuminate/database": "^10.43",
"illuminate/encryption": "^10.43",
"illuminate/events": "^10.43",
"illuminate/filesystem": "^10.43",
"illuminate/http": "^10.43",
"illuminate/log": "^10.43",
"illuminate/queue": "^10.43",
"illuminate/routing": "^10.43",
"illuminate/support": "^10.43",
"illuminate/validation": "^10.43",
"illuminate/view": "^10.43",
"laravel/prompts": "^0.1.7",
"laravel/serializable-closure": "^1.3",
"league/flysystem": "^3.8",
Expand All @@ -84,13 +84,12 @@
},
"suggest": {
"roots/acorn-prettify": "A collection of modules to apply theme-agnostic front-end modifications (^1.0).",
"spatie/laravel-ignition": "A beautiful error page for development (^1.6)."
"spatie/laravel-ignition": "A beautiful error page for development (^2.0)."
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
"pestphp/pest-plugin": true
}
},
"minimum-stability": "dev",
Expand Down
6 changes: 4 additions & 2 deletions src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

use function Illuminate\Filesystem\join_paths;

class Application extends Container implements ApplicationContract, CachesConfiguration, CachesRoutes, HttpKernelInterface
{
use Macroable;
Expand All @@ -38,7 +40,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
*
* @var string
*/
const VERSION = '10.33.0';
const VERSION = '10.43.0';

/**
* The base path for the Laravel installation.
Expand Down Expand Up @@ -586,7 +588,7 @@ public function viewPath($path = '')
*/
public function joinPaths($basePath, $path = '')
{
return $basePath.($path != '' ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : '');
return join_paths($basePath, $path);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Log\LogManager;
use Illuminate\Support\Env;
use Monolog\Handler\NullHandler;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\ErrorHandler\Error\FatalError;
Expand Down Expand Up @@ -118,7 +119,7 @@ protected function shouldIgnoreDeprecationErrors()
{
return ! class_exists(LogManager::class)
|| ! static::$app->hasBeenBootstrapped()
|| static::$app->runningUnitTests();
|| (static::$app->runningUnitTests() && ! Env::get('LOG_DEPRECATIONS_WHILE_TESTING'));
}

/**
Expand Down
27 changes: 26 additions & 1 deletion src/Illuminate/Foundation/Bus/PendingChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
use Closure;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Queue\CallQueuedClosure;
use Illuminate\Support\Traits\Conditionable;
use Laravel\SerializableClosure\SerializableClosure;

class PendingChain
{
use Conditionable;

/**
* The class name of the job being dispatched.
*
Expand Down Expand Up @@ -129,7 +132,7 @@ public function catchCallbacks()
}

/**
* Dispatch the job with the given arguments.
* Dispatch the job chain.
*
* @return \Illuminate\Foundation\Bus\PendingDispatch
*/
Expand Down Expand Up @@ -162,4 +165,26 @@ public function dispatch()

return app(Dispatcher::class)->dispatch($firstJob);
}

/**
* Dispatch the job chain if the given truth test passes.
*
* @param bool|\Closure $boolean
* @return \Illuminate\Foundation\Bus\PendingDispatch|null
*/
public function dispatchIf($boolean)
{
return value($boolean) ? $this->dispatch() : null;
}

/**
* Dispatch the job chain unless the given truth test passes.
*
* @param bool|\Closure $boolean
* @return \Illuminate\Foundation\Bus\PendingDispatch|null
*/
public function dispatchUnless($boolean)
{
return ! value($boolean) ? $this->dispatch() : null;
}
}
84 changes: 64 additions & 20 deletions src/Illuminate/Foundation/Console/AboutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Foundation\Console;

use Closure;
use Illuminate\Console\Command;
use Illuminate\Support\Composer;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -127,7 +128,7 @@ protected function displayDetail($data)
$data->pipe(fn ($data) => $section !== 'Environment' ? $data->sort() : $data)->each(function ($detail) {
[$label, $value] = $detail;

$this->components->twoColumnDetail($label, value($value));
$this->components->twoColumnDetail($label, value($value, false));
});
});
}
Expand All @@ -143,7 +144,7 @@ protected function displayJson($data)
$output = $data->flatMap(function ($data, $section) {
return [
(string) Str::of($section)->snake() => $data->mapWithKeys(fn ($item, $key) => [
$this->toSearchKeyword($item[0]) => value($item[1]),
$this->toSearchKeyword($item[0]) => value($item[1], true),
]),
];
});
Expand All @@ -158,40 +159,50 @@ protected function displayJson($data)
*/
protected function gatherApplicationInformation()
{
self::$data = [];

$formatEnabledStatus = fn ($value) => $value ? '<fg=yellow;options=bold>ENABLED</>' : 'OFF';
$formatCachedStatus = fn ($value) => $value ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>';

static::addToSection('Environment', fn () => [
'Application Name' => config('app.name'),
'Laravel Version' => $this->laravel->version(),
'PHP Version' => phpversion(),
'Composer Version' => $this->composer->getVersion() ?? '<fg=yellow;options=bold>-</>',
'Environment' => $this->laravel->environment(),
'Debug Mode' => config('app.debug') ? '<fg=yellow;options=bold>ENABLED</>' : 'OFF',
'Debug Mode' => static::format(config('app.debug'), console: $formatEnabledStatus),
'URL' => Str::of(config('app.url'))->replace(['http://', 'https://'], ''),
'Maintenance Mode' => $this->laravel->isDownForMaintenance() ? '<fg=yellow;options=bold>ENABLED</>' : 'OFF',
'Maintenance Mode' => static::format($this->laravel->isDownForMaintenance(), console: $formatEnabledStatus),
]);

static::addToSection('Cache', fn () => [
'Config' => $this->laravel->configurationIsCached() ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>',
'Events' => $this->laravel->eventsAreCached() ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>',
'Routes' => $this->laravel->routesAreCached() ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>',
'Views' => $this->hasPhpFiles($this->laravel->storagePath('framework/views')) ? '<fg=green;options=bold>CACHED</>' : '<fg=yellow;options=bold>NOT CACHED</>',
'Config' => static::format($this->laravel->configurationIsCached(), console: $formatCachedStatus),
'Events' => static::format($this->laravel->eventsAreCached(), console: $formatCachedStatus),
'Routes' => static::format($this->laravel->routesAreCached(), console: $formatCachedStatus),
'Views' => static::format($this->hasPhpFiles($this->laravel->storagePath('framework/views')), console: $formatCachedStatus),
]);

$logChannel = config('logging.default');

if (config('logging.channels.'.$logChannel.'.driver') === 'stack') {
$secondary = collect(config('logging.channels.'.$logChannel.'.channels'))
->implode(', ');

$logs = '<fg=yellow;options=bold>'.$logChannel.'</> <fg=gray;options=bold>/</> '.$secondary;
} else {
$logs = $logChannel;
}

static::addToSection('Drivers', fn () => array_filter([
'Broadcasting' => config('broadcasting.default'),
'Cache' => config('cache.default'),
'Database' => config('database.default'),
'Logs' => $logs,
'Logs' => function ($json) {
$logChannel = config('logging.default');

if (config('logging.channels.'.$logChannel.'.driver') === 'stack') {
$secondary = collect(config('logging.channels.'.$logChannel.'.channels'));

return value(static::format(
value: $logChannel,
console: fn ($value) => '<fg=yellow;options=bold>'.$value.'</> <fg=gray;options=bold>/</> '.$secondary->implode(', '),
json: fn () => $secondary->all(),
), $json);
} else {
$logs = $logChannel;
}

return $logs;
},
'Mail' => config('mail.default'),
'Octane' => config('octane.server'),
'Queue' => config('queue.default'),
Expand Down Expand Up @@ -260,6 +271,27 @@ protected function sections()
->all();
}

/**
* Materialize a function that formats a given value for CLI or JSON output.
*
* @param mixed $value
* @param (\Closure(mixed):(mixed))|null $console
* @param (\Closure(mixed):(mixed))|null $json
* @return \Closure(bool):mixed
*/
public static function format($value, Closure $console = null, Closure $json = null)
{
return function ($isJson) use ($value, $console, $json) {
if ($isJson === true && $json instanceof Closure) {
return value($json, $value);
} elseif ($isJson === false && $console instanceof Closure) {
return value($console, $value);
}

return value($value);
};
}

/**
* Format the given string for searching.
*
Expand All @@ -270,4 +302,16 @@ protected function toSearchKeyword(string $value)
{
return (string) Str::of($value)->lower()->snake();
}

/**
* Flush the registered about data.
*
* @return void
*/
public static function flushState()
{
static::$data = [];

static::$customDataResolvers = [];
}
}
26 changes: 24 additions & 2 deletions src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Console\Command;
use Illuminate\Foundation\Events\MaintenanceModeEnabled;
use Illuminate\Foundation\Exceptions\RegisterErrorViewPaths;
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;
use Throwable;

Expand All @@ -23,6 +24,7 @@ class DownCommand extends Command
{--retry= : The number of seconds after which the request may be retried}
{--refresh= : The number of seconds after which the browser may refresh}
{--secret= : The secret phrase that may be used to bypass maintenance mode}
{--with-secret : Generate a random secret phrase that may be used to bypass maintenance mode}
{--status=503 : The status code that should be used when returning the maintenance mode response}';

/**
Expand All @@ -46,7 +48,9 @@ public function handle()
return 0;
}

$this->laravel->maintenanceMode()->activate($this->getDownFilePayload());
$downFilePayload = $this->getDownFilePayload();

$this->laravel->maintenanceMode()->activate($downFilePayload);

file_put_contents(
storage_path('framework/maintenance.php'),
Expand All @@ -56,6 +60,10 @@ public function handle()
$this->laravel->get('events')->dispatch(new MaintenanceModeEnabled());

$this->components->info('Application is now in maintenance mode.');

if ($downFilePayload['secret'] !== null) {
$this->components->info('You may bypass maintenance mode via ['.config('app.url')."/{$downFilePayload['secret']}].");
}
} catch (Exception $e) {
$this->components->error(sprintf(
'Failed to enter maintenance mode: %s.',
Expand All @@ -78,7 +86,7 @@ protected function getDownFilePayload()
'redirect' => $this->redirectPath(),
'retry' => $this->getRetryTime(),
'refresh' => $this->option('refresh'),
'secret' => $this->option('secret'),
'secret' => $this->getSecret(),
'status' => (int) $this->option('status', 503),
'template' => $this->option('render') ? $this->prerenderView() : null,
];
Expand Down Expand Up @@ -137,4 +145,18 @@ protected function getRetryTime()

return is_numeric($retry) && $retry > 0 ? (int) $retry : null;
}

/**
* Get the secret phrase that may be used to bypass maintenance mode.
*
* @return string|null
*/
protected function getSecret()
{
return match (true) {
! is_null($this->option('secret')) => $this->option('secret'),
$this->option('with-secret') => Str::random(),
default => null,
};
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ protected function load($paths)

$namespace = $this->app->getNamespace();

foreach ((new Finder)->in($paths)->files() as $file) {
foreach (Finder::create()->in($paths)->files() as $file) {
$command = $this->commandClassFromFile($file, $namespace);

if (is_subclass_of($command, Command::class) &&
Expand Down
1 change: 0 additions & 1 deletion src/Illuminate/Foundation/Console/ModelMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ protected function createMigration()
$this->call('make:migration', [
'name' => "create_{$table}_table",
'--create' => $table,
'--fullpath' => true,
]);
}

Expand Down
Loading

0 comments on commit a5b4d59

Please sign in to comment.