Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add php-project-get-php-executable and php-project-get-phan-executable #436

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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