Skip to content

Commit

Permalink
Phpactor installation procedure
Browse files Browse the repository at this point in the history
Add a phpactor-update function in order to manage Phpactor's
installation from this package.

As an alternative, let the user configure `phactor-executable` but
remove other ways of detecting phpactor.
  • Loading branch information
kermorgant committed Sep 30, 2018
1 parent 9ca0352 commit 5389bec
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
11 changes: 9 additions & 2 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ This package is Emacs interface to [[http://phpactor.github.io/phpactor/][Phpact

*NOTICE*: This package is in development. Since some functions are running, this is released as an /alpha version/.

*NOTICE*: Phpactor is also in development stage.

#+BEGIN_HTML
<a href="http://melpa.org/#/phpactor"><img alt="MELPA: phpactor" src="http://melpa.org/packages/phpactor-badge.svg"></a>
<a href="http://stable.melpa.org/#/phpactor"><img alt="MELPA stable: phpactor" src="http://stable.melpa.org/packages/phpactor-badge.svg"></a>
#+END_HTML
** Instalation
Please be aware that Phpactor is also in development stage.
A simple installation method is not yet provided, but you can build it using Composer.

After having installed this package, run `phpactor-update` (this will install a supported version of phpactor inside phpactor.el's installation folder).
*NOTICE*: To ensure the appropriate version of Phpactor is installed, please run this command after every upgrade of phpactor.el

Alternatively, you can install Phpactor on your own and configure `phpactor-executable` but please be aware that any change in Phpactor's rpc protocol can introduce breakages.


** Configuration
See https://phpactor.github.io/phpactor/configuration.html

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"sebastian/diff": "@dev"
},
"config": {
"sort-packages": true
"optimize-autoloader": true,
"classmap-authoritative": true,
"sort-packages": true
}
}
30 changes: 25 additions & 5 deletions phpactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
;; Created: 8 Apr 2018
;; Version: 0.1.0
;; Keywords: tools, php
;; Package-Requires: ((emacs "24.3") (cl-lib "0.5") (f "0.17"))
;; Package-Requires: ((emacs "24.3") (cl-lib "0.5") (f "0.17") (composer "0.1"))
;; URL: https://github.com/emacs-php/phpactor.el
;; License: GPL-3.0-or-later

Expand Down Expand Up @@ -48,6 +48,7 @@
(require 'json)
(require 'php-project)
(require 'ring)
(require 'composer)

;; Variables
;;;###autoload
Expand All @@ -72,6 +73,7 @@
(defvar phpactor--debug nil)
(defvar phpactor-history-size 100)
(defvar phpactor-history-ring nil)
(defvar phpactor-allow-composer-setup t)

(defvar phpactor--buffer-name "*Phpactor*")

Expand All @@ -86,10 +88,26 @@
"Return Phpactor command or path to executable."
(or (when phpactor-executable
(php-project--eval-bootstrap-scripts phpactor-executable))
(executable-find phpactor-command-name)
(let ((vendor-executable (f-join (phpactor-get-working-dir) "vendor/bin/phpactor")))
(let ((vendor-executable (f-join (phpactor-package-directory) "vendor/bin/phpactor")))
(when (file-exists-p vendor-executable)
vendor-executable))))
vendor-executable))
(error "Phpactor not found. Please run phpactor-update")))

(defun phpactor-update ()
"Install or update phpactor inside phpactor.el's folder."
(interactive)
(let ((package-folder (phpactor-package-directory))
(composer-executable (car (composer--find-executable))))
(setq default-directory package-folder)
(unless composer-executable
(when (not phpactor-allow-composer-setup) (error ("composer not found.")))
(composer--ensure-exist-managed-composer-phar)
(setq composer-executable (composer--get-path-tomanaged-composer-phar)))
(call-process composer-executable nil (get-buffer-create phpactor-action--buffer-name) nil "install" "--no-dev")))

(defun phpactor-package-directory ()
"Return the folder where phpactor.el is installed."
(file-name-directory(locate-library "phpactor.el")))

(defun phpactor-get-working-dir ()
"Return working directory of Phpactor."
Expand Down Expand Up @@ -464,7 +482,9 @@ function."
(cl-defun phpactor-action-dispatch (&key action parameters version)
"Execite action by `NAME' and `PARAMETERS'."
(when (and version (not (equal phpactor--supported-rpc-version version)))
(error "Phpactor uses rpc protocol %s whereas this package requires %s" version phpactor--supported-rpc-version))
(if (phpactor-executable)
(error "Phpactor uses rpc protocol %s but this package requires %s" version phpactor--supported-rpc-version)
(error "Phpactor should be upgraded. Please run phpactor-update")))
(phpactor--add-history 'phpactor-action-dispatch (list :action action :parameters parameters :version version))
(let ((func (cdr-safe (assq (intern action) phpactor-action-table))))
(if func
Expand Down

0 comments on commit 5389bec

Please sign in to comment.