温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-31 03:04:02 来源:网络 阅读:4285 作者:rufei_555 栏目:web开发

从官网下载composer

https://getcomposer.org/

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

下载好了后, 进行安装.

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

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

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

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

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


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

下载composer.phar

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

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

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

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

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

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

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

下面就来用一下composer.

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

由于装了  shell menu,

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

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


现在遵循最传统的方式使用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

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


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

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

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

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

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

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对象.

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

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

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

end...


(有关composer更多的内容, 访问: http://www.phpcomposer.com/)



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI