From 141cf2247d2bb52b3b12452a4b6081aa18f09710 Mon Sep 17 00:00:00 2001
From: USAMI Kenta <tadsan@zonu.me>
Date: Tue, 26 Nov 2019 23:36:42 +0900
Subject: [PATCH] Add php-system-find-php-ini-file and php-ini command

---
 php.el | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/php.el b/php.el
index 7f33fdac..663559af 100644
--- a/php.el
+++ b/php.el
@@ -413,5 +413,40 @@ When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'.
      (if (called-interactively-p 'interactive) #'display-buffer #'get-buffer)
      (format "*%s*" buf-name))))
 
+(defun php-ini ()
+  "Get `php --ini' output buffer."
+  (interactive)
+  (let ((buffer (get-buffer-create " *php --ini*")))
+    (with-current-buffer buffer
+      (view-mode -1)
+      (read-only-mode -1)
+      (erase-buffer)
+      (shell-command (concat php-executable " --ini") buffer)
+      (view-mode +1))
+    (if (called-interactively-p 'interactive)
+        (pop-to-buffer buffer)
+      buffer)))
+
+(defun php-find-system-php-ini-file (&optional file)
+  "Find php.ini FILE by `php --ini'."
+  (interactive
+   (list
+    (let* ((default-directory (expand-file-name "~"))
+           (buffer (php-ini))
+           (path (with-current-buffer buffer
+                   (goto-char (point-min))
+                   (save-match-data
+                     (when (re-search-forward ": \\(.+?\\)$" nil nil)
+                       (match-string 1))))))
+      (when (or (null path) (not (file-directory-p path)))
+        (when (called-interactively-p 'interactive)
+          (pop-to-buffer buffer))
+        (user-error "Failed get path to PHP ini files directory"))
+      (read-file-name "Find php.ini file: "
+                      (concat (expand-file-name path) "/")
+                      nil nil nil
+                      #'file-exists-p))))
+  (find-file file))
+
 (provide 'php)
 ;;; php.el ends here