In this repository I will use and explain composer main autoloadings: PSR-0, PSR-4, Classmap...
composer status -v
composer update
Read composer.json install/update only PHPUnit package and its dependencies and update/create composer.lock
composer update "phpunit/phpunit"
Will install the packages specified in composer.lock if not exists reads composer.json, install and write composer.lock
composer install
composer remove
composer remove "phpunit/phpunit" --update-with-dependencies
composer require "phpunit/phpunit"
Creates a "classmap" mapping having each class to its file in a big array (vendor/composer/autoload_classmap.php)
composer dump-autoload --optimize
The instructions below defines to use stable versions following this order stable, dev or alpha packages searching to use the more stable (dev, stable, beta..)
"minimum-stability": "dev",
"prefer-stable" : true
"autoload": {
"files": ["src/functions/list.php"]
}
Autoload of classes by specifying the classmap (composer dump-autoload is necessary everytime you had a new class). Array is mandatory
vendor/composer/autoload_classmap.php will content an array with Namespace\Package\Class => FILE_PATH_OF_CLASS
"autoload": {
"classmap": ["lib/"],
}
composer install
will refresh vendor/composer/autoload_namespaces.php file which is read by vendor/composer/autoload_real.php
"autoload": {
"psr-0": {
"WordWrapper": ["src/"],
}
}
Same thing but for a specific package of the namespace (classes of package Counter within the namespace Utils will be searched and loaded from src
When specifying a Namespace vendor/composer/autoload_namespaces.php will be update container Namespace\Package => DIRECTORY
"autoload": {
"psr-0": {
"Utils\\Counter": ["src/"]
}
}
It is compatible with PSR-0 but doesn't oblige to have under src/ a tree src/Utils/Log like in PSR-0
"psr-4": {
"Utils\\Log\\": ["src/"]
}