Skip to content

Commit e71fd6a

Browse files
committed
Add php-project-get-php-executable and php-project-get-phan-executable
Setting these related commands project-local is very important for strict analysis of projects.
1 parent 0064334 commit e71fd6a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

php-project.el

+48
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
;;
3838
;; Return list of path to bootstrap script file.
3939
;;
40+
;; ### `php-project-get-php-executable()'
41+
;;
42+
;; Return path to PHP executable file with the project settings overriding.
43+
;;
44+
;; ### `php-project-get-phan-executable()'
45+
;;
46+
;; Return path to Phan executable file with the project settings overriding.
47+
;; Phan is a static analyzer and LSP server implementation for PHP.
48+
;; See https://github.com/phan/phan
49+
;;
4050
;; ## `.dir-locals.el' support
4151
;;
4252
;; - `php-project-coding-style'
@@ -47,6 +57,13 @@
4757
;; - `php-project-bootstrap-scripts'
4858
;; - List of path to bootstrap file of project.
4959
;; (ex. (((root . "vendor/autoload.php") (root . "inc/bootstrap.php")))
60+
;; - `php-project-php-executable'
61+
;; - Path to project specific PHP executable file.
62+
;; - If you want to use a file different from the system wide `php' command.
63+
;; - `php-project-phan-executable'
64+
;; - Path to project specific Phan executable file.
65+
;; - When not specified explicitly, it is automatically searched from
66+
;; Composer's dependency of the project and `exec-path'.
5067
;;
5168

5269
;;; Code:
@@ -93,6 +110,21 @@ defines constants, and sets the class loaders.")
93110
(make-variable-buffer-local 'php-project-bootstrap-scripts)
94111
(put 'php-project-bootstrap-scripts 'safe-local-variable #'php-project--eval-bootstrap-scripts))
95112

113+
;;;###autoload
114+
(progn
115+
(defvar php-project-php-executable nil
116+
"Path to php executable file.")
117+
(make-variable-buffer-local 'php-project-php-executable)
118+
(put 'php-project-php-executable 'safe-local-variable
119+
#'(lambda (v) (and (stringp v) (file-executable-p v)))))
120+
121+
;;;###autoload
122+
(progn
123+
(defvar php-project-phan-executable nil
124+
"Path to phan executable file.")
125+
(make-variable-buffer-local 'php-project-phan-executable)
126+
(put 'php-project-phan-executable 'safe-local-variable #'php-project--eval-bootstrap-scripts))
127+
96128
;;;###autoload
97129
(progn
98130
(defvar php-project-coding-style nil
@@ -120,6 +152,22 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
120152
(cl-loop for v in val collect (php-project--eval-bootstrap-scripts v)))
121153
(t nil)))
122154

155+
(defun php-project-get-php-executable ()
156+
"Return path to PHP executable file."
157+
(cond
158+
((and (stringp php-project-php-executable)
159+
(file-executable-p php-project-php-executable))
160+
php-project-php-executable)
161+
((boundp 'php-executable) php-executable)
162+
(t (executable-find "php"))))
163+
164+
(defun php-project-get-phan-executable ()
165+
"Return path to phan executable file."
166+
(or (car-safe (php-project--eval-bootstrap-scripts
167+
(list php-project-phan-executable
168+
(cons 'root "vendor/bin/phan"))))
169+
(executable-find "phan")))
170+
123171
;;;###autoload
124172
(defun php-project-get-bootstrap-scripts ()
125173
"Return list of bootstrap script."

0 commit comments

Comments
 (0)