php oauth2 server,用composer装oauth2-server-php v0.9(bshaffer)

从官网下载composer

composer是跨平台的, 这里只介绍windows使用composer

下载好了后, 进行安装.

25dbbe00855917bea333169726ffb4ff.png

可以选择 "Install Shell Menus", 这将会在右键菜单里面增加composer的快捷入口.

20749391c57592f3455d8239d25e2b11.png

composer会自动找到php.exe的位置. 也可以自定义php的位置.

d574a2211a115bd3b18fee8763af5f4e.png

994c0ab3c461c57039f537c20649f388.png

下载composer.phar

f3a881429bdea55ab8b7679b4d7189ac.png

该死的"墙", 连接上×××.

3d36d2f4cee3470cf4256015d6f12e58.png

我的php 5.3.3 确实够老的. 点击next.

582a5c93ca315ef1a2261eb1baa9951d.png

成功, composer设置了 path 环境变量. 所以可以在command line的任意位置使用composer命令了.

90c5314a19ceb6af9193654275dae276.png

下面就来用一下composer.

新建一个文件夹, C:\clearvale\elgg\ztest\oauth_server_bshaffer

由于装了  shell menu,

所以直接在文件夹上右键选择 Use Composer here

6353c46bca057291696d784f50911008.png

现在遵循最传统的方式使用composer, 新建oauth_server_bshaffer/composer.json 文件.

这里用 bshaffer的oauth2 server来演示. 在composer.php里面写入如下内容.

{

"require": {

"bshaffer/oauth2-server-php": "~0.9"

}

}

<<<<<<<<<<<<<<<<<<<<

这里记录一下, 之前写入的是

{

"require": {

"bshaffer/oauth2-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/oauth2-server-php dev-develop -> satisfiable by bshaffer/oauth2-server-php[dev-develop].

- bshaffer/oauth2-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/oauth2-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/oauth2-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/oauth2-server-php ~1.7 -> satisfiable by bshaffer/oauth2-server-php[v1.7.0, v1.7.1].

大意是说: 1.7这个版本的最低php环境是 php >= 5.3.9

那么到底有多少个版本, 哪个版本支持php5.3.3 呢?

可以访问composer的packagelist官网.

f8efa16dc93403cdaa33e6f757eac7c0.png

正好, 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/oauth2-server-php (v0.9)

Downloading: 100%

Writing lock file

Generating autoload files

成功了. composer已经成功安装了oauth2-server-php (v0.9),

查看安装后的文件目录.

0d0fb83897a6045f2730b2b3188b38ea.png

composer.lock用于锁定所有包的版本.  安装的时候会检查composer.lock文件的存在.

composer.lock和composer.json一起控制项目的版本.

比如现在已经装完了包, 再次运行composer install, 会显示 Nothing to install or update.

a0fccfefd030186950f92adad2f0b0ad.png

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_oauth2_db;host=localhost";

$username = "root";

$password = "root";

$storage = new OAuth2_Storage_Pdo(array('dsn' => $dsn, 'username' => $username, 'password' => $password));

print_r($storage);

最后打印出了 $storage对象.

spacer.giff03d8c36708a8dc81704812b1736d8c7.png

那么可见包里面的文件已经被自动加载. 只需要 require 'vendor/autoload.php';

包里面的所有文件都可以使用了.

end...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值