MCPcopy Index your code
hub / github.com/php/frankenphp / parsePhpServer

Function parsePhpServer

caddy/module.go:369–627  ·  view source on GitHub ↗

parsePhpServer parses the php_server directive, which has a similar syntax to the php_fastcgi directive. A line such as this: php_server is equivalent to a route consisting of: # Add trailing slash for directory requests @canonicalPath { file {path}/index.php not path */ } re

(h httpcaddyfile.Helper)

Source from the content-addressed store, hash-verified

367//
368// parsePhpServer is freely inspired from the php_fastgci directive of the Caddy server (Apache License 2.0, Matthew Holt and The Caddy Authors)
369func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
370 if !h.Next() {
371 return nil, h.ArgErr()
372 }
373
374 // set up FrankenPHP
375 phpsrv := FrankenPHPModule{}
376
377 // set up file server
378 fsrv := fileserver.FileServer{}
379 disableFsrv := false
380
381 // set up the set of file extensions allowed to execute PHP code
382 extensions := []string{".php"}
383
384 // set the default index file for the try_files rewrites
385 indexFile := "index.php"
386
387 // set up for explicitly overriding try_files
388 var tryFiles []string
389
390 // if the user specified a matcher token, use that
391 // matcher in a route that wraps both of our routes;
392 // either way, strip the matcher token and pass
393 // the remaining tokens to the unmarshaler so that
394 // we can gain the rest of the directive syntax
395 userMatcherSet, err := h.ExtractMatcherSet()
396 if err != nil {
397 return nil, err
398 }
399
400 // make a new dispenser from the remaining tokens so that we
401 // can reset the dispenser back to this point for the
402 // php unmarshaler to read from it as well
403 dispenser := h.NewFromNextSegment()
404
405 // read the subdirectives that we allow as overrides to
406 // the php_server shortcut
407 // NOTE: we delete the tokens as we go so that the php
408 // unmarshal doesn't see these subdirectives which it cannot handle
409 for dispenser.Next() {
410 for dispenser.NextBlock(0) {
411 // ignore any sub-subdirectives that might
412 // have the same name somewhere within
413 // the php passthrough tokens
414 if dispenser.Nesting() != 1 {
415 continue
416 }
417
418 // parse the php_server subdirectives
419 switch dispenser.Val() {
420 case "root":
421 if !dispenser.NextArg() {
422 return nil, dispenser.ArgErr()
423 }
424 phpsrv.Root = dispenser.Val()
425 fsrv.Root = phpsrv.Root
426 dispenser.DeleteN(2)

Callers

nothing calls this directly

Calls 3

UnmarshalCaddyfileMethod · 0.95
prependWorkerRoutesFunction · 0.85
ResetMethod · 0.80

Tested by

no test coverage detected