PROGRAMMING

MINTE9
REMEMBERS




Last update:   23-07-2021

COMPOSER

Composer is a tool for dependency management in PHP. You declare the libraries your project depends on and it will install (update) them for you.
 
sudo apt update
sudo apt install wget php-cli php-zip unzip curl
curl -sS getcomposer.org/installer |php
To use Composer a project simply need a composer.json file in its root directory. This file defines the dependencies of the project.
 CodeCopy
{
    "require": {
        "nesbot/carbon": "2.12.*"
    }
}
Require    (2/2)

REQUIRE

We can edit composer.json manually, or we can use commands (require/update).
 
mkdir /var/www/html/composer-test
cd /var/www/html/composer-test

composer require nesbot/carbon

   # Failed to open stream: Permission denied
   # Cannot create cache directory /home/catalin/.composer/cache/
   # Avoid sudo when running composer.

sudo chown -R myuser.myuser composer-test
sudo chown -R catalin.catalin /home/catalin/.composer/
... 2 lines
˄˄˄
 CodeCopy
require __DIR__ . '/vendor/autoload.php';
use Carbon\Carbon;

printf("Now: %s", Carbon::now()); // Now: 2020-05-08 10:34:49
printf("Lastweek: %s", Carbon::now()->subWeek());

UPDATE

Composer will update the package if newer version found. Also, version constraint match with the one specified in the composer.json.
 
composer outdated
composer clearcache
composer update

Questions    
77. Slim Framework
76 . Composer
Last update:   23-07-2021

        A B C D E F
🔔
1/2