@@ -78,19 +78,25 @@ for example, (get-buffer \"foo-buffer\"), '(:file . \"/path/to/file\")."
78
78
(member (car obj) (list :file :string ))
79
79
(stringp (cdr obj))))
80
80
81
+ (defun php-runtime-default-handler (status output )
82
+ " Return `OUTPUT' , and raise error when `STATUS' is not 0."
83
+ (if (eq 0 status)
84
+ output
85
+ (error output)))
81
86
82
87
; ; PHP Execute class
83
88
84
89
;;;### autoload
85
90
(defclass php-runtime-execute nil
86
91
((executable :initarg :executable :type string)
87
92
(code :initarg :code :type (satisfies php-runtime--code-satisfied-p))
93
+ (handler :initarg :handler :type function :initform #'php-runtime-default-handler )
88
94
(stdin :initarg :stdin :type (satisfies php-runtime--stdin-satisfied-p) :initform nil )
89
95
(stdout :initarg :stdout :type (or null buffer-live list ) :initform nil )
90
96
(stderr :initarg :stderr :type (or null buffer-live list ) :initform nil )))
91
97
92
98
(cl-defmethod php-runtime-run ((php php-runtime-execute))
93
- " Execute PHP process using `php -r' with code.
99
+ " Execute PHP process using `php -r' with code and return status code .
94
100
95
101
This execution method is affected by the number of character limit of OS command arguments.
96
102
You can check the limitation by command, for example \( shell-command-to-string \" getconf ARG_MAX\" ) ."
@@ -99,6 +105,13 @@ You can check the limitation by command, for example \(shell-command-to-string \
99
105
(php-runtime--call-php-process-with-input-buffer php args)
100
106
(php-runtime--call-php-process php args))))
101
107
108
+ (cl-defmethod php-runtime-process ((php php-runtime-execute))
109
+ " Execute PHP process using `php -r' with code and return output."
110
+ (let ((status (php-runtime-run php))
111
+ (output (with-current-buffer (php-runtime-stdout-buffer php)
112
+ (buffer-substring-no-properties (point-min ) (point-max )))))
113
+ (funcall (oref php handler) status output)))
114
+
102
115
(cl-defmethod php-runtime--call-php-process ((php php-runtime-execute) args)
103
116
" Execute PHP Process by php-execute `PHP' and `ARGS' ."
104
117
(apply #'call-process (oref php executable)
@@ -162,13 +175,13 @@ Pass `INPUT-BUFFER' to PHP executable as STDIN."
162
175
" Evalute PHP code `CODE' without open tag, and return buffer.
163
176
164
177
Pass `INPUT-BUFFER' to PHP executable as STDIN."
165
- (let ((execute (php-runtime-execute :code (cons :string code)
178
+ (let ((executor (php-runtime-execute :code (cons :string code)
166
179
:executable php-runtime-php-executable
167
180
:stderr (get-buffer-create php-runtime-error-buffer-name)))
168
181
(temp-input-buffer (when (and input-buffer (not (bufferp input-buffer)))
169
182
(php-runtime--temp-buffer))))
170
183
(when input-buffer
171
- (oset execute stdin
184
+ (oset executor stdin
172
185
(if (or (bufferp input-buffer)
173
186
(and (consp input-buffer) (eq :file (car input-buffer))))
174
187
input-buffer
@@ -177,13 +190,11 @@ Pass `INPUT-BUFFER' to PHP executable as STDIN."
177
190
(insert input-buffer))))))
178
191
179
192
(unwind-protect
180
- (progn (php-runtime-run execute)
181
- (with-current-buffer (php-runtime-stdout-buffer execute)
182
- (buffer-substring-no-properties (point-min ) (point-max ))))
193
+ (php-runtime-process executor)
183
194
(when (and temp-input-buffer (buffer-live-p temp-input-buffer))
184
195
(kill-buffer temp-input-buffer))
185
196
(when php-runtime--kill-temp-output-buffer
186
- (kill-buffer (php-runtime-stdout-buffer execute ))))))
197
+ (kill-buffer (php-runtime-stdout-buffer executor ))))))
187
198
188
199
(provide 'php-runtime )
189
200
; ;; php-runtime.el ends here
0 commit comments