Composer là gì?
Composer là một trong khí cụ dùng làm quản lý và vận hành những Package
nhập project. Nó được chấp nhận khai báo, install
, update
hoặc remove
một hoặc nhiều package nhập project của công ty.
Bạn đang xem: composer là gì
Cơ chế hoạt động và sinh hoạt của Composer cũng ko cần là mới mẻ, tất cả chúng ta tiếp tục phát hiện concept
này ở NPM của NodeJs hoặc Bundle của Ruby language.
Dependency management
Composer không quản lý và vận hành những Packgage tương tự như yum
trong Centos hoặc apt
trong Ubuntu. Nó quản lý và vận hành những Packages theo đuổi từng Project ví dụ và ko tương hỗ phạm vi thiết đặt global
. Tất cả những Package đều được thiết đặt nhập folder vendor
của project , tất cả chúng ta rất có thể xóa ngẫu nhiên Package nào là của project trải qua Composer
Các mệnh lệnh cơ phiên bản nhập Composer
Để dùng Composer
các các bạn cần sở hữu nó bên trên máy của tớ. cũng có thể sở hữu song lập bằng phương pháp chuyển vận tệp tin bên trên trang chủ của Composer về và sở hữu như thông thường . Mé canh bại liệt cũng đều có một những không giống là bạn cũng có thể dùng Laragon
vì thế nhập Laragon tiếp tục tích thích hợp sẵn Composer
rồi
Để kiểm tra composer đang được sở hữu trên máy của công ty hoặc ko, chúng ta chạy mệnh lệnh sau
composer
Sau khi thiết đặt thành công xuất sắc những bạn cũng có thể chính thức dò la hiểu những câu mệnh lệnh cơ phiên bản nhập Laragon bên dưới đây
Composer Init
Đây là mệnh lệnh khởi tạo ra composer cho tới project của công ty, khi chạy mệnh lệnh này nó sẽ bị căn vặn các bạn nhập một trong những options như sau
--name
: Tên của package.
--description
: Mô miêu tả về package.
--author
: Tên tác giả
--type
: Kiểu của Package.
--homepage
: Link home page page của Package
--require
: Package và version bắt buộc
--require-dev
: Package giành cho môi trường xung quanh dev
--repository
: Link package thẳng kể từ Github repository
Composer install
Lệnh này tiếp tục gọi toàn bộ những package config nhập tệp tin composer,json và sở hữu chúng nó vào folder vender
composer install
Chúng tao hay sử dụng mệnh lệnh này cho tới lần thứ nhất init project hoặc khi với package vừa mới được insert nhập tệp tin composer.json
Composer update
Để update lên version tiên tiến nhất của những package tiếp tục `install` nhập vendor tất cả chúng ta tiếp tục dùng lệnh
composer update
Tất cả những package nhập project được update lên version mới mẻ sẽ tiến hành ghi lại nhập vào tệp tin composer.lock. Sau này sở hữu lại project nó sẽ bị lấy phiên bản tiên tiến nhất này
Trường thích hợp không thích update toàn bộ những package của project tất cả chúng ta rất có thể hướng đẫn package name cần thiết update
php composer.phar update vendor/package1 vendor/package2
Bạn cũng rất có thể dùng cú pháp sau đây nhằm update thứu tự từng package nhập folder vendor
php composer.phar update "vendor/*"
Để rollback lại về version thấp rộng lớn cho 1 package tất cả chúng ta dùng command này
php composer.phar update
The custom constraint has vĩ đại be a subset of the existing constraint you have, and this feature is only available for your root package dependencies.
If you only want vĩ đại update the package(s) for which you provide custom constraints using --with, you can skip --with and just use constraints with the partial update syntax:
php composer.phar update vendor/package:2.0.1 vendor/package2:3.0.*
--prefer-source: Install packages from source when available.
--prefer-dist: Install packages from dist when available.
--dry-run: Simulate the command without actually doing anything.
--dev: Install packages listed in require-dev (this is the mặc định behavior).
--no-dev: Skip installing packages listed in require-dev. The autoloader generation skips the autoload-dev rules.
--no-install: Does not lập cập the install step after updating the composer.lock tệp tin.
--lock: Only updates the lock tệp tin hash vĩ đại suppress warning about the lock tệp tin being out of date.
--with: Temporary version constraint vĩ đại add, e.g. foo/bar:1.0.0 or foo/bar=1.0.0
--no-autoloader: Skips autoloader generation.
--no-scripts: Skips execution of scripts defined in composer.json.
--no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
--with-dependencies (-w): Update also dependencies of packages in the argument list, except those which are root requirements.
--with-all-dependencies (-W): Update also dependencies of packages in the argument list, including those which are root requirements.
--optimize-autoloader (-o): Convert PSR-0/4 autoloading vĩ đại classmap vĩ đại get a faster autoloader. This is recommended especially for production, but can take a bit of time vĩ đại lập cập, so sánh it is currently not done by mặc định.
--classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
--apcu-autoloader: Use APCu vĩ đại cache found/not-found classes.
--apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.
Xem thêm: make a mess là gì
--ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
--ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it.
--prefer-stable: Prefer stable versions of dependencies.
--prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.
--interactive: Interactive interface with autocompletion vĩ đại select the packages vĩ đại update.
--root-reqs: Restricts the update vĩ đại your first degree dependencies.
Composer require
Khi mình muốn install một package mới mẻ cho tới project của tớ, các bạn sẽ dùng command sau
php composer.phar require packageName
Đây là những options khi install package
--dev: Add packages vĩ đại require-dev.
--dry-run: Simulate the command without actually doing anything.
--prefer-source: Install packages from source when available.
--prefer-dist: Install packages from dist when available.
--no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
--no-update: Disables the automatic update of the dependencies (implies --no-install).
--no-install: Does not lập cập the install step after updating the composer.lock tệp tin.
--no-scripts: Skips execution of scripts defined in composer.json
--update-no-dev: Run the dependency update with the --no-dev option.
--update-with-dependencies (-w): Also update dependencies of the newly required packages, except those that are root requirements.
--update-with-all-dependencies (-W): Also update dependencies of the newly required packages, including those that are root requirements.
--ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
--ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it.
--prefer-stable: Prefer stable versions of dependencies.
--prefer-lowest: Prefer lowest versions of dependencies. Useful for testing minimal versions of requirements, generally used with --prefer-stable.
--sort-packages: Keep packages sorted in composer.json.
--optimize-autoloader (-o): Convert PSR-0/4 autoloading vĩ đại classmap vĩ đại get a faster autoloader. This is recommended especially for production, but can take a bit of time vĩ đại lập cập, so sánh it is currently not done by mặc định.
--classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
--apcu-autoloader: Use APCu vĩ đại cache found/not-found classes.
--apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader.
Composer remove
Để xóa package ngoài project tao dùng command sau:
php composer.phar remove vendor/package vendor/package2
Sau khi xóa nó cũng xóa package name ở nhập composer.lock file
Options:
--dev: Remove packages from require-dev.
--dry-run: Simulate the command without actually doing anything.
--no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
--no-update: Disables the automatic update of the dependencies (implies --no-install).
--no-install: Does not lập cập the install step after updating the composer.lock tệp tin.
--no-scripts: Skips execution of scripts defined in composer.json.
--update-no-dev: Run the dependency update with the --no-dev option.
--update-with-dependencies (-w): Also update dependencies of the removed packages. (Deprecrated, is now mặc định behavior)
--update-with-all-dependencies (-W): Allows all inherited dependencies vĩ đại be updated, including those that are root requirements.
--ignore-platform-reqs: ignore all platform requirements (php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill these. See also the platform config option.
--ignore-platform-req: ignore a specific platform requirement(php, hhvm, lib-* and ext-*) and force the installation even if the local machine does not fulfill it.
--optimize-autoloader (-o): Convert PSR-0/4 autoloading vĩ đại classmap vĩ đại get a faster autoloader. This is recommended especially for production, but can take a bit of time vĩ đại lập cập so sánh it is currently not done by mặc định.
--classmap-authoritative (-a): Autoload classes from the classmap only. Implicitly enables --optimize-autoloader.
--apcu-autoloader: Use APCu vĩ đại cache found/not-found classes.
--apcu-autoloader-prefix: Use a custom prefix for the APCu autoloader cache. Implicitly enables --apcu-autoloader
Composer dump-autoload
Nếu bạn phải update autoloader cho 1 class mới mẻ nhập classmap package bạn cũng có thể xử dụng
Xem thêm: vanished là gì
composer dump-autoload
Bình luận