附录*Composer
注意:Composer 不是一个包管理器。是的,它涉及 "packages" 和 "libraries",但它在每个项目的基础上进行管理,在你项目的某个目录中(例如
vendor
)进行安装。默认情况下它不会在全局安装任何东西。因此,这仅仅是一个依赖管理。
安装
局部安装(当前项目安装):
curl -sS https://getcomposer.org/installer | php
使用命令:
php composer.phar install
全局安装:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
使用命令:
composer install
配置中国镜像
查看当前的镜像地址:
$ composer config -g repo.packagist
-----------------------------
{"type":"composer","url":"https?:\/\/packagist.org","allow_ssl_downgrade":true} #当前为国外的源
启动本镜像服务,一下两种配置
系统全局配置
单个项目配置
使用
composer初始化
$ composer init
# Package name : cms/test
# Description : test composer
# Author : revin
# Minimum Stability : 忽略,直接确定
# Package Type : project
剩下全部确定
composer.json
{
"name": "cms/test",
"description": "test composer",
"type": "project",
"authors": [
{
"name": "revin",
"email": "revin.bian@vidaxl.com"
}
],
"require": {}
}
搜索依赖包
$ composer search monolog
------------------------------------------
monolog/monolog Sends your logs to files, sockets, inboxes, databases and various web services
kdyby/monolog Integration of Monolog into Nette Framework
adeira/monolog
stackify/monolog Stackify logs and errors for Monolog
thinframe/monolog Monolog Application
flowpack/monolog Monolog integration for Flow
cakephp/monolog CakePHP Monolog Plugin
mrtnzlml/monolog
mero/yii2-monolog The Monolog integration for the Yii framework.
amberovsky/zf2-monolog Monolog integration to Zend Framework 2
symfony/monolog-bundle Symfony MonologBundle
symfony/monolog-bridge Symfony Monolog Bridge
theorchard/monolog-cascade Monolog extension to configure multiple loggers in the blink of an eye and access them from anywhere
kamisama/monolog-init Very basic and light Dependency Injector Container for Monolog
logentries/logentries-monolog-handler A handler for Monolog that sends messages to Logentries.com.
则monolog/monolog 则为库名称
查看库的详细信息
$ composer show monolog/monolog
------------------------------------------
name : monolog/monolog
descrip. : Sends your logs to files, sockets, inboxes, databases and various web services
keywords : log, logging, psr-3
versions : dev-master, 2.0.x-dev, 1.x-dev, 1.22.1, 1.22.0, 1.21.0, 1.20.0, 1.19.0, 1.18.2, 1.18.1, 1.18.0, 1.17.2, 1.17.1, 1.17.0, 1.16.0, 1.15.0, 1.14.0, 1.13.1, 1.13.0, 1.12.0, 1.11.0, 1.10.0, 1.9.1, 1.9.0, 1.8.0, 1.7.0, 1.6.0, 1.5.0, 1.4.1, 1.4.0, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.2, 1.0.1, 1.0.0, 1.0.0-RC1
type : library
license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
source : [git] https://github.com/Seldaek/monolog.git f8248dba5db8f4e60ec6a505bf43146c6c0466f9
dist : [zip] https://api.github.com/repos/Seldaek/monolog/zipball/f8248dba5db8f4e60ec6a505bf43146c6c0466f9 f8248dba5db8f4e60ec6a505bf43146c6c0466f9
names : monolog/monolog, psr/log-implementation
autoload
psr-4
Monolog\ => src/Monolog
requires
php ^7.0
psr/log ^1.0.1
requires (dev)
doctrine/couchdb ~1.0@dev
ruflin/elastica >=0.90 <3.0
php-console/php-console ^3.1.3
php-amqplib/php-amqplib ~2.4
sentry/sentry ^0.13
graylog2/gelf-php ^1.4.2
jakub-onderka/php-parallel-lint ^0.9
predis/predis ^1.1
phpspec/prophecy ^1.6.1
aws/aws-sdk-php ^2.4.9 || ^3.0
phpunit/phpunit ^5.7
swiftmailer/swiftmailer ^5.3|^6.0
suggests
aws/aws-sdk-php Allow sending log messages to AWS services like DynamoDB
doctrine/couchdb Allow sending log messages to a CouchDB server
ext-amqp Allow sending log messages to an AMQP server (1.0+ required)
ext-mongodb Allow sending log messages to a MongoDB server (via driver)
graylog2/gelf-php Allow sending log messages to a GrayLog2 server
mongodb/mongodb Allow sending log messages to a MongoDB server (via library)
php-amqplib/php-amqplib Allow sending log messages to an AMQP server using php-amqplib
php-console/php-console Allow sending log messages to Google Chrome
rollbar/rollbar Allow sending log messages to Rollbar
ruflin/elastica Allow sending log messages to an Elastic Search server
sentry/sentry Allow sending log messages to a Sentry server
provides
psr/log-implementation 1.0.0
安装:
声明方式安装:
修改
composer.json
文件:
{
"name": "cms/test",
"description": "test composer",
"type": "project",
"authors": [
{
"name": "revin",
"email": "revin.bian@vidaxl.com"
}
],
"require": {
"monolog/monolog": "1.21.*"
}
}
执行命令
$ composer install
require 命令安装
例子:composer require symfony/http-foundation
此时的composer.json
{
"name": "cms/test",
"description": "test composer",
"type": "project",
"authors": [
{
"name": "revin",
"email": "revin.bian@vidaxl.com"
}
],
"require": {
"monolog/monolog": "1.21.*",
"symfony/http-foundation": "^3.3"
}
}
并没有更新之前安装的版本
删除包
当删除了"monolog/monolog": "1.21.*"
包。则只需要删除此行。执行composer update 命令。
执行
composer update
时,不会影响到其他的包版本。
Last updated