class VendorHardeningPlugin implements PluginInterface, EventSubscriberInterface (View source)

internal  
 

A Composer plugin to clean out your project's vendor directory.

This plugin will remove directory paths within installed packages. You might use this in order to mitigate the security risks of having your vendor directory within an HTTP server's docroot.

Properties

protected Composer $composer

Composer object.

protected IOInterface $io

IO object.

protected Config $config Configuration.
protected string[] $packagesAlreadyCleaned

List of projects already cleaned.

Methods

activate(Composer $composer, IOInterface $io)

{@inheritdoc}

deactivate(Composer $composer, IOInterface $io)

{@inheritdoc}

uninstall(Composer $composer, IOInterface $io)

{@inheritdoc}

static 
getSubscribedEvents()

{@inheritdoc}

onPostAutoloadDump(Event $event)

POST_AUTOLOAD_DUMP event handler.

onPostCmd(Event $event)

POST_UPDATE_CMD and POST_INSTALL_CMD event handler.

onPrePackageInstall(PackageEvent $event)

PRE_PACKAGE_INSTALL event handler.

onPrePackageUpdate(PackageEvent $event)

PRE_PACKAGE_UPDATE event handler.

onPostPackageInstall(PackageEvent $event)

POST_PACKAGE_INSTALL event handler.

onPostPackageUpdate(PackageEvent $event)

POST_PACKAGE_UPDATE event handler.

removeBinBeforeCleanup(BasePackage $package)

Remove bin config for packages that would have the bin file removed.

string[]
findBinOverlap(string[] $binaries, string[] $clean_paths)

Find bin files which are inside cleanup directories.

PackageInterface[]
getInstalledPackages()

Gets a list of all installed packages from Composer.

string
getInstallPathForPackage(PackageInterface $package)

Gets the installed path for a package.

cleanAllPackages()

Clean all configured packages.

cleanPackage(PackageInterface $package)

Clean a single package.

cleanPathsForPackage(PackageInterface $package, string $paths_for_package)

Clean the installed directories for a named package.

writeAccessRestrictionFiles(string $vendor_dir)

Place .htaccess and web.config files into the vendor directory.

Details

activate(Composer $composer, IOInterface $io)

{@inheritdoc}

Parameters

Composer $composer
IOInterface $io

deactivate(Composer $composer, IOInterface $io)

{@inheritdoc}

Parameters

Composer $composer
IOInterface $io

uninstall(Composer $composer, IOInterface $io)

{@inheritdoc}

Parameters

Composer $composer
IOInterface $io

static getSubscribedEvents()

{@inheritdoc}

onPostAutoloadDump(Event $event)

POST_AUTOLOAD_DUMP event handler.

Parameters

Event $event

The Composer event.

onPostCmd(Event $event)

POST_UPDATE_CMD and POST_INSTALL_CMD event handler.

Parameters

Event $event

The Composer event.

onPrePackageInstall(PackageEvent $event)

PRE_PACKAGE_INSTALL event handler.

Parameters

PackageEvent $event

onPrePackageUpdate(PackageEvent $event)

PRE_PACKAGE_UPDATE event handler.

Parameters

PackageEvent $event

onPostPackageInstall(PackageEvent $event)

POST_PACKAGE_INSTALL event handler.

Parameters

PackageEvent $event

onPostPackageUpdate(PackageEvent $event)

POST_PACKAGE_UPDATE event handler.

Parameters

PackageEvent $event

protected removeBinBeforeCleanup(BasePackage $package)

Remove bin config for packages that would have the bin file removed.

Where the configured bin files are in the directories to be removed, remove the bin config.

Parameters

BasePackage $package

The package we're cleaning up.

protected string[] findBinOverlap(string[] $binaries, string[] $clean_paths)

Find bin files which are inside cleanup directories.

Parameters

string[] $binaries

'Bin' configuration from the package we're cleaning up.

string[] $clean_paths

The paths we're cleaning up.

Return Value

string[]

Bin files to remove, with the file as both the key and the value.

protected PackageInterface[] getInstalledPackages()

Gets a list of all installed packages from Composer.

Return Value

PackageInterface[]

The list of installed packages.

protected string getInstallPathForPackage(PackageInterface $package)

Gets the installed path for a package.

Parameters

PackageInterface $package

The package.

Return Value

string

Path to the install path for the package, relative to the project. This accounts for changes made by composer/installers, if any.

cleanAllPackages()

Clean all configured packages.

This applies in the context of a post-command event.

cleanPackage(PackageInterface $package)

Clean a single package.

This applies in the context of a package post-install or post-update event.

Parameters

PackageInterface $package

The package to clean.

protected cleanPathsForPackage(PackageInterface $package, string $paths_for_package)

Clean the installed directories for a named package.

Parameters

PackageInterface $package

The package to clean.

string $paths_for_package

List of directories in $package_name to remove

writeAccessRestrictionFiles(string $vendor_dir)

Place .htaccess and web.config files into the vendor directory.

Parameters

string $vendor_dir

Path to vendor directory.