caddy.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. // Package caddy provides a PHP module for the Caddy web server.
  2. // FrankenPHP embeds the PHP interpreter directly in Caddy, giving it the ability to run your PHP scripts directly.
  3. // No PHP FPM required!
  4. package caddy
  5. import (
  6. "encoding/json"
  7. "errors"
  8. "fmt"
  9. "github.com/prometheus/client_golang/prometheus"
  10. "net/http"
  11. "path/filepath"
  12. "strconv"
  13. "strings"
  14. "github.com/caddyserver/caddy/v2"
  15. "github.com/caddyserver/caddy/v2/caddyconfig"
  16. "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
  17. "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
  18. "github.com/caddyserver/caddy/v2/modules/caddyhttp"
  19. "github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver"
  20. "github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
  21. "github.com/dunglas/frankenphp"
  22. "go.uber.org/zap"
  23. )
  24. const defaultDocumentRoot = "public"
  25. func init() {
  26. caddy.RegisterModule(FrankenPHPApp{})
  27. caddy.RegisterModule(FrankenPHPModule{})
  28. httpcaddyfile.RegisterGlobalOption("frankenphp", parseGlobalOption)
  29. httpcaddyfile.RegisterHandlerDirective("php", parseCaddyfile)
  30. httpcaddyfile.RegisterDirectiveOrder("php", "before", "file_server")
  31. httpcaddyfile.RegisterDirective("php_server", parsePhpServer)
  32. httpcaddyfile.RegisterDirectiveOrder("php_server", "before", "file_server")
  33. }
  34. type mainPHPinterpreterKeyType int
  35. var mainPHPInterpreterKey mainPHPinterpreterKeyType
  36. var phpInterpreter = caddy.NewUsagePool()
  37. var metrics = frankenphp.NewPrometheusMetrics(prometheus.DefaultRegisterer)
  38. type phpInterpreterDestructor struct{}
  39. func (phpInterpreterDestructor) Destruct() error {
  40. frankenphp.Shutdown()
  41. return nil
  42. }
  43. type workerConfig struct {
  44. // FileName sets the path to the worker script.
  45. FileName string `json:"file_name,omitempty"`
  46. // Num sets the number of workers to start.
  47. Num int `json:"num,omitempty"`
  48. // Env sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
  49. Env map[string]string `json:"env,omitempty"`
  50. // Directories to watch for file changes
  51. Watch []string `json:"watch,omitempty"`
  52. }
  53. type FrankenPHPApp struct {
  54. // NumThreads sets the number of PHP threads to start. Default: 2x the number of available CPUs.
  55. NumThreads int `json:"num_threads,omitempty"`
  56. // Workers configures the worker scripts to start.
  57. Workers []workerConfig `json:"workers,omitempty"`
  58. }
  59. // CaddyModule returns the Caddy module information.
  60. func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
  61. return caddy.ModuleInfo{
  62. ID: "frankenphp",
  63. New: func() caddy.Module { return &f },
  64. }
  65. }
  66. func (f *FrankenPHPApp) Start() error {
  67. repl := caddy.NewReplacer()
  68. logger := caddy.Log()
  69. opts := []frankenphp.Option{frankenphp.WithNumThreads(f.NumThreads), frankenphp.WithLogger(logger), frankenphp.WithMetrics(metrics)}
  70. for _, w := range f.Workers {
  71. opts = append(opts, frankenphp.WithWorkers(repl.ReplaceKnown(w.FileName, ""), w.Num, w.Env, w.Watch))
  72. }
  73. _, loaded, err := phpInterpreter.LoadOrNew(mainPHPInterpreterKey, func() (caddy.Destructor, error) {
  74. if err := frankenphp.Init(opts...); err != nil {
  75. return nil, err
  76. }
  77. return phpInterpreterDestructor{}, nil
  78. })
  79. if err != nil {
  80. return err
  81. }
  82. if loaded {
  83. frankenphp.Shutdown()
  84. if err := frankenphp.Init(opts...); err != nil {
  85. return err
  86. }
  87. }
  88. return nil
  89. }
  90. func (f *FrankenPHPApp) Stop() error {
  91. caddy.Log().Info("FrankenPHP stopped 🐘")
  92. // reset configuration so it doesn't bleed into later tests
  93. f.Workers = nil
  94. f.NumThreads = 0
  95. return nil
  96. }
  97. // UnmarshalCaddyfile implements caddyfile.Unmarshaler.
  98. func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
  99. for d.Next() {
  100. for d.NextBlock(0) {
  101. switch d.Val() {
  102. case "num_threads":
  103. if !d.NextArg() {
  104. return d.ArgErr()
  105. }
  106. v, err := strconv.Atoi(d.Val())
  107. if err != nil {
  108. return err
  109. }
  110. f.NumThreads = v
  111. case "worker":
  112. wc := workerConfig{}
  113. if d.NextArg() {
  114. wc.FileName = d.Val()
  115. }
  116. if d.NextArg() {
  117. v, err := strconv.Atoi(d.Val())
  118. if err != nil {
  119. return err
  120. }
  121. wc.Num = v
  122. }
  123. for d.NextBlock(1) {
  124. v := d.Val()
  125. switch v {
  126. case "file":
  127. if !d.NextArg() {
  128. return d.ArgErr()
  129. }
  130. wc.FileName = d.Val()
  131. case "num":
  132. if !d.NextArg() {
  133. return d.ArgErr()
  134. }
  135. v, err := strconv.Atoi(d.Val())
  136. if err != nil {
  137. return err
  138. }
  139. wc.Num = v
  140. case "env":
  141. args := d.RemainingArgs()
  142. if len(args) != 2 {
  143. return d.ArgErr()
  144. }
  145. if wc.Env == nil {
  146. wc.Env = make(map[string]string)
  147. }
  148. wc.Env[args[0]] = args[1]
  149. case "watch":
  150. if !d.NextArg() {
  151. // the default if the watch directory is left empty:
  152. wc.Watch = append(wc.Watch, "./**/*.{php,yaml,yml,twig,env}")
  153. } else {
  154. wc.Watch = append(wc.Watch, d.Val())
  155. }
  156. }
  157. if wc.FileName == "" {
  158. return errors.New(`the "file" argument must be specified`)
  159. }
  160. if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(wc.FileName) {
  161. wc.FileName = filepath.Join(frankenphp.EmbeddedAppPath, wc.FileName)
  162. }
  163. }
  164. f.Workers = append(f.Workers, wc)
  165. }
  166. }
  167. }
  168. return nil
  169. }
  170. func parseGlobalOption(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) {
  171. app := &FrankenPHPApp{}
  172. if err := app.UnmarshalCaddyfile(d); err != nil {
  173. return nil, err
  174. }
  175. // tell Caddyfile adapter that this is the JSON for an app
  176. return httpcaddyfile.App{
  177. Name: "frankenphp",
  178. Value: caddyconfig.JSON(app, nil),
  179. }, nil
  180. }
  181. type FrankenPHPModule struct {
  182. // Root sets the root folder to the site. Default: `root` directive, or the path of the public directory of the embed app it exists.
  183. Root string `json:"root,omitempty"`
  184. // SplitPath sets the substrings for splitting the URI into two parts. The first matching substring will be used to split the "path info" from the path. The first piece is suffixed with the matching substring and will be assumed as the actual resource (CGI script) name. The second piece will be set to PATH_INFO for the CGI script to use. Default: `.php`.
  185. SplitPath []string `json:"split_path,omitempty"`
  186. // ResolveRootSymlink enables resolving the `root` directory to its actual value by evaluating a symbolic link, if one exists.
  187. ResolveRootSymlink *bool `json:"resolve_root_symlink,omitempty"`
  188. // Env sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
  189. Env map[string]string `json:"env,omitempty"`
  190. resolvedDocumentRoot string
  191. preparedEnv frankenphp.PreparedEnv
  192. preparedEnvNeedsReplacement bool
  193. logger *zap.Logger
  194. }
  195. // CaddyModule returns the Caddy module information.
  196. func (FrankenPHPModule) CaddyModule() caddy.ModuleInfo {
  197. return caddy.ModuleInfo{
  198. ID: "http.handlers.php",
  199. New: func() caddy.Module { return new(FrankenPHPModule) },
  200. }
  201. }
  202. // Provision sets up the module.
  203. func (f *FrankenPHPModule) Provision(ctx caddy.Context) error {
  204. f.logger = ctx.Logger(f)
  205. if f.Root == "" {
  206. if frankenphp.EmbeddedAppPath == "" {
  207. f.Root = "{http.vars.root}"
  208. } else {
  209. rrs := false
  210. f.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot)
  211. f.ResolveRootSymlink = &rrs
  212. }
  213. } else {
  214. if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(f.Root) {
  215. f.Root = filepath.Join(frankenphp.EmbeddedAppPath, f.Root)
  216. }
  217. }
  218. if len(f.SplitPath) == 0 {
  219. f.SplitPath = []string{".php"}
  220. }
  221. if f.ResolveRootSymlink == nil {
  222. rrs := true
  223. f.ResolveRootSymlink = &rrs
  224. }
  225. if !needReplacement(f.Root) {
  226. root, err := filepath.Abs(f.Root)
  227. if err != nil {
  228. return fmt.Errorf("unable to make the root path absolute: %w", err)
  229. }
  230. f.resolvedDocumentRoot = root
  231. if *f.ResolveRootSymlink {
  232. root, err := filepath.EvalSymlinks(root)
  233. if err != nil {
  234. return fmt.Errorf("unable to resolve root symlink: %w", err)
  235. }
  236. f.resolvedDocumentRoot = root
  237. }
  238. }
  239. if f.preparedEnv == nil {
  240. f.preparedEnv = frankenphp.PrepareEnv(f.Env)
  241. for _, e := range f.preparedEnv {
  242. if needReplacement(e) {
  243. f.preparedEnvNeedsReplacement = true
  244. break
  245. }
  246. }
  247. }
  248. return nil
  249. }
  250. // needReplacement checks if a string contains placeholders.
  251. func needReplacement(s string) bool {
  252. return strings.Contains(s, "{") || strings.Contains(s, "}")
  253. }
  254. // ServeHTTP implements caddyhttp.MiddlewareHandler.
  255. // TODO: Expose TLS versions as env vars, as Apache's mod_ssl: https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go#L298
  256. func (f FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ caddyhttp.Handler) error {
  257. origReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
  258. repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
  259. var documentRootOption frankenphp.RequestOption
  260. if f.resolvedDocumentRoot == "" {
  261. documentRootOption = frankenphp.WithRequestDocumentRoot(repl.ReplaceKnown(f.Root, ""), *f.ResolveRootSymlink)
  262. } else {
  263. documentRootOption = frankenphp.WithRequestResolvedDocumentRoot(f.resolvedDocumentRoot)
  264. }
  265. env := make(map[string]string, len(f.preparedEnv)+1)
  266. env["REQUEST_URI\x00"] = origReq.URL.RequestURI()
  267. for k, v := range f.preparedEnv {
  268. if f.preparedEnvNeedsReplacement {
  269. env[k] = repl.ReplaceKnown(v, "")
  270. } else {
  271. env[k] = v
  272. }
  273. }
  274. fr, err := frankenphp.NewRequestWithContext(
  275. r,
  276. documentRootOption,
  277. frankenphp.WithRequestSplitPath(f.SplitPath),
  278. frankenphp.WithRequestPreparedEnv(env),
  279. )
  280. if err != nil {
  281. return err
  282. }
  283. return frankenphp.ServeHTTP(w, fr)
  284. }
  285. // UnmarshalCaddyfile implements caddyfile.Unmarshaler.
  286. func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
  287. for d.Next() {
  288. for d.NextBlock(0) {
  289. switch d.Val() {
  290. case "root":
  291. if !d.NextArg() {
  292. return d.ArgErr()
  293. }
  294. f.Root = d.Val()
  295. case "split":
  296. f.SplitPath = d.RemainingArgs()
  297. if len(f.SplitPath) == 0 {
  298. return d.ArgErr()
  299. }
  300. case "env":
  301. args := d.RemainingArgs()
  302. if len(args) != 2 {
  303. return d.ArgErr()
  304. }
  305. if f.Env == nil {
  306. f.Env = make(map[string]string)
  307. f.preparedEnv = make(frankenphp.PreparedEnv)
  308. }
  309. f.Env[args[0]] = args[1]
  310. f.preparedEnv[args[0]+"\x00"] = args[1]
  311. case "resolve_root_symlink":
  312. if !d.NextArg() {
  313. continue
  314. }
  315. v, err := strconv.ParseBool(d.Val())
  316. if err != nil {
  317. return err
  318. }
  319. if d.NextArg() {
  320. return d.ArgErr()
  321. }
  322. f.ResolveRootSymlink = &v
  323. }
  324. }
  325. }
  326. return nil
  327. }
  328. // parseCaddyfile unmarshals tokens from h into a new Middleware.
  329. func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
  330. m := FrankenPHPModule{}
  331. err := m.UnmarshalCaddyfile(h.Dispenser)
  332. return m, err
  333. }
  334. // parsePhpServer parses the php_server directive, which has a similar syntax
  335. // to the php_fastcgi directive. A line such as this:
  336. //
  337. // php_server
  338. //
  339. // is equivalent to a route consisting of:
  340. //
  341. // # Add trailing slash for directory requests
  342. // @canonicalPath {
  343. // file {path}/index.php
  344. // not path */
  345. // }
  346. // redir @canonicalPath {path}/ 308
  347. //
  348. // # If the requested file does not exist, try index files
  349. // @indexFiles file {
  350. // try_files {path} {path}/index.php index.php
  351. // split_path .php
  352. // }
  353. // rewrite @indexFiles {http.matchers.file.relative}
  354. //
  355. // # FrankenPHP!
  356. // @phpFiles path *.php
  357. // php @phpFiles
  358. // file_server
  359. //
  360. // parsePhpServer is freely inspired from the php_fastgci directive of the Caddy server (Apache License 2.0, Matthew Holt and The Caddy Authors)
  361. func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
  362. if !h.Next() {
  363. return nil, h.ArgErr()
  364. }
  365. // set up FrankenPHP
  366. phpsrv := FrankenPHPModule{}
  367. // set up file server
  368. fsrv := fileserver.FileServer{}
  369. disableFsrv := false
  370. // set up the set of file extensions allowed to execute PHP code
  371. extensions := []string{".php"}
  372. // set the default index file for the try_files rewrites
  373. indexFile := "index.php"
  374. // set up for explicitly overriding try_files
  375. tryFiles := []string{}
  376. // if the user specified a matcher token, use that
  377. // matcher in a route that wraps both of our routes;
  378. // either way, strip the matcher token and pass
  379. // the remaining tokens to the unmarshaler so that
  380. // we can gain the rest of the directive syntax
  381. userMatcherSet, err := h.ExtractMatcherSet()
  382. if err != nil {
  383. return nil, err
  384. }
  385. // make a new dispenser from the remaining tokens so that we
  386. // can reset the dispenser back to this point for the
  387. // php unmarshaler to read from it as well
  388. dispenser := h.NewFromNextSegment()
  389. // read the subdirectives that we allow as overrides to
  390. // the php_server shortcut
  391. // NOTE: we delete the tokens as we go so that the php
  392. // unmarshal doesn't see these subdirectives which it cannot handle
  393. for dispenser.Next() {
  394. for dispenser.NextBlock(0) {
  395. // ignore any sub-subdirectives that might
  396. // have the same name somewhere within
  397. // the php passthrough tokens
  398. if dispenser.Nesting() != 1 {
  399. continue
  400. }
  401. // parse the php_server subdirectives
  402. switch dispenser.Val() {
  403. case "root":
  404. if !dispenser.NextArg() {
  405. return nil, dispenser.ArgErr()
  406. }
  407. phpsrv.Root = dispenser.Val()
  408. fsrv.Root = phpsrv.Root
  409. dispenser.DeleteN(2)
  410. case "split":
  411. extensions = dispenser.RemainingArgs()
  412. dispenser.DeleteN(len(extensions) + 1)
  413. if len(extensions) == 0 {
  414. return nil, dispenser.ArgErr()
  415. }
  416. case "index":
  417. args := dispenser.RemainingArgs()
  418. dispenser.DeleteN(len(args) + 1)
  419. if len(args) != 1 {
  420. return nil, dispenser.ArgErr()
  421. }
  422. indexFile = args[0]
  423. case "try_files":
  424. args := dispenser.RemainingArgs()
  425. dispenser.DeleteN(len(args) + 1)
  426. if len(args) < 1 {
  427. return nil, dispenser.ArgErr()
  428. }
  429. tryFiles = args
  430. case "file_server":
  431. args := dispenser.RemainingArgs()
  432. dispenser.DeleteN(len(args) + 1)
  433. if len(args) < 1 || args[0] != "off" {
  434. return nil, dispenser.ArgErr()
  435. }
  436. disableFsrv = true
  437. }
  438. }
  439. }
  440. // reset the dispenser after we're done so that the frankenphp
  441. // unmarshaler can read it from the start
  442. dispenser.Reset()
  443. if frankenphp.EmbeddedAppPath != "" {
  444. if phpsrv.Root == "" {
  445. phpsrv.Root = filepath.Join(frankenphp.EmbeddedAppPath, defaultDocumentRoot)
  446. fsrv.Root = phpsrv.Root
  447. rrs := false
  448. phpsrv.ResolveRootSymlink = &rrs
  449. } else if filepath.IsLocal(fsrv.Root) {
  450. phpsrv.Root = filepath.Join(frankenphp.EmbeddedAppPath, phpsrv.Root)
  451. fsrv.Root = phpsrv.Root
  452. }
  453. }
  454. // set up a route list that we'll append to
  455. routes := caddyhttp.RouteList{}
  456. // set the list of allowed path segments on which to split
  457. phpsrv.SplitPath = extensions
  458. // if the index is turned off, we skip the redirect and try_files
  459. if indexFile != "off" {
  460. // route to redirect to canonical path if index PHP file
  461. redirMatcherSet := caddy.ModuleMap{
  462. "file": h.JSON(fileserver.MatchFile{
  463. TryFiles: []string{"{http.request.uri.path}/" + indexFile},
  464. }),
  465. "not": h.JSON(caddyhttp.MatchNot{
  466. MatcherSetsRaw: []caddy.ModuleMap{
  467. {
  468. "path": h.JSON(caddyhttp.MatchPath{"*/"}),
  469. },
  470. },
  471. }),
  472. }
  473. redirHandler := caddyhttp.StaticResponse{
  474. StatusCode: caddyhttp.WeakString(strconv.Itoa(http.StatusPermanentRedirect)),
  475. Headers: http.Header{"Location": []string{"{http.request.orig_uri.path}/"}},
  476. }
  477. redirRoute := caddyhttp.Route{
  478. MatcherSetsRaw: []caddy.ModuleMap{redirMatcherSet},
  479. HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(redirHandler, "handler", "static_response", nil)},
  480. }
  481. // if tryFiles wasn't overridden, use a reasonable default
  482. if len(tryFiles) == 0 {
  483. tryFiles = []string{"{http.request.uri.path}", "{http.request.uri.path}/" + indexFile, indexFile}
  484. }
  485. // route to rewrite to PHP index file
  486. rewriteMatcherSet := caddy.ModuleMap{
  487. "file": h.JSON(fileserver.MatchFile{
  488. TryFiles: tryFiles,
  489. SplitPath: extensions,
  490. }),
  491. }
  492. rewriteHandler := rewrite.Rewrite{
  493. URI: "{http.matchers.file.relative}",
  494. }
  495. rewriteRoute := caddyhttp.Route{
  496. MatcherSetsRaw: []caddy.ModuleMap{rewriteMatcherSet},
  497. HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(rewriteHandler, "handler", "rewrite", nil)},
  498. }
  499. routes = append(routes, redirRoute, rewriteRoute)
  500. }
  501. // route to actually pass requests to PHP files;
  502. // match only requests that are for PHP files
  503. var pathList []string
  504. for _, ext := range extensions {
  505. pathList = append(pathList, "*"+ext)
  506. }
  507. phpMatcherSet := caddy.ModuleMap{
  508. "path": h.JSON(pathList),
  509. }
  510. // the rest of the config is specified by the user
  511. // using the php directive syntax
  512. dispenser.Next() // consume the directive name
  513. err = phpsrv.UnmarshalCaddyfile(dispenser)
  514. if err != nil {
  515. return nil, err
  516. }
  517. // create the PHP route which is
  518. // conditional on matching PHP files
  519. phpRoute := caddyhttp.Route{
  520. MatcherSetsRaw: []caddy.ModuleMap{phpMatcherSet},
  521. HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(phpsrv, "handler", "php", nil)},
  522. }
  523. routes = append(routes, phpRoute)
  524. // create the file server route
  525. if !disableFsrv {
  526. fileRoute := caddyhttp.Route{
  527. MatcherSetsRaw: []caddy.ModuleMap{},
  528. HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(fsrv, "handler", "file_server", nil)},
  529. }
  530. routes = append(routes, fileRoute)
  531. }
  532. subroute := caddyhttp.Subroute{
  533. Routes: routes,
  534. }
  535. // the user's matcher is a prerequisite for ours, so
  536. // wrap ours in a subroute and return that
  537. if userMatcherSet != nil {
  538. return []httpcaddyfile.ConfigValue{
  539. {
  540. Class: "route",
  541. Value: caddyhttp.Route{
  542. MatcherSetsRaw: []caddy.ModuleMap{userMatcherSet},
  543. HandlersRaw: []json.RawMessage{caddyconfig.JSONModuleObject(subroute, "handler", "subroute", nil)},
  544. },
  545. },
  546. }, nil
  547. }
  548. // otherwise, return the literal subroute instead of
  549. // individual routes, to ensure they stay together and
  550. // are treated as a single unit, without necessarily
  551. // creating an actual subroute in the output
  552. return []httpcaddyfile.ConfigValue{
  553. {
  554. Class: "route",
  555. Value: subroute,
  556. },
  557. }, nil
  558. }
  559. // Interface guards
  560. var (
  561. _ caddy.App = (*FrankenPHPApp)(nil)
  562. _ caddy.Provisioner = (*FrankenPHPModule)(nil)
  563. _ caddyhttp.MiddlewareHandler = (*FrankenPHPModule)(nil)
  564. _ caddyfile.Unmarshaler = (*FrankenPHPModule)(nil)
  565. )