Skip to content

Commit 6d33794

Browse files
committed
Support PHP selector options
1 parent f88e651 commit 6d33794

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

plugins_php_selector.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (c *UserContext) PHPSelectorDisableExtension(version string, extension stri
9191
}
9292
}
9393

94-
// Extension is already disabled or doesn't exist..
94+
// Extension is already disabled or doesn't exist.
9595
if len(setExtensions) == len(enabledExtensions) {
9696
return nil
9797
}
@@ -232,6 +232,49 @@ func (c *UserContext) PHPSelectorSetExtensions(version string, extensions ...str
232232
return nil
233233
}
234234

235+
// PHPSelectorSetOptions sets the given options for the given PHP version.
236+
func (c *UserContext) PHPSelectorSetOptions(version string, options map[string]string) error {
237+
if options == nil {
238+
return errors.New("no options provided")
239+
}
240+
241+
if err := c.CreateSession(); err != nil {
242+
return fmt.Errorf("failed to create user session: %w", err)
243+
}
244+
245+
csrfToken, err := c.phpSelectorCreateCSRFToken()
246+
if err != nil {
247+
return fmt.Errorf("failed to create CSRF token: %w", err)
248+
}
249+
250+
jsonOptions, err := json.Marshal(options)
251+
if err != nil {
252+
return fmt.Errorf("failed to marshal options: %w", err)
253+
}
254+
255+
body := url.Values{}
256+
body.Set("command", "cloudlinux-selector")
257+
body.Set("csrftoken", csrfToken)
258+
body.Set("method", "set")
259+
body.Set("params[options]", string(jsonOptions))
260+
body.Set("params[interpreter]", "php")
261+
body.Set("params[version]", version)
262+
263+
resp := struct {
264+
Result string `json:"result"`
265+
}{}
266+
267+
if _, err = c.makeRequestOld(http.MethodPost, "PLUGINS/phpselector/index.raw?c=send-request", body, &resp); err != nil {
268+
return err
269+
}
270+
271+
if resp.Result != "success" {
272+
return errors.New("failed to set extensions")
273+
}
274+
275+
return nil
276+
}
277+
235278
// PHPSelectorSetVersion sets PHP to the given version.
236279
func (c *UserContext) PHPSelectorSetVersion(version string) error {
237280
if err := c.CreateSession(); err != nil {

0 commit comments

Comments
 (0)