@@ -127,6 +127,7 @@ func (f *FrankenPHPApp) Stop() error {
127127func (f * FrankenPHPApp ) UnmarshalCaddyfile (d * caddyfile.Dispenser ) error {
128128 for d .Next () {
129129 for d .NextBlock (0 ) {
130+ // when adding a new directive, also update the allowedDirectives error message
130131 switch d .Val () {
131132 case "num_threads" :
132133 if ! d .NextArg () {
@@ -198,12 +199,20 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
198199 }
199200
200201 if d .NextArg () {
201- v , err := strconv .Atoi (d .Val ())
202- if err != nil {
203- return err
202+ if d .Val () == "watch" {
203+ wc .Watch = append (wc .Watch , "./**/*.{php,yaml,yml,twig,env}" )
204+ } else {
205+ v , err := strconv .Atoi (d .Val ())
206+ if err != nil {
207+ return err
208+ }
209+
210+ wc .Num = v
204211 }
212+ }
205213
206- wc .Num = v
214+ if d .NextArg () {
215+ return errors .New ("FrankenPHP: too many 'worker' arguments: " + d .Val ())
207216 }
208217
209218 for d .NextBlock (1 ) {
@@ -241,6 +250,9 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
241250 } else {
242251 wc .Watch = append (wc .Watch , d .Val ())
243252 }
253+ default :
254+ allowedDirectives := "file, num, env, watch"
255+ return wrongSubDirectiveError ("worker" , allowedDirectives , v )
244256 }
245257
246258 if wc .FileName == "" {
@@ -253,6 +265,9 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
253265 }
254266
255267 f .Workers = append (f .Workers , wc )
268+ default :
269+ allowedDirectives := "num_threads, max_threads, php_ini, worker"
270+ return wrongSubDirectiveError ("frankenphp" , allowedDirectives , d .Val ())
256271 }
257272 }
258273 }
@@ -407,6 +422,7 @@ func (f FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ ca
407422
408423// UnmarshalCaddyfile implements caddyfile.Unmarshaler.
409424func (f * FrankenPHPModule ) UnmarshalCaddyfile (d * caddyfile.Dispenser ) error {
425+ // when adding a new directive, also update the allowedDirectives error message
410426 for d .Next () {
411427 for d .NextBlock (0 ) {
412428 switch d .Val () {
@@ -448,6 +464,9 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
448464 }
449465
450466 f .ResolveRootSymlink = & v
467+ default :
468+ allowedDirectives := "root, split, env, resolve_root_symlink"
469+ return wrongSubDirectiveError ("php or php_server" , allowedDirectives , d .Val ())
451470 }
452471 }
453472 }
@@ -745,6 +764,11 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
745764 }, nil
746765}
747766
767+ // return a nice error message
768+ func wrongSubDirectiveError (module string , allowedDriectives string , wrongValue string ) error {
769+ return fmt .Errorf ("unknown '%s' subdirective: '%s' (allowed directives are: %s)" , module , wrongValue , allowedDriectives )
770+ }
771+
748772// Interface guards
749773var (
750774 _ caddy.App = (* FrankenPHPApp )(nil )
0 commit comments