03 Composer - HugoEsparzaC/CiCompOverflow GitHub Wiki

Composer dependency manager for PHP

Composer is a dependency manager for PHP projects. Similar to what npm is for Node.js, Composer allows you to declare the libraries your PHP project needs, and it takes care of installing and updating them.

Composer uses a file called composer.json to store the project's dependencies and configuration, and another file called composer.lock to lock the exact versions of the installed dependencies. By using Composer, you can ensure that your project is always using the correct versions of the libraries, making it easier to share and collaborate on projects with other developers.

Some basic Composer commands include:

  • composer install: Installs the dependencies listed in composer.json.
  • composer update: Updates the dependencies to their latest compatible versions.
  • composer require <package>: Adds a new dependency to the project.

It is especially useful in large PHP projects or projects that use many third-party packages, as it simplifies managing and updating libraries.

Create composer.json

composer init

Install composer dependencies

composer require vlucas/phpdotenv

Example composer.json

{
    "name": "hugoesparzac/ci-comp-overflow",
    "description": "A forum platform designed for Computer Science students to collaborate, ask questions, and share knowledge, inspired by Stack Overflow",
    "type": "project",
    "autoload": {
        "psr-4": {
            "MVC\\" : "./",
            "Controllers\\" : "./controllers",
            "Model\\" : "./models"
        }
    },
    "authors": [
        {
            "name": "Hugo Esparza C",
            "email": "[email protected]"
        }
    ],
    "require": {
        "vlucas/phpdotenv": "^5.6"
    }
}
⚠️ **GitHub.com Fallback** ⚠️