Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/php/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,16 @@ func composerInstall(ctx *gcp.Context, flags []string) error {
return nil
}

// ComposerInstall runs `composer install`, using the cache iff a lock file is present.
// composerDumpAutoload runs `composer dump-autoload` with the given flags.
func composerDumpAutoload(ctx *gcp.Context, flags []string) error {
cmd := append([]string{"composer", "dump-autoload"}, flags...)
if _, err := ctx.Exec(cmd, gcp.WithUserAttribution); err != nil {
return err
}
return nil
}

// ComposerInstall runs `composer install`, using the cache if a lock file is present.
// It creates a layer, so it returns the layer so that the caller may further modify it
// if they desire.
func ComposerInstall(ctx *gcp.Context, cacheTag string) (*libcnb.Layer, error) {
Expand Down Expand Up @@ -201,6 +210,12 @@ func ComposerInstall(ctx *gcp.Context, cacheTag string) (*libcnb.Layer, error) {
if _, err := ctx.Exec([]string{"cp", "--archive", layerVendor, Vendor}, gcp.WithUserTimingAttribution); err != nil {
return nil, err
}
// Why re-generate the autoload files? Since these autoload files include list of all PSR auto-loaded files (including local workspace files)
// This will cause issues for files added/removed since the last cache as these won't be within the classmap
ctx.Logf("Re-generating autoload files.")
if err := composerDumpAutoload(ctx, []string{"--optimize"}); err != nil {
return nil, err
}
} else {
ctx.Logf("Installing application dependencies.")
// Clear layer so we don't end up with outdated dependencies (e.g. something was removed from composer.json).
Expand Down