2022-10-04 12:36:03 +00:00
|
|
|
package frankenphp
|
|
|
|
|
2022-10-04 15:42:45 +00:00
|
|
|
import (
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
2022-10-04 12:36:03 +00:00
|
|
|
|
2022-10-15 09:54:42 +00:00
|
|
|
// Option instances allow to configure FrankenPHP.
|
2022-10-04 12:36:03 +00:00
|
|
|
type Option func(h *opt) error
|
|
|
|
|
|
|
|
// opt contains the available options.
|
|
|
|
//
|
|
|
|
// If you change this, also update the Caddy module and the documentation.
|
|
|
|
type opt struct {
|
|
|
|
numThreads int
|
|
|
|
workers []workerOpt
|
2022-10-04 15:42:45 +00:00
|
|
|
logger *zap.Logger
|
2022-10-04 12:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type workerOpt struct {
|
|
|
|
fileName string
|
|
|
|
num int
|
|
|
|
}
|
|
|
|
|
2022-10-15 09:54:42 +00:00
|
|
|
// WithNumThreads configures the number of PHP threads to start.
|
2022-10-04 12:36:03 +00:00
|
|
|
func WithNumThreads(numThreads int) Option {
|
|
|
|
return func(o *opt) error {
|
2022-10-12 07:38:45 +00:00
|
|
|
o.numThreads = numThreads
|
2022-10-04 12:36:03 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-15 09:54:42 +00:00
|
|
|
// WithWorkers configures the PHP workers to start.
|
2022-10-04 12:36:03 +00:00
|
|
|
func WithWorkers(fileName string, num int) Option {
|
|
|
|
return func(o *opt) error {
|
|
|
|
o.workers = append(o.workers, workerOpt{fileName, num})
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
2022-10-04 15:42:45 +00:00
|
|
|
|
2022-10-15 09:54:42 +00:00
|
|
|
// WithLogger configures the global logger to use.
|
2022-10-04 15:42:45 +00:00
|
|
|
func WithLogger(l *zap.Logger) Option {
|
|
|
|
return func(o *opt) error {
|
|
|
|
o.logger = l
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|