Installing Propel in our project via Composer
Let's pull Propel2 ORM into our project using Composer. Let's take a look at the related packages needed for Propel2.
Installing Composer globally on Ubuntu 14.04 is described here .
The first stage of familiarization will be
The main source of plug-in libraries and ready-made solutions will be
composer.json :
composer.json - the main file in which the necessary libraries, the rules for their installation and other fine-tuning will be written.
Composer.json example :
{
"require": {
"php":">=7.0"
}
}
This example will check if our php version matches the one required in the file. Since I have php 5.6, it will give an error.
Problem 1
- This package requires php >=7.0 but your PHP version (5.6.36) does not satisfy that requirement.
composer.lock :
composer.lock - file of installable versions. When install is created if not created, but is not updated when re-installing. It stores the versions of the libraries used. To update versions, update is used.
Consider the basic commands to get started with composer:
1.Init- creates composer.json :
In the root of the site (for example /var/www/proj.loc), using the init command, you need to create a composer.json.
composer init
After entering init, you will be required to enter project data. Once input is complete, a composer.json file will be created.
Will create a file with standard information about the project, the user, but with an empty list of included libraries.
{
"name": "username/proj.loc",
"description": "Description",
"type": "proj.loc",
"license": "free",
"authors": [
{
"name": "username",
"email": "ad@min.loc"
}
],
"require": {}
}
2. Require - adding a new package from packegist.org to composer.json:
We are in the directory where the required composer.json is located (in my case /var/www/proj.loc).
composer require symfony/var-dumper
This command will pull symfony/var-dumper , its related packages in use, and do an install . This package will be deployed in the standard project directory in the vendor folder and regenerate the autoload.php file, which is responsible for including all installed libraries.
But there is also the ability to add the necessary packages manually, and do install or update.
Example:
{
"name": "username/proj.loc",
"description": "Description",
"type": "proj.loc",
"license": "free",
"authors": [
{
"name": "userbame",
"email": "ad@min.loc"
}
],
"require": {
"symfony/var-dumper": "^3.4"
}
}
3. Install - depending on the require block in composer.json , it installs all the packages specified in it, pulls the links used by these packages.
composer install
After that, a vendor folder is created near the composer.json file and packages are pulled into it. If composer.lock is not created, it will be created with the package versions at the time of installation. If you re-install, then composer.lock will not be regenerated, and the versions that are written in composer.lock will be pulled up
4. Update - updates the versions of the packages in the composer.lock file. Doesn't touch versions in composer.json.
composer update
Unlike install, it pulls up the latest versions of the required libraries and writes them into composer.lock, and the next install will take new versions from everyone if composer.lock is present (since it is in priority).
You should be careful with this command, as updates may be pulled up in which the methods you use are called differently and thus you can fail the assembly.
A complete list of commands can be found
Let's pull Propel2 ORM into our project using Composer. Let's take a look at the related packages needed for Propel2.
Having figured out what Compser is and what it is for, you should figure out how to use it on the site. In the article, we will consider connecting libraries pulled up through Composer.