用composer装oauth2-server-phpv0.9(bshaffer)
从官网下载composer
威远网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联建站2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站。
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
写入如下内容:
$dsn, 'username' => $username, 'password' => $password)); print_r($storage);
最后打印出了 $storage对象.
那么可见包里面的文件已经被自动加载. 只需要 require 'vendor/autoload.php';
包里面的所有文件都可以使用了.
end...
(有关composer更多的内容, 访问: http://www.phpcomposer.com/)
文章标题:用composer装oauth2-server-phpv0.9(bshaffer)
URL地址:http://myzitong.com/article/ieisge.html