Create Composer autoloading rules for your Zend Framework modules
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status


The zf-composer-autoloading package provides a single vendor binary, autoload-module-via-composer, which will:

  • Add the named module to the project autoloading rules defined in composer.json, and
  • Dump the autoloading rules on completion.


Run the following composer command:

$ composer require --dev "zfcampus/zf-composer-autoloading"


$ ./vendor/bin/autoload-module-via-composer \
> [help|--help|-h] \
> [--composer|-c <composer path>] \
> [--type|-t <psr0|psr4>] \
> modulename


  • help, --help, and -h each display the script's help message.
  • --composer and -c each allow you to specify the path to the Composer binary, if it is not in your $PATH.
  • --type and -t allow you to specify the autoloading type, which should be one of psr-0 or psr-4; if not provided, the script will attempt to auto-determine the value based on the directory structure of the module.
  • modulename is the name of the module for which to setup Composer-based autoloading.


  • Modules are assumed to have a src/ directory. If they do not, the autoloading generated will be incorrect.
  • If unable to determine the autoloading type, PSR-0 will be assumed.
  • If the Module class file for the module is in the module root, it will be moved to the module's src/ directory.


  1. Autodetect a module's autoloading type, and generate a Composer autoloading entry.

    $ ./vendor/bin/autoload-module-via-composer Status
  2. Specify PSR-0 for the module type, and generate a Composer autoloading entry.

    $ ./vendor/bin/autoload-module-via-composer --type psr0 Status
  3. Specify PSR-4 for the module type, and generate a Composer autoloading entry.

    $ ./vendor/bin/autoload-module-via-composer --type psr4 Status
  4. Specify the path to the composer binary when generating autoloading entries:

    $ ./vendor/bin/autoload-module-via-composer -c composer.phar Status