zfcampus / zf-composer-autoloading
Sets up Composer-based autoloading for your Zend Framework modules
Installs: 879 065
Dependents: 5
Suggesters: 0
Security: 0
Stars: 16
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- php: ^5.6 || ^7.0
- zendframework/zend-stdlib: ^3.1
Requires (Dev)
- mikey179/vfsstream: ^1.6.4
- mockery/mockery: ^1.0
- php-mock/php-mock-phpunit: ^1.1.2 || ^2.0
- phpunit/phpunit: ^5.7.27 || ^6.5.8 || ^7.1.5
- zendframework/zend-coding-standard: ~1.0.0
README
Repository abandoned 2019-12-31
This repository has moved to laminas/laminas-composer-autoloading.
Introduction
The zf-composer-autoloading
package provides a single vendor binary,
zf-composer-autoloading
, which provides following commands:
enable
- add the named module to the project autoloading rules defined incomposer.json
, anddisable
- remove autoloading rules for the module fromcomposer.json
Both commands also dump the autoloading rules on completion.
Upgrading
If you were using the v1 series of this component, the script previously exposed was
autoload-module-via-composer
. That script is now renamed tozf-composer-autoloading
.
Installation
Run the following composer
command:
$ composer require --dev "zfcampus/zf-composer-autoloading"
Note the --dev
flag; this tool is intended for use in development only.
Usage
$ ./vendor/bin/zf-composer-autoloading \ > enable|disable \ > [help|--help|-h] \ > [--composer|-c <composer path>] \ > [--type|-t <psr0|psr4>] \ > [--modules-path|-p <path>] \ > modulename
Commands
enable
- enables composer-based autoloading for the module.disable
- disables composer-based autoloading for the module.
Arguments
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 ofpsr-0
orpsr-4
; if not provided, the script will attempt to auto-determine the value based on the directory structure of the module.--modules-path
and-p
allow you to specify the path to the modules directory; default tomodule
.modulename
is the name of the module for which to setup Composer-based autoloading.
Notes
- 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.
- On enabling autoloading, if the
Module
class file for the module is in the module root, it will be moved to the module'ssrc/
directory (zend-mvc applications only).
Examples
-
Autodetect a module's autoloading type, and generate a Composer autoloading entry for "Status" module.
$ ./vendor/bin/zf-composer-autoloading enable Status
-
Autodetect a module's autoloading type, and remove a Composer autoloading entry for "Status" module.
$ ./vendor/bin/zf-composer-autoloading disable Status
-
Specify PSR-0 for the module type, and generate a Composer autoloading entry for "Status" module.
$ ./vendor/bin/zf-composer-autoloading enable --type psr0 Status
-
Specify PSR-4 for the module type, and generate a Composer autoloading entry for "Status" module.
$ ./vendor/bin/zf-composer-autoloading enable --type psr4 Status
-
Specify the path to the composer binary when generating autoloading entry for "Status" module:
$ ./vendor/bin/zf-composer-autoloading enable -c composer.phar Status
-
Specify the path to modules directory, and generate a Composer autoloading entry for "Status" module.
$ ./vendor/bin/zf-composer-autoloading enable -p src Status