您好,登錄后才能下訂單哦!
從官網下載composer
https://getcomposer.org/
composer是跨平臺的, 這里只介紹windows使用composer
下載好了后, 進行安裝.
可以選擇 "Install Shell Menus", 這將會在右鍵菜單里面增加composer的快捷入口.
composer會自動找到php.exe的位置. 也可以自定義php的位置.
下載composer.phar
該死的"墻", 連接上×××.
我的php 5.3.3 確實夠老的. 點擊next.
成功, composer設置了 path 環境變量. 所以可以在command line的任意位置使用composer命令了.
下面就來用一下composer.
新建一個文件夾, C:\clearvale\elgg\ztest\oauth_server_bshaffer
由于裝了 shell menu,
所以直接在文件夾上右鍵選擇 Use Composer here
現在遵循最傳統的方式使用composer, 新建oauth_server_bshaffer/composer.json 文件.
這里用 bshaffer的oauth3 server來演示. 在composer.php里面寫入如下內容.
{
"require": {
"bshaffer/oauth3-server-php": "~0.9"
}
}
<<<<<<<<<<<<<<<<<<<<
這里記錄一下, 之前寫入的是
{
"require": {
"bshaffer/oauth3-server-php": "~1.7",
}
}
首先多了個 , 號
導致composer報錯.
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]
去掉逗號后, 又報如下錯誤:
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].
大意是說: 1.7這個版本的最低php環境是 php >= 5.3.9
那么到底有多少個版本, 哪個版本支持php5.3.3 呢?
可以訪問composer的packagelist官網.
https://packagist.org/packages/bshaffer/oauth3-server-php#v0.9
正好, bshaffer也推薦v0.9為stable release.
>>>>>>>>>>>>>>>>>>>>>>>>>
所以就裝 v0.9, 繼續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已經成功安裝了oauth3-server-php (v0.9),
查看安裝后的文件目錄.
composer.lock用于鎖定所有包的版本. 安裝的時候會檢查composer.lock文件的存在.
composer.lock和composer.json一起控制項目的版本.
比如現在已經裝完了包, 再次運行composer install, 會顯示 Nothing to install or update.
oauth_server_php v0.9包已經安裝完畢.
下面測試一下 auto_load
新建: C:\clearvale\elgg\ztest\oauth_server_bshaffer\test.php
寫入如下內容:
<?php require 'vendor/autoload.php'; //token controller $dsn = "mysql:my_oauth3_db;host=localhost"; $username = "root"; $password = "root"; $storage = new OAuth3_Storage_Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password)); print_r($storage);
最后打印出了 $storage對象.
那么可見包里面的文件已經被自動加載. 只需要 require 'vendor/autoload.php';
包里面的所有文件都可以使用了.
end...
(有關composer更多的內容, 訪問: http://www.phpcomposer.com/)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。