The reason you're not able to find any documentation for PSR-4 autoloading files which aren't classes, that's because as the specification states - it's designed for autoloading classes.
Taken directly from the official specs:
This PSR describes a specification for autoloading classes from file paths. It is fully interoperable, and can be used in addition to any other autoloading specification, including PSR-0. This PSR also describes where to place files that will be autoloaded according to the specification.
More specifically;
The term "class" refers to classes, interfaces, traits, and other similar structures.
A file with functions isn't really a similar structure.
To autoload those files, you'll need to autoload using files
:
"autoload": {
"files": [
"src/my_cool_function1.php",
"src/my_cool_function2.php"
],
"psr-4": {
"SomeNamespace\\": "src/YourNamespace/"
}
}
You'll notice from this, that the psr-4 spec maps (usually) to a namespace.
my_lib/function1.php
, and then namespace it like this:<?php namespace my_lib; function function1() {}
? – Shutdown