ashleyhood / php-lxd

A PHP library for interacting with the LXD REST API
MIT License
28 stars 15 forks source link

Containers write don't work properly #31

Open piferrari opened 3 years ago

piferrari commented 3 years ago

Hi,

There is a mistake in arguments between Endpoint/Containers/Files/write() (line55) and Endpoint/AbstructEndpoint/post() (line 49).

In the first method (write) when you make a call to post (line 55) you give 3 arguments :

->post(the container name?with_get_params, follow by data, and headers)

but you must add an parameter between data and headers because in the post method the 3rd parameters is used to buildPath and actually you buildPath with requestHeaders array.

I corrected it like that at

return $this->post($this->getEndpoint().$name.'/files?path='.$filepath, $data, /****** USLESS ********/ []  /****** ARRAY ******/, $headers);

but i think you can find a more elegant way.

Best regards

PS: sorry for my poor english

ashleyhood commented 3 years ago

Thanks @piferrari for finding that. There are 3 solutions we could do:

  1. just add the empty array as you have done (least preferred)
  2. remove the parameter argument from AbstructEndpoint.php and refactor all the code that uses it (might work)
  3. refactor the endpoints to use the parameter argument correctly (this is the best solution but the hardest to do)

Does anyone else have any preference or comments?