Skip to content

Commit 38d8adb

Browse files
authored
Merge pull request #804 from emacs-php/feature/print-opcode-and-php-parse
Impl php-phpdbg-disassemble-file and php-parse-file
2 parents 5d1eb02 + aaaa85c commit 38d8adb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

lisp/php.el

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@
5555
:tag "PHP Executable"
5656
:type 'string)
5757

58+
(defcustom php-phpdbg-executable (list "phpdbg")
59+
"The location of the PHPDBG executable."
60+
:group 'php
61+
:tag "PHP PHPDBG Executable"
62+
:type '(repeat string))
63+
64+
(defcustom php-php-parse-executabe nil
65+
"The location of the php-parse executable."
66+
:group 'php
67+
:tag "PHP php-parse Executable"
68+
:type '(repeat string))
69+
5870
(defcustom php-site-url "https://www.php.net/"
5971
"Default PHP.net site URL.
6072
@@ -804,5 +816,29 @@ When `DOCUMENT-ROOT' is NIL, the document root is obtained from `ROUTER-OR-DIR'.
804816
#'file-exists-p))))
805817
(find-file file))
806818

819+
820+
(defun php-phpdbg-disassemble-file (file)
821+
"Read PHP FILE and print opcodes."
822+
(interactive (list (if (or buffer-file-name (zerop (prefix-numeric-value current-prefix-arg)))
823+
buffer-file-name
824+
(expand-file-name
825+
(read-file-name "Select PHP file: " default-directory buffer-file-name)))))
826+
(let ((args `(,@php-phpdbg-executable "-dopcache.enable_cli=1" "-p*" ,file)))
827+
(compile (mapconcat #'shell-quote-argument args " "))))
828+
829+
(defun php-parse-file (file)
830+
"Parse PHP FILE and print node tree."
831+
(interactive (list (if (or buffer-file-name (zerop (prefix-numeric-value current-prefix-arg)))
832+
buffer-file-name
833+
(expand-file-name
834+
(read-file-name "Select PHP file: " default-directory buffer-file-name)))))
835+
(let* ((project-dir (php-project-get-root-dir))
836+
(executable (or php-php-parse-executabe
837+
(file-executable-p (expand-file-name "vendor/bin/php-parse" project-dir))
838+
(executable-find "php-parse")
839+
(user-error "`php-parse' command not found")))
840+
(args `(,@(if (listp executable) executable (list executable)) ,file)))
841+
(compile (mapconcat #'shell-quote-argument args " "))))
842+
807843
(provide 'php)
808844
;;; php.el ends here

0 commit comments

Comments
 (0)