Skip to content

Commit

Permalink
Add php-project-get-php-executable and php-project-get-phan-executable
Browse files Browse the repository at this point in the history
Setting these related commands project-local is very important for
strict analysis of projects.
  • Loading branch information
zonuexe committed Mar 7, 2018
1 parent 0064334 commit e71fd6a
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions php-project.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
;;
;; Return list of path to bootstrap script file.
;;
;; ### `php-project-get-php-executable()'
;;
;; Return path to PHP executable file with the project settings overriding.
;;
;; ### `php-project-get-phan-executable()'
;;
;; Return path to Phan executable file with the project settings overriding.
;; Phan is a static analyzer and LSP server implementation for PHP.
;; See https://github.com/phan/phan
;;
;; ## `.dir-locals.el' support
;;
;; - `php-project-coding-style'
Expand All @@ -47,6 +57,13 @@
;; - `php-project-bootstrap-scripts'
;; - List of path to bootstrap file of project.
;; (ex. (((root . "vendor/autoload.php") (root . "inc/bootstrap.php")))
;; - `php-project-php-executable'
;; - Path to project specific PHP executable file.
;; - If you want to use a file different from the system wide `php' command.
;; - `php-project-phan-executable'
;; - Path to project specific Phan executable file.
;; - When not specified explicitly, it is automatically searched from
;; Composer's dependency of the project and `exec-path'.
;;

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

;;;###autoload
(progn
(defvar php-project-php-executable nil
"Path to php executable file.")
(make-variable-buffer-local 'php-project-php-executable)
(put 'php-project-php-executable 'safe-local-variable
#'(lambda (v) (and (stringp v) (file-executable-p v)))))

;;;###autoload
(progn
(defvar php-project-phan-executable nil
"Path to phan executable file.")
(make-variable-buffer-local 'php-project-phan-executable)
(put 'php-project-phan-executable 'safe-local-variable #'php-project--eval-bootstrap-scripts))

;;;###autoload
(progn
(defvar php-project-coding-style nil
Expand Down Expand Up @@ -120,6 +152,22 @@ Typically it is `pear', `drupal', `wordpress', `symfony2' and `psr2'.")
(cl-loop for v in val collect (php-project--eval-bootstrap-scripts v)))
(t nil)))

(defun php-project-get-php-executable ()
"Return path to PHP executable file."
(cond
((and (stringp php-project-php-executable)
(file-executable-p php-project-php-executable))
php-project-php-executable)
((boundp 'php-executable) php-executable)
(t (executable-find "php"))))

(defun php-project-get-phan-executable ()
"Return path to phan executable file."
(or (car-safe (php-project--eval-bootstrap-scripts
(list php-project-phan-executable
(cons 'root "vendor/bin/phan"))))
(executable-find "phan")))

;;;###autoload
(defun php-project-get-bootstrap-scripts ()
"Return list of bootstrap script."
Expand Down

0 comments on commit e71fd6a

Please sign in to comment.