nadar / php-composer-reader

A PHP library to read and manipulate the composer.json file.
MIT License
23 stars 4 forks source link

read from composer json string instead of file #14

Open tacman opened 1 day ago

tacman commented 1 day ago

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.

nadar commented 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:

nadar commented 1 day ago

and maybe writeContent should throw an exception https://github.com/nadar/php-composer-reader/blob/master/src/ComposerReader.php#L84

tacman commented 1 day ago

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.