Open Spreeuw opened 3 years ago
You can use override_autoload
to add a files
key to the package's existing autoload configuration with the extra files you want.
Adding the res
folder to composer/ca-bundle is straightforward:
{
"require": {
"composer/ca-bundle": "1.2.10"
},
"require-dev": {
"brianhenryie/strauss": "0.10.4"
},
"extra": {
"strauss": {
"target_directory": "strauss",
"namespace_prefix": "Issue31\\",
"override_autoload": {
"composer/ca-bundle": {
"psr-4": {
"Composer\\CaBundle\\": "src"
},
"files": [
"res"
]
}
}
}
}
}
tecnickcom/tcpdf's fonts
folder contains PHP files that you probably don't want to prefix, so add that path to the exclude_from_prefix
/file_patterns
key.
{
"require": {
"tecnickcom/tcpdf": "6.4.2"
},
"require-dev": {
"brianhenryie/strauss": "0.10.4"
},
"extra": {
"strauss": {
"target_directory": "strauss",
"namespace_prefix": "Issue31\\",
"override_autoload": {
"tecnickcom/tcpdf": {
"classmap": [
"config",
"include",
"tcpdf.php",
"tcpdf_parser.php",
"tcpdf_import.php",
"tcpdf_barcodes_1d.php",
"tcpdf_barcodes_2d.php",
"include/tcpdf_colors.php",
"include/tcpdf_filters.php",
"include/tcpdf_font_data.php",
"include/tcpdf_fonts.php",
"include/tcpdf_images.php",
"include/tcpdf_static.php",
"include/barcodes/datamatrix.php",
"include/barcodes/pdf417.php",
"include/barcodes/qrcode.php"
],
"files": [
"fonts"
]
}
},
"exclude_from_prefix": {
"file_patterns": [
"/^psr.*$/",
"~^tecnickcom/tcpdf/fonts.*~"
]
}
}
}
}
TBH, most of the classmap they have defined is unnecessary here. Once the directory is specified, everything inside it will be copied.
I'll leave this open until I update the README with a few lines about this.
Thanks for working that out! I think we'll stick to copying afterwards in that case, for simplicity sake. Configuring the autoloader part feels like an unnecessary extra step if all you want is the files to be copied.
Excellent. This worked well for copying directories I need. Thank you @BrianHenryIE.
Stripped down version:
"extra": {
"strauss": {
"override_autoload": {
"composer/ca-bundle": {
"files": [
"res"
]
}
}
}
}
I'm considering this functionality, maybe like:
"extra": {
"strauss": {
"copy_files": {
"composer/ca-bundle": [
"res"
]
}
}
}
It would really just be merged back into the override_autoload
key mentioned above, but it's a little clearer.
What's the best name? extra_files
, include_files
, additional_files
, just files
?
@alexmigf
@BrianHenryIE extra_files
or additional_files
seems fine to me.
@BrianHenryIE I had need for something like this due to how Dompdf works. By default strauss does not copy some of the root files. The VERSION
file is actually needed by dompdf or else it throws an error when using the library.
See this line: https://github.com/dompdf/dompdf/blob/v2.0.3/src/Dompdf.php#L261
I had to the following to get all the files into the prefixed directory:
"override_autoload": {
"dompdf/dompdf": {
"classmap": ["."]
}
}
When utilizing libraries that contain files like fonts (
tecnickcom/tcpdf
) or other non-php assets (composer/ca-bundle
is a library built around acacert.pem
file), these assets are not copied over by Strauss. We currently resolve this with a bash script that runs after Strauss, but it would be nice to be able to tell Strauss which folders to copy over, or even to let it copy all the files/folders for a specific library?