從官網(wǎng)下載composer
威遠(yuǎn)網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、APP開(kāi)發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開(kāi)發(fā),運(yùn)營(yíng)維護(hù)。創(chuàng)新互聯(lián)建站2013年至今到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來(lái)保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
https://getcomposer.org/
composer是跨平臺(tái)的, 這里只介紹windows使用composer
下載好了后, 進(jìn)行安裝.
可以選擇 "Install Shell Menus", 這將會(huì)在右鍵菜單里面增加composer的快捷入口.
composer會(huì)自動(dòng)找到php.exe的位置. 也可以自定義php的位置.
下載composer.phar
該死的"墻", 連接上×××.
我的php 5.3.3 確實(shí)夠老的. 點(diǎn)擊next.
成功, composer設(shè)置了 path 環(huán)境變量. 所以可以在command line的任意位置使用composer命令了.
下面就來(lái)用一下composer.
新建一個(gè)文件夾, C:\clearvale\elgg\ztest\oauth_server_bshaffer
由于裝了 shell menu,
所以直接在文件夾上右鍵選擇 Use Composer here
現(xiàn)在遵循最傳統(tǒng)的方式使用composer, 新建oauth_server_bshaffer/composer.json 文件.
這里用 bshaffer的oauth3 server來(lái)演示. 在composer.php里面寫入如下內(nèi)容.
{
"require": {
"bshaffer/oauth3-server-php": "~0.9"
}
}
<<<<<<<<<<<<<<<<<<<<
這里記錄一下, 之前寫入的是
{
"require": {
"bshaffer/oauth3-server-php": "~1.7",
}
}
首先多了個(gè) , 號(hào)
導(dǎo)致composer報(bào)錯(cuò).
C:\clearvale\elgg\ztest\oauth_server_bshaffer>composer install
[Seld\JsonLint\ParsingException]
"./composer.json" does not contain valid JSON
Parse error on line 3:
}
---------------------^
Expected: 'STRING' - It appears you have an extra trailing comma
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-plugins] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--n
o-progress] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [--ignore-platform-reqs] [packages1] ... [packagesN]
去掉逗號(hào)后, 又報(bào)如下錯(cuò)誤:
C:\clearvale\elgg\ztest\oauth_server_bshaffer>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for bshaffer/oauth3-server-php dev-develop -> satisfiable by bshaffer/oauth3-server-php[dev-develop].
- bshaffer/oauth3-server-php dev-develop requires php >=5.3.9 -> your PHP version (5.3.3) or "config.platform.php" value does not satisfy that req
uirement.
C:\clearvale\elgg\ztest\oauth_server_bshaffer>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- bshaffer/oauth3-server-php v1.7.1 requires php >=5.3.9 -> your PHP version (5.3.3) or "config.platform.php" value does not satisfy that requirem
ent.
- bshaffer/oauth3-server-php v1.7.0 requires php >=5.3.9 -> your PHP version (5.3.3) or "config.platform.php" value does not satisfy that requirem
ent.
- Installation request for bshaffer/oauth3-server-php ~1.7 -> satisfiable by bshaffer/oauth3-server-php[v1.7.0, v1.7.1].
大意是說(shuō): 1.7這個(gè)版本的最低php環(huán)境是 php >= 5.3.9
那么到底有多少個(gè)版本, 哪個(gè)版本支持php5.3.3 呢?
可以訪問(wèn)composer的packagelist官網(wǎng).
https://packagist.org/packages/bshaffer/oauth3-server-php#v0.9
正好, bshaffer也推薦v0.9為stable release.
>>>>>>>>>>>>>>>>>>>>>>>>>
所以就裝 v0.9, 繼續(xù)composer install
C:\clearvale\elgg\ztest\oauth_server_bshaffer>composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing bshaffer/oauth3-server-php (v0.9)
Downloading: 100%
Writing lock file
Generating autoload files
成功了. composer已經(jīng)成功安裝了oauth3-server-php (v0.9),
查看安裝后的文件目錄.
composer.lock用于鎖定所有包的版本. 安裝的時(shí)候會(huì)檢查composer.lock文件的存在.
composer.lock和composer.json一起控制項(xiàng)目的版本.
比如現(xiàn)在已經(jīng)裝完了包, 再次運(yùn)行composer install, 會(huì)顯示 Nothing to install or update.
oauth_server_php v0.9包已經(jīng)安裝完畢.
下面測(cè)試一下 auto_load
新建: C:\clearvale\elgg\ztest\oauth_server_bshaffer\test.php
寫入如下內(nèi)容:
$dsn, 'username' => $username, 'password' => $password)); print_r($storage);
最后打印出了 $storage對(duì)象.
那么可見(jiàn)包里面的文件已經(jīng)被自動(dòng)加載. 只需要 require 'vendor/autoload.php';
包里面的所有文件都可以使用了.
end...
(有關(guān)composer更多的內(nèi)容, 訪問(wèn): http://www.phpcomposer.com/)