0Pricing
PHP Academy · Lesson

Composer Scripts and Autoloading

Define scripts in composer.json and enable class autoloading.

Scripts in composer.json

The scripts key defines named shell commands that run via composer run-script NAME or just composer NAME.

Defining a Script

Scripts are arrays of shell commands or PHP static-method callbacks.

// composer.json
{
  "scripts": {
    "test": "vendor/bin/phpunit",
    "lint": "vendor/bin/phpcs src/",
    "cs-fix": "vendor/bin/phpcbf src/"
  }
}

All lessons in this course

  1. Installing and Initializing Composer
  2. Requiring and Updating Packages
  3. Understanding composer.lock
  4. Composer Scripts and Autoloading
← Back to PHP Academy