ashleyhood / php-lxd

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

PHP Catchable fatal error when file writing to container #14

Closed renky closed 7 years ago

renky commented 7 years ago

When using the file write method there happens a PHP Catchable fatal error. Has anybody already used file write and read successfully?

$lxd->containers->files->write($containernamename,'/etc/network/interfaces', 'test'); leads to: PHP Catchable fatal error: Argument 1 passed to Opensaucesystems\Lxd\Endpoint\AbstructEndpoint::createJsonBody() must be of the type arra y, string given, called in /..../vendor/opensaucesystems/lxd/src/Endpoint/AbstructEndpoint.php on line 51 and defined in /..../vendor/opensaucesystems/lxd/src/Endpoint/AbstructEndpoint.php on line 121

renky commented 7 years ago

ok sorry - after shortly thinking about it: This Function protected function createJsonBody(array $data) doesn't make sense like it is... In the function it is checked if it is an array or not - but the header already forces the input to be an array... but on the other hand when writing a file, it is usually a string - is there a case where this data is really an array? And how should it be? Is the solution only to remove the "array" from the createJsonBody-Definition? So this solves my problem now, but what did the creator want, when he wrote the function?

ashleyhood commented 7 years ago

You are right, it shouldn't have a type-hint of array on the createJsonBody or on the data input for post, put or patch methods (just over aggressive type-hinting by me).

I think we could just remove the type-hints and that should solve it.