master

laravel/framework

Last updated at: 29/12/2023 09:22

OptimizeCommand.php

TLDR

This file contains the OptimizeCommand class, which is responsible for caching framework bootstrap, configuration, and metadata in order to improve performance.

Methods

There are no methods in this file.

Classes

OptimizeCommand

The OptimizeCommand class extends the Command class and is used to optimize the application. It is registered as a console command with the name 'optimize'.

The class has the following properties:

  • $name (string): The console command name, which is set to 'optimize'.
  • $description (string): The console command description, which is set to 'Cache framework bootstrap, configuration, and metadata to increase performance'.

The class has the following method:

handle()

This method is responsible for executing the console command. It starts by displaying a message about caching the framework bootstrap, configuration, and metadata. Then, it uses the collect function to define an array of tasks to be executed, such as calling other console commands silently. For each task, it uses the $this->components->task() method to display a message indicating the task being performed. Finally, it adds a new line.

<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'optimize')]
class OptimizeCommand extends Command
{
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'optimize';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Cache framework bootstrap, configuration, and metadata to increase performance';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $this->components->info('Caching framework bootstrap, configuration, and metadata.');

        collect([
            'config' => fn () => $this->callSilent('config:cache') == 0,
            'events' => fn () => $this->callSilent('event:cache') == 0,
            'routes' => fn () => $this->callSilent('route:cache') == 0,
            'views' => fn () => $this->callSilent('view:cache') == 0,
        ])->each(fn ($task, $description) => $this->components->task($description, $task));

        $this->newLine();
    }
}