Provision sets up the module.
(ctx caddy.Context)
| 63 | |
| 64 | // Provision sets up the module. |
| 65 | func (f *FrankenPHPModule) Provision(ctx caddy.Context) error { |
| 66 | f.logger = ctx.Slogger() |
| 67 | app, err := ctx.App("frankenphp") |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | fapp, ok := app.(*FrankenPHPApp) |
| 72 | if !ok { |
| 73 | return fmt.Errorf(`expected ctx.App("frankenphp") to return *FrankenPHPApp, got %T`, app) |
| 74 | } |
| 75 | if fapp == nil { |
| 76 | return fmt.Errorf(`expected ctx.App("frankenphp") to return *FrankenPHPApp, got nil`) |
| 77 | } |
| 78 | |
| 79 | f.assignMercureHub(ctx) |
| 80 | |
| 81 | loggerOpt := frankenphp.WithRequestLogger(f.logger) |
| 82 | for i, wc := range f.Workers { |
| 83 | // make the file path absolute from the public directory |
| 84 | // this can only be done if the root is defined inside php_server |
| 85 | if !filepath.IsAbs(wc.FileName) && f.Root != "" { |
| 86 | wc.FileName = filepath.Join(f.Root, wc.FileName) |
| 87 | } |
| 88 | |
| 89 | // Inherit environment variables from the parent php_server directive |
| 90 | if f.Env != nil { |
| 91 | wc.inheritEnv(f.Env) |
| 92 | } |
| 93 | |
| 94 | wc.requestOptions = append(wc.requestOptions, loggerOpt) |
| 95 | f.Workers[i] = wc |
| 96 | } |
| 97 | |
| 98 | workers, err := fapp.addModuleWorkers(f.Workers...) |
| 99 | if err != nil { |
| 100 | return err |
| 101 | } |
| 102 | f.Workers = workers |
| 103 | |
| 104 | if f.Root == "" { |
| 105 | if frankenphp.EmbeddedAppPath == "" { |
| 106 | f.Root = "{http.vars.root}" |
| 107 | } else { |
| 108 | f.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot) |
| 109 | |
| 110 | f.ResolveRootSymlink = new(false) |
| 111 | } |
| 112 | } else if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(f.Root) { |
| 113 | f.Root = filepath.Join(frankenphp.EmbeddedAppPath, f.Root) |
| 114 | } |
| 115 | |
| 116 | if len(f.SplitPath) == 0 { |
| 117 | f.SplitPath = []string{".php"} |
| 118 | } |
| 119 | |
| 120 | opt, err := frankenphp.WithRequestSplitPath(f.SplitPath) |
| 121 | if err != nil { |
| 122 | return fmt.Errorf("invalid split_path: %w", err) |
nothing calls this directly
no test coverage detected