Skip to content

Commit

Permalink
Use classmap instead of files for global __
Browse files Browse the repository at this point in the history
Composer supports having two different mechanisms for autoloading,
[`classmap`][composer-classmap] or [`files`][composer-files]. The
`files` option is intended to be used for PHP files which define
functions in the global namespace. Any classes that need to be in the
global namespace should happen via the `classmap` option.

In situations where you try using `__` inside of a Composer callback
[script][composer-script], you would receive a 'Class "__" not found'
message. This is due to the fact that `files` are not autoloaded in
Composer scripts.

> Callbacks can only autoload classes from psr-0, psr-4 and classmap
> definitions. If a defined callback relies on functions defined outside
> of a class, the callback itself is responsible for loading the file
> containing these functions.

[composer-script]: https://getcomposer.org/doc/articles/scripts.md#defining-scripts
[composer-classmap]: https://getcomposer.org/doc/04-schema.md#classmap
[composer-files]: https://getcomposer.org/doc/04-schema.md#files
  • Loading branch information
allejo committed Jun 14, 2023
1 parent 73f68be commit a8c8845
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

**TBD — [Diff](https://github.com/maciejczyzewski/bottomline/compare/0.2.3...0.2.4)[Docs](https://maciejczyzewski.github.io/bottomline/)**

* Fix `Class "__" not found` autoload error when calling `__::*` inside of a Composer script
* Added `__::some` as a counterpart to `__::every`
* Made the callable in `__::every` nullable. It will default to using `__::identity` so that using `__::every` with an array will automatically remove all falsey values

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"phpunit/phpunit": "^4.8||^6.5||^9.5"
},
"autoload": {
"files": ["bottomline.php"],
"classmap": ["bottomline.php"],
"psr-4": {"__\\": "src/__/"}
},
"autoload-dev": {
Expand Down

0 comments on commit a8c8845

Please sign in to comment.