I'm working on a PHP library (as a composer package) that needs a XML file to work. I'm using simplexml_load_file
to load the XML file, but I'm wondering where I should put the file and how to get a path that always works. The current file structure looks like this is:
/
src/
Vendor/
Library.php
tests/
LibraryTest.php
composer.json
composer.lock
My composer.json
file :
{
"name": "vendor/library",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Vendor": "src/"
}
}
}
You can't do this directly, but there are some possibilities:
Create a private repository which will contain only your XML file and add it to your composer. You'll then find it in your vendor folder. Here you can find a documentation about how to create custom repos: https://getcomposer.org/doc/articles/handling-private-packages-with-satis.md
Save it in your application, in some data
folder and add to a GIT.
Add a simple checking to your application, so if the XML file hasn't been found, display message with information how to get it.
I'd recommend to mix points 2 and 3.