Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:composer是工作最常用的工具之一
序号 | 命令 | 作用 |
---|---|---|
1 | composer install |
添加依赖信息到composer.json |
2 | composer update |
更新composer.json这个文件,那么composer.lock里的版本就重写了 |
3 | composer require |
使用composer require components/jquery来生成vendor文件,components文件,composer文件,autoload.php文件,还生成了composer.lock,用来锁定版本号 |
4 | composer create-project |
用来建目录,项目 |
在VSCode里安装
终端-新终端-pwd查看当前路径,是否在当前项目
cd 0806
pwd
php -v拿到当前php版本
clear清屏
https://pkg.phpcomposer.com/#how-to-install-composer
CA证书安装
https://curl.haxx.se/docs/caextract.html
php.ini里查找:openssl.cafile=
openssl.cafile=D:/phpstudy_pro/cacert.pem
https://pkg.phpcomposer.com/#how-to-install-composer
复制以下指令进行下载:
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
得到一个安装器:composer-setup.php
下载安装
php composer-setup.php
得到composer.phar,它是多个php文件的压缩文档
下面这条命令是删除composer-setup.php
php -r "unlink('composer-setup.php');"
查看composer.phar版本号:
php composer.phar -v
Composer version 1.10.10
批处理composer.bat
把以下指令放入
@php "%~dp0composer.phar" %*
执行以下测试
composer init
中国全量镜像,用来加速
composer config -g repo.packagist composer https://packagist.phpcomposer.com
升级版本
composer selfupdate
创建composer.json
Package name (<vendor>/<name>) [melinda/0806]: phpcn/melinda
Description []: test
Author [, n to skip]: melinda <melinda@php.cn>
Minimum Stability []: 这里是一些版权信息
Package Type (e.g. library, project, metapackage, composer-plugin) []: 这里是一些插件和依赖
License []: MIT(问项目基于什么样的协议)
Define your dependencies.
Would you like to define your dependencies (require) interactively [yes]? bootstrap(安装什么依赖)
Please answer yes, y, no, or n.
Would you like to define your dependencies (require) interactively [yes]? no
Would you like to define your dev dependencies (require-dev) interactively [yes]? no
{
"name": "phpcn/melinda",
"description": "test",
"license": "MIT",
"authors": [
{
"name": "melinda",
"email": "melinda@php.cn"
}
],
"require": {}
}
Do you confirm generation [yes]?yes
然后就生成了composer.json文件,以下是内容,这种是交互方式,一般不用
{
"name": "phpcn/melinda",
"description": "test",
"license": "MIT",
"authors": [
{
"name": "melinda",
"email": "melinda@php.cn"
}
],
"require": {}
}
-----------------------------------------------------------------
https://packagist.org/
搜索jquery
components/jquery
composer.json文件手动创建一个,以下是内容
{
"name": "phpcn/demo",
"require": {
"components/jquery": "3.4.*"
}
}
-----------------------------------------------------------------------
新建终端,命令:composer install添加依赖信息
生成vendor文件,components文件,composer文件
autoload.php很重要
还生成了composer.lock,用来锁定版本号,同样的环境开发工作
如果后面composer升级,就要把composer.lock删除后,再重新安装
还可以用composer update命令来更新composer.json这个文件,那么composer.lock里的版本就重写了
---------------------------------------
把vendor,composer.json,composer.lock都删除
在新终端用下面的命令重新生成被删除的文件
composer require components/jquery
用以下命令强制更新版本号
composer require components/jquery "3.4.1"
建目录为博客
输入指令:
composer create-project laravel/Laravel blogs
版本6
composer create-project --prefer-dist laravel/laravel blog 6.*