options.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. maxThreads int
  13. workers []workerOpt
  14. logger *zap.Logger
  15. metrics Metrics
  16. phpIni map[string]string
  17. }
  18. type workerOpt struct {
  19. fileName string
  20. num int
  21. env PreparedEnv
  22. watch []string
  23. }
  24. // WithNumThreads configures the number of PHP threads to start.
  25. func WithNumThreads(numThreads int) Option {
  26. return func(o *opt) error {
  27. o.numThreads = numThreads
  28. return nil
  29. }
  30. }
  31. func WithMaxThreads(maxThreads int) Option {
  32. return func(o *opt) error {
  33. o.maxThreads = maxThreads
  34. return nil
  35. }
  36. }
  37. func WithMetrics(m Metrics) Option {
  38. return func(o *opt) error {
  39. o.metrics = m
  40. return nil
  41. }
  42. }
  43. // WithWorkers configures the PHP workers to start.
  44. func WithWorkers(fileName string, num int, env map[string]string, watch []string) Option {
  45. return func(o *opt) error {
  46. o.workers = append(o.workers, workerOpt{fileName, num, PrepareEnv(env), watch})
  47. return nil
  48. }
  49. }
  50. // WithLogger configures the global logger to use.
  51. func WithLogger(l *zap.Logger) Option {
  52. return func(o *opt) error {
  53. o.logger = l
  54. return nil
  55. }
  56. }
  57. // WithPhpIni configures user defined PHP ini settings.
  58. func WithPhpIni(overrides map[string]string) Option {
  59. return func(o *opt) error {
  60. o.phpIni = overrides
  61. return nil
  62. }
  63. }