Showing posts with label Composer. Show all posts
Showing posts with label Composer. Show all posts

Difference Between Composer.json and Composer.lock or composer.json v/s composer.lock

 In a Simple ways

composer.json is the list of required libraries and versions for your project.

composer.lock is what is currently installed.

Composer Update ( Refers composer.json file )

When you do composer update it will check for the composer.json file and updates all the packages/libraries that are listed in it & once the packages are updated it will rewrite new updates in composer.json & composer.lock file by deleting old package updates.

Basically, the following process takes place

A - Read composer.json

B - Remove installed packages that are not required in composer.json

C- Check latest versions of required packages in composer.json from https://packagist.org

D - Install the latest versions of your packages

E - Update composer.lock with installed packages version & even update composer.json file with it

F - composer install


Composer Install ( Uses composer.lock file)

When you do composer install it will check for composer.lock file and install all the packages/libraries that are listed in composer.lock file.

This command won't update anything like composer update.

Basically, the following process takes place

1) composer.lock file 

If it does not exists then run composer-update and create it

If exists then read composer.lock file for installation of packages

2) Install the packages specified in the composer.lock file


what is the composer and use in drupal 8

 

Composer is a dependency manager for PHP. Drupal can be updated through composer using the command line.

Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries. It was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project.

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Drupal uses Composer to manage the various libraries that it depends on. Modules can also use Composer to include 3rd party libraries.

Drupal update through composer using the following command.

To update Drupal using composer, run the command 'composer update drupal/core --with-dependencies'

Using Composer with Drupal 8

There are many benefits to using Composer. In short, it allows us to systematically manage a sprawling list of dependencies (and their subsidiary dependencies). It assists with locating, downloading, validating, and loading said packages, all while ensuring that exactly the right versions for each package are used. 


Composer.json

Composer retrieves information from packagist.org to download packages, Drupal projects are not listed on Packagist, instead, Drupal.org provides its own repository of composer metadata for Drupal projects.


The Composer template, already includes it in therepositories ofcomposer.json:


"repositories": [

    {

        "type": "composer",

        "url": "https://packages.drupal.org/8"

    }

],

Core version

In Composer, Drupal core is a package like any other. So it is added to your project by adding a dependency to your composer.json.


Adding the following information to the composer.json will download the latest Drupal 7 release and place it in the web/-folder of the Composer project.


{

    "require": {

        "composer/installers": "~1.0",

        "drupal/drupal": "7.*"

    },

    "repositories": [

        {

            "type": "composer",

            "url": "https://packages.drupal.org/7"

        }

    ],

    "extra": {

        "installer-paths": {

            "web/": [

                "type:drupal-core"

            ]

        }

    }

}

With Drupal 8 we can choose the same approach ("drupal/drupal": "8.*") or we can use the subtree-split of the core-directory ("drupal/core": "8.*").


You can use the ready to go template for each version: Branch 8.x for Drupal 8 or Branch 7.x for Drupal 7


Projects

All Drupal projects to be retrieved should be added as dependencies in semantic versioning format.


The following will download the Chaos tool suite (ctools) module version 1.4 for Drupal 7.


{

    "require": {

        "drupal/ctools": "1.4"

    }

}

The module will be placed under sites/all/modules/contrib/.


You can also run php composer.phar require drupal/ctools from the command line in the root directory of the project. This will prompt for any additional information needed and update composer.json accordingly.


Since many Drupal projects are not available from the default Composer package repository Packagist, they will be downloaded from the Drupal repository defined in the composer.json

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...