Skip to content

🛠️ DumpAutoloadWithOptions

Generates autoloader files using a custom option map. It is the flexible variant of DumpAutoload.

When to use

Use it when you need to specify multiple options such as --optimize, --classmap-authoritative, --apcu, and --no-dev simultaneously, which the single boolean parameter of DumpAutoload cannot express.

Signature

go
func (c *Composer) DumpAutoloadWithOptions(options map[string]string) error

Parameters

ParameterTypeDescription
optionsmap[string]stringAutoloader option map; keys are option names (without --), values are option values, and boolean options take an empty string

Return value

error: returns the corresponding error message if an error occurs while generating the autoloader files; nil on success.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("initialization failed: %v", err)
	}

	// Maximum optimization combination for production
	options := map[string]string{
		"optimize":             "",
		"classmap-authoritative": "",
		"apcu":                 "",
		"no-dev":               "",
	}
	if err := comp.DumpAutoloadWithOptions(options); err != nil {
		log.Fatalf("failed to generate autoloader: %v", err)
	}

	fmt.Println("Autoloader files generated")
}

Advanced

  • --classmap-authoritative requires a complete and accurate class map; it is recommended to use it together with --optimize.
  • --apcu requires the APCu extension to be installed in PHP, otherwise it is ignored.
  • For simple scenarios that only need the optimize toggle, DumpAutoload is more straightforward.

Released under the MIT License