Subject: bug#72966: 30.0.90; [PATCH] php-ts-mode: custom php.ini config for the built-in php webserver

From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 02 Sep 2024 15:29:23 +0200

Ciao, 
this patch adds a new CONFIG attribute to 'php-ts-mode-run-php-webserver' that 
allows you to specify an alternative php.ini file to the default (or whatever 
is specified in 'php-ts-mode-php-config').
Thanks.

Vincenzo.

>From 8b688884219e081a086559728251172d710b51e2 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Mon, 2 Sep 2024 14:11:01 +0200
Subject: [PATCH] Support for custom php.ini for the built-in PHP web server.

A new CONFIG attribute, which defaults to 'php-ts-mode-php-config',
allows an alternative php.ini file to be specified for the built-in web
server. The 'php-ts-mode-run-php-webserver' function, when called
interactively with a prefix argument, also requires this new attribute.

* lisp/progmodes/php-ts-mode.el (php-ts-mode-run-php-webserver):
New CONFIG attribute. Update docstring.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--webserver-read-args):
Support the new TYPE. Update docstring.
---
 lisp/progmodes/php-ts-mode.el | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index 3f89de14075..34304049c5c 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -1469,8 +1469,12 @@ php-ts-mode
 
 
 ;;;###autoload
-(defun php-ts-mode-run-php-webserver (&optional port hostname document-root
-                                                router-script num-of-workers)
+(defun php-ts-mode-run-php-webserver (&optional port
+                                                hostname
+                                                document-root
+                                                router-script
+                                                config
+                                                num-of-workers)
   "Run PHP built-in web server.
 
 PORT: Port number of built-in web server, default `php-ts-mode-ws-port'.
@@ -1482,12 +1486,14 @@ php-ts-mode-run-php-webserver
 Prompt for the document-root if the default value is nil.
 ROUTER-SCRIPT: Path of the router PHP script,
 see `https://www.php.net/manual/en/features.commandline.webserver.php'
+CONFIG: Alternative php.ini config, default `php-ts-mode-php-config'.
 NUM-OF-WORKERS: Before run the web server set the
 PHP_CLI_SERVER_WORKERS env variable useful for testing code against
 multiple simultaneous requests.
 
+
 Interactively, when invoked with prefix argument, always prompt
-for PORT, HOSTNAME, DOCUMENT-ROOT and ROUTER-SCRIPT."
+for PORT, HOSTNAME, DOCUMENT-ROOT, ROUTER-SCRIPT and CONFIG."
   (interactive (when current-prefix-arg
                  (php-ts-mode--webserver-read-args)))
   (let* ((port (or
@@ -1502,6 +1508,9 @@ php-ts-mode-run-php-webserver
                          document-root
                          php-ts-mode-ws-document-root
                          (php-ts-mode--webserver-read-args 'document-root)))
+         (config (or config
+                     (when php-ts-mode-php-config
+                       (expand-file-name php-ts-mode-php-config))))
          (host (format "%s:%d" hostname port))
          (name (format "PHP web server on: %s" host))
          (buf-name (format "*%s*" name))
@@ -1509,6 +1518,8 @@ php-ts-mode-run-php-webserver
                 nil
                 (list "-S" host
                       "-t" document-root
+                      (when config
+			(format "-c %s" config))
                       router-script)))
          (process-environment
           (cons (cond
@@ -1529,8 +1540,8 @@ php-ts-mode-run-php-webserver
 
 (defun php-ts-mode--webserver-read-args (&optional type)
   "Helper for `php-ts-mode-run-php-webserver'.
-The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\" or
-\"router-script\", otherwise it requires all of them."
+The optional TYPE can be the symbol \"port\", \"hostname\", \"document-root\",
+\"router-script\" or \"config\", otherwise it requires all of them."
   (let ((ask-port (lambda ()
                     (read-number "Port: " 3000)))
         (ask-hostname (lambda ()
@@ -1546,17 +1557,25 @@ php-ts-mode--webserver-read-args
                               (read-file-name "Router script: "
                                               (file-name-directory
                                                (or (buffer-file-name)
-                                                   default-directory)))))))
+                                                   default-directory))))))
+        (ask-config (lambda()
+                      (expand-file-name
+                       (read-file-name "Alternative php.ini: "
+                                       (file-name-directory
+                                        (or (buffer-file-name)
+                                            default-directory)))))))
     (cl-case type
       (port (funcall ask-port))
       (hostname (funcall ask-hostname))
       (document-root (funcall ask-document-root))
       (router-script (funcall ask-router-script))
+      (config (funcall ask-config))
       (t (list
           (funcall ask-port)
           (funcall ask-hostname)
           (funcall ask-document-root)
-          (funcall ask-router-script))))))
+          (funcall ask-router-script)
+          (funcall ask-config))))))
 
 (define-derived-mode inferior-php-ts-mode comint-mode "Inferior PHP"
   "Major mode for PHP inferior process."
-- 
2.46.0