Open tacman opened 1 day ago
Yes absolutly agree. constructor should be type hinted string|array
if its an array the file read section can be skipped :+1:
and maybe writeContent should throw an exception https://github.com/nadar/php-composer-reader/blob/master/src/ComposerReader.php#L84
WriteContent could take an optional filename anyway, since you might not want to write the file to the same place it was read from. And it could be mandatory if the data came in via an array.
I have a database of Symfony bundles where the composer.json is stored as a field in the database. I'd like to invoke the reader with a string, array or object and skip reading the file and parsing it, since I don't actually have a composer.json file on the system.
I think this could be done by making the file optional in the constructor and adding a setContent() method.
Or the constructor could check if the "filename" was valid json, and if so parse it. Or add the content to the constructor.