REMEMBER PHP

MINTE9
2REMEMBER




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
... 3 lines
˄˄˄
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.*"
    }
}
... 5 lines
˄˄˄
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/
... 8 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());
... 4 lines
˄˄˄

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
... 3 lines
˄˄˄

Questions    
No. 76   Slim Framework
CARD
75

        A B C D E F
🔔
1/2