options.go 1008 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package frankenphp
  2. import (
  3. "go.uber.org/zap"
  4. )
  5. // Option instances allow to configure FrankenPHP.
  6. type Option func(h *opt) error
  7. // opt contains the available options.
  8. //
  9. // If you change this, also update the Caddy module and the documentation.
  10. type opt struct {
  11. numThreads int
  12. workers []workerOpt
  13. logger *zap.Logger
  14. }
  15. type workerOpt struct {
  16. fileName string
  17. num int
  18. env PreparedEnv
  19. }
  20. // WithNumThreads configures the number of PHP threads to start.
  21. func WithNumThreads(numThreads int) Option {
  22. return func(o *opt) error {
  23. o.numThreads = numThreads
  24. return nil
  25. }
  26. }
  27. // WithWorkers configures the PHP workers to start.
  28. func WithWorkers(fileName string, num int, env map[string]string) Option {
  29. return func(o *opt) error {
  30. o.workers = append(o.workers, workerOpt{fileName, num, PrepareEnv(env)})
  31. return nil
  32. }
  33. }
  34. // WithLogger configures the global logger to use.
  35. func WithLogger(l *zap.Logger) Option {
  36. return func(o *opt) error {
  37. o.logger = l
  38. return nil
  39. }
  40. }