I was able to solve my problem using hints from Jakub Zalas's answer (option 2).
The idea is to:
- Copy composer's working
autoload_classmap.php
to autoload_classmap-orig.php
.
- Rearrange classes/change
composer.json
as required.
- Test new autoload against orig classmap.
To avoid situation when including one class' source file automaticaly defines another class (i. e. more than one class is defined in one file), each class should be loaded in clean php environment (separate php-cli run).
I used 2 scripts for that:
Class autoload checker (check.php):
<?php
// test if a class, mentioned in autoload_classmap-orig.php at line $num,
// can be autoloaded. Exit status: 0 - ok, 4 - failed to autoload,
// 3 - no more classes in autoload_classmap-orig.php
error_reporting(0);
require_once(__DIR__ . "/vendor/autoload.php");
$num = $argv[1];
$classes = array_keys(include('autoload_classmap-orig.php'));
if (!isset($classes[$num])) {
exit(3);
}
$current_class = $classes[$num];
echo $current_class;
if (!class_exists($current_class)) {
exit(4);
}
exit(0);
Iterator (check.sh)
#!/usr/bin/env bash
# call ./check.php until all classes are checked or max number
# of checks reached.
max=500
num=0
while true ; do
php ./check.php $num
status=$?
case $status in
0) echo " - OK" ;;
3) echo "\nFinished." ; break ;;
4) echo " - CAN NOT BE AUTOLOADED" ;;
*) echo " - UNKNOWN ERROR $status" ;;
esac
num=$(($num + 1))
if [ "$num" -gt "$max" ] ; then
echo "\nMax number of classes reached."
break
fi
done