options.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. metrics Metrics
  15. }
  16. type workerOpt struct {
  17. fileName string
  18. num int
  19. env PreparedEnv
  20. }
  21. // WithNumThreads configures the number of PHP threads to start.
  22. func WithNumThreads(numThreads int) Option {
  23. return func(o *opt) error {
  24. o.numThreads = numThreads
  25. return nil
  26. }
  27. }
  28. func WithMetrics(m Metrics) Option {
  29. return func(o *opt) error {
  30. o.metrics = m
  31. return nil
  32. }
  33. }
  34. // WithWorkers configures the PHP workers to start.
  35. func WithWorkers(fileName string, num int, env map[string]string) Option {
  36. return func(o *opt) error {
  37. o.workers = append(o.workers, workerOpt{fileName, num, PrepareEnv(env)})
  38. return nil
  39. }
  40. }
  41. // WithLogger configures the global logger to use.
  42. func WithLogger(l *zap.Logger) Option {
  43. return func(o *opt) error {
  44. o.logger = l
  45. return nil
  46. }
  47. }