master

laravel/framework

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

ClearCompiledCommand.php

TLDR

This file defines the ClearCompiledCommand class, which extends the Command class. It provides a method handle() which removes the compiled class file, as well as cached services and packages files.

Methods

handle()

This method executes the console command. It checks if the cached services and packages files exist and deletes them if they do. Finally, it logs a success message indicating that the compiled services and packages files have been removed.

Classes

ClearCompiledCommand

This class extends the Command class and represents a console command for clearing the compiled class file. It defines the command name, description, and a handle() method to execute the command.

<?php

namespace Illuminate\Foundation\Console;

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

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Remove the compiled class file';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        if (is_file($servicesPath = $this->laravel->getCachedServicesPath())) {
            @unlink($servicesPath);
        }

        if (is_file($packagesPath = $this->laravel->getCachedPackagesPath())) {
            @unlink($packagesPath);
        }

        $this->components->info('Compiled services and packages files removed successfully.');
    }
}