ComposerScripts.php
TLDR
This file, ComposerScripts.php
, is a part of the Illuminate\Foundation
namespace and contains the ComposerScripts
class. This class provides methods to handle post-install, post-update, and post-autoload-dump Composer events. The class also has a protected method to clear the cached Laravel bootstrapping files.
Methods
postInstall
This method handles the post-install Composer event. It requires the Composer\Script\Event
object as a parameter and includes the autoload file. It then calls the clearCompiled
method.
postUpdate
This method handles the post-update Composer event. It has the same functionality as the postInstall
method, i.e., it requires the Composer\Script\Event
object as a parameter, includes the autoload file, and calls the clearCompiled
method.
postAutoloadDump
This method handles the post-autoload-dump Composer event. Similarly to the previous methods, it requires the Composer\Script\Event
object as a parameter, includes the autoload file, and calls the clearCompiled
method.
clearCompiled
This protected method clears the cached Laravel bootstrapping files. It creates a new instance of the Application
class with the current working directory as a parameter. Then, it checks if the cached configuration file, services file, and packages file exist, and deletes them if they do.
Classes
No classes are defined in this file.
<?php
namespace Illuminate\Foundation;
use Composer\Script\Event;
class ComposerScripts
{
/**
* Handle the post-install Composer event.
*
* @param \Composer\Script\Event $event
* @return void
*/
public static function postInstall(Event $event)
{
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
static::clearCompiled();
}
/**
* Handle the post-update Composer event.
*
* @param \Composer\Script\Event $event
* @return void
*/
public static function postUpdate(Event $event)
{
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
static::clearCompiled();
}
/**
* Handle the post-autoload-dump Composer event.
*
* @param \Composer\Script\Event $event
* @return void
*/
public static function postAutoloadDump(Event $event)
{
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';
static::clearCompiled();
}
/**
* Clear the cached Laravel bootstrapping files.
*
* @return void
*/
protected static function clearCompiled()
{
$laravel = new Application(getcwd());
if (is_file($configPath = $laravel->getCachedConfigPath())) {
@unlink($configPath);
}
if (is_file($servicesPath = $laravel->getCachedServicesPath())) {
@unlink($servicesPath);
}
if (is_file($packagesPath = $laravel->getCachedPackagesPath())) {
@unlink($packagesPath);
}
}
}