phizshop的独立GatewayWorker服务
commit
4c8a017a70
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of workerman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* 用于检测业务代码死循环或者长时间阻塞等问题
|
||||
* 如果发现业务卡死,可以将下面declare打开(去掉//注释),并执行php start.php reload
|
||||
* 然后观察一段时间workerman.log看是否有process_timeout异常
|
||||
*/
|
||||
|
||||
//declare(ticks=1);
|
||||
|
||||
use \GatewayWorker\Lib\Gateway;
|
||||
|
||||
/**
|
||||
* 主逻辑
|
||||
* 主要是处理 onConnect onMessage onClose 三个方法
|
||||
* onConnect 和 onClose 如果不需要可以不用实现并删除
|
||||
*/
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* 当客户端连接时触发
|
||||
* 如果业务不需此回调可以删除onConnect
|
||||
*
|
||||
* @param int $client_id 连接id
|
||||
*/
|
||||
/*public static function onConnect($client_id)
|
||||
{
|
||||
// 向当前client_id发送数据
|
||||
Gateway::sendToClient($client_id, "Hello $client_id\r\n");
|
||||
// 向所有人发送
|
||||
Gateway::sendToAll("$client_id 在座");
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 当客户端发来消息时触发
|
||||
* @param int $client_id 连接id
|
||||
* @param mixed $message 具体消息
|
||||
*/
|
||||
public static function onMessage($client_id, $message)
|
||||
{
|
||||
// 向所有人发送
|
||||
$message_data = json_decode($message, true);
|
||||
if (!$message_data) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*Gateway::sendToAll("$client_id 爱你");*/
|
||||
//判断类型传输对应的值
|
||||
|
||||
switch ($message_data['type']) {
|
||||
//心跳
|
||||
case 'pong':
|
||||
return;
|
||||
case 'login':
|
||||
//判断是否存在类型 0是支付时间 1是排队事件 2是app推送小程序出票信息
|
||||
if (!isset($message_data['type_id'])) {
|
||||
throw new \Exception("\$message_data['type_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']} \$message:$message");
|
||||
}
|
||||
switch ($message_data['type_id']) {
|
||||
case 0:
|
||||
//执行支付成功的推送
|
||||
file_put_contents("./ceshi.txt", json_encode($message_data));
|
||||
$uid = $message_data['uid'];
|
||||
Gateway::bindUid($client_id, $uid);
|
||||
break;
|
||||
case 1:
|
||||
//执行用户的核销完成事件
|
||||
$store_id = $message_data['store_id'];
|
||||
//这里绑定uid 处理之后的业务流程
|
||||
Gateway::joinGroup($client_id, $store_id);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'say':
|
||||
|
||||
//发言 以及及时推送消息
|
||||
switch ($message_data['type_id']) {
|
||||
case 0:
|
||||
//执行支付成功的推送
|
||||
$uid = $message_data['uid'];
|
||||
$message = $message_data['content'];
|
||||
$new_message['type'] = "retail1";
|
||||
$new_message['content'] = $message;
|
||||
$new_message['type_id'] = 0;
|
||||
return Gateway::sendToUid($uid, json_encode($new_message));
|
||||
default:
|
||||
$uid = $message_data['uid'];
|
||||
$message = $message_data['content'];
|
||||
$new_message['type'] = "say";
|
||||
$new_message['content'] = $message;
|
||||
$new_message['type_id'] = $message_data['type_id'];
|
||||
return Gateway::sendToUid($uid, json_encode($new_message));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当用户断开连接时触发
|
||||
* @param int $client_id 连接id
|
||||
*/
|
||||
public static function onClose($client_id)
|
||||
{
|
||||
// 向所有人发送
|
||||
// GateWay::sendToAll("$client_id logout\r\n");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,459 @@
|
|||
/*!
|
||||
* Bootstrap v3.0.1 by @fat and @mdo
|
||||
* Copyright 2013 Twitter, Inc.
|
||||
* Licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Designed and built with all the love in the world by @mdo and @fat.
|
||||
*/
|
||||
|
||||
.btn-default,
|
||||
.btn-primary,
|
||||
.btn-success,
|
||||
.btn-info,
|
||||
.btn-warning,
|
||||
.btn-danger {
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.2);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.btn-default:active,
|
||||
.btn-primary:active,
|
||||
.btn-success:active,
|
||||
.btn-info:active,
|
||||
.btn-warning:active,
|
||||
.btn-danger:active,
|
||||
.btn-default.active,
|
||||
.btn-primary.active,
|
||||
.btn-success.active,
|
||||
.btn-info.active,
|
||||
.btn-warning.active,
|
||||
.btn-danger.active {
|
||||
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
|
||||
}
|
||||
|
||||
.btn:active,
|
||||
.btn.active {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
.btn-default {
|
||||
text-shadow: 0 1px 0 #fff;
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#ffffff), to(#e0e0e0));
|
||||
background-image: -webkit-linear-gradient(top, #ffffff 0%, #e0e0e0 100%);
|
||||
background-image: -moz-linear-gradient(top, #ffffff 0%, #e0e0e0 100%);
|
||||
background-image: linear-gradient(to bottom, #ffffff 0%, #e0e0e0 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #dbdbdb;
|
||||
border-color: #ccc;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe0e0e0', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-default:hover,
|
||||
.btn-default:focus {
|
||||
background-color: #e0e0e0;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-default:active,
|
||||
.btn-default.active {
|
||||
background-color: #e0e0e0;
|
||||
border-color: #dbdbdb;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#428bca), to(#2d6ca2));
|
||||
background-image: -webkit-linear-gradient(top, #428bca 0%, #2d6ca2 100%);
|
||||
background-image: -moz-linear-gradient(top, #428bca 0%, #2d6ca2 100%);
|
||||
background-image: linear-gradient(to bottom, #428bca 0%, #2d6ca2 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #2b669a;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff2d6ca2', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-primary:hover,
|
||||
.btn-primary:focus {
|
||||
background-color: #2d6ca2;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-primary:active,
|
||||
.btn-primary.active {
|
||||
background-color: #2d6ca2;
|
||||
border-color: #2b669a;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#5cb85c), to(#419641));
|
||||
background-image: -webkit-linear-gradient(top, #5cb85c 0%, #419641 100%);
|
||||
background-image: -moz-linear-gradient(top, #5cb85c 0%, #419641 100%);
|
||||
background-image: linear-gradient(to bottom, #5cb85c 0%, #419641 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #3e8f3e;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff419641', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-success:hover,
|
||||
.btn-success:focus {
|
||||
background-color: #419641;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-success:active,
|
||||
.btn-success.active {
|
||||
background-color: #419641;
|
||||
border-color: #3e8f3e;
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f0ad4e), to(#eb9316));
|
||||
background-image: -webkit-linear-gradient(top, #f0ad4e 0%, #eb9316 100%);
|
||||
background-image: -moz-linear-gradient(top, #f0ad4e 0%, #eb9316 100%);
|
||||
background-image: linear-gradient(to bottom, #f0ad4e 0%, #eb9316 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #e38d13;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffeb9316', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-warning:hover,
|
||||
.btn-warning:focus {
|
||||
background-color: #eb9316;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-warning:active,
|
||||
.btn-warning.active {
|
||||
background-color: #eb9316;
|
||||
border-color: #e38d13;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#d9534f), to(#c12e2a));
|
||||
background-image: -webkit-linear-gradient(top, #d9534f 0%, #c12e2a 100%);
|
||||
background-image: -moz-linear-gradient(top, #d9534f 0%, #c12e2a 100%);
|
||||
background-image: linear-gradient(to bottom, #d9534f 0%, #c12e2a 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #b92c28;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc12e2a', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-danger:hover,
|
||||
.btn-danger:focus {
|
||||
background-color: #c12e2a;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-danger:active,
|
||||
.btn-danger.active {
|
||||
background-color: #c12e2a;
|
||||
border-color: #b92c28;
|
||||
}
|
||||
|
||||
.btn-info {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#5bc0de), to(#2aabd2));
|
||||
background-image: -webkit-linear-gradient(top, #5bc0de 0%, #2aabd2 100%);
|
||||
background-image: -moz-linear-gradient(top, #5bc0de 0%, #2aabd2 100%);
|
||||
background-image: linear-gradient(to bottom, #5bc0de 0%, #2aabd2 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #28a4c9;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff2aabd2', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.btn-info:hover,
|
||||
.btn-info:focus {
|
||||
background-color: #2aabd2;
|
||||
background-position: 0 -15px;
|
||||
}
|
||||
|
||||
.btn-info:active,
|
||||
.btn-info.active {
|
||||
background-color: #2aabd2;
|
||||
border-color: #28a4c9;
|
||||
}
|
||||
|
||||
.thumbnail,
|
||||
.img-thumbnail {
|
||||
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.075);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.dropdown-menu > li > a:hover,
|
||||
.dropdown-menu > li > a:focus {
|
||||
background-color: #e8e8e8;
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f5f5f5), to(#e8e8e8));
|
||||
background-image: -webkit-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-image: -moz-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-image: linear-gradient(to bottom, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);
|
||||
}
|
||||
|
||||
.dropdown-menu > .active > a,
|
||||
.dropdown-menu > .active > a:hover,
|
||||
.dropdown-menu > .active > a:focus {
|
||||
background-color: #357ebd;
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#428bca), to(#357ebd));
|
||||
background-image: -webkit-linear-gradient(top, #428bca 0%, #357ebd 100%);
|
||||
background-image: -moz-linear-gradient(top, #428bca 0%, #357ebd 100%);
|
||||
background-image: linear-gradient(to bottom, #428bca 0%, #357ebd 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff357ebd', GradientType=0);
|
||||
}
|
||||
|
||||
.navbar-default {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#ffffff), to(#f8f8f8));
|
||||
background-image: -webkit-linear-gradient(top, #ffffff 0%, #f8f8f8 100%);
|
||||
background-image: -moz-linear-gradient(top, #ffffff 0%, #f8f8f8 100%);
|
||||
background-image: linear-gradient(to bottom, #ffffff 0%, #f8f8f8 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-radius: 4px;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#fff8f8f8', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 5px rgba(0, 0, 0, 0.075);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), 0 1px 5px rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.navbar-default .navbar-nav > .active > a {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#ebebeb), to(#f3f3f3));
|
||||
background-image: -webkit-linear-gradient(top, #ebebeb 0%, #f3f3f3 100%);
|
||||
background-image: -moz-linear-gradient(top, #ebebeb 0%, #f3f3f3 100%);
|
||||
background-image: linear-gradient(to bottom, #ebebeb 0%, #f3f3f3 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff3f3f3', GradientType=0);
|
||||
-webkit-box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.075);
|
||||
box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.navbar-brand,
|
||||
.navbar-nav > li > a {
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
|
||||
}
|
||||
|
||||
.navbar-inverse {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#3c3c3c), to(#222222));
|
||||
background-image: -webkit-linear-gradient(top, #3c3c3c 0%, #222222 100%);
|
||||
background-image: -moz-linear-gradient(top, #3c3c3c 0%, #222222 100%);
|
||||
background-image: linear-gradient(to bottom, #3c3c3c 0%, #222222 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff3c3c3c', endColorstr='#ff222222', GradientType=0);
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||
}
|
||||
|
||||
.navbar-inverse .navbar-nav > .active > a {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#222222), to(#282828));
|
||||
background-image: -webkit-linear-gradient(top, #222222 0%, #282828 100%);
|
||||
background-image: -moz-linear-gradient(top, #222222 0%, #282828 100%);
|
||||
background-image: linear-gradient(to bottom, #222222 0%, #282828 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff222222', endColorstr='#ff282828', GradientType=0);
|
||||
-webkit-box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.25);
|
||||
box-shadow: inset 0 3px 9px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.navbar-inverse .navbar-brand,
|
||||
.navbar-inverse .navbar-nav > li > a {
|
||||
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.navbar-static-top,
|
||||
.navbar-fixed-top,
|
||||
.navbar-fixed-bottom {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.alert {
|
||||
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
-webkit-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#dff0d8), to(#c8e5bc));
|
||||
background-image: -webkit-linear-gradient(top, #dff0d8 0%, #c8e5bc 100%);
|
||||
background-image: -moz-linear-gradient(top, #dff0d8 0%, #c8e5bc 100%);
|
||||
background-image: linear-gradient(to bottom, #dff0d8 0%, #c8e5bc 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #b2dba1;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffc8e5bc', GradientType=0);
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#d9edf7), to(#b9def0));
|
||||
background-image: -webkit-linear-gradient(top, #d9edf7 0%, #b9def0 100%);
|
||||
background-image: -moz-linear-gradient(top, #d9edf7 0%, #b9def0 100%);
|
||||
background-image: linear-gradient(to bottom, #d9edf7 0%, #b9def0 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #9acfea;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffb9def0', GradientType=0);
|
||||
}
|
||||
|
||||
.alert-warning {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#fcf8e3), to(#f8efc0));
|
||||
background-image: -webkit-linear-gradient(top, #fcf8e3 0%, #f8efc0 100%);
|
||||
background-image: -moz-linear-gradient(top, #fcf8e3 0%, #f8efc0 100%);
|
||||
background-image: linear-gradient(to bottom, #fcf8e3 0%, #f8efc0 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #f5e79e;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fff8efc0', GradientType=0);
|
||||
}
|
||||
|
||||
.alert-danger {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f2dede), to(#e7c3c3));
|
||||
background-image: -webkit-linear-gradient(top, #f2dede 0%, #e7c3c3 100%);
|
||||
background-image: -moz-linear-gradient(top, #f2dede 0%, #e7c3c3 100%);
|
||||
background-image: linear-gradient(to bottom, #f2dede 0%, #e7c3c3 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #dca7a7;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffe7c3c3', GradientType=0);
|
||||
}
|
||||
|
||||
.progress {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#ebebeb), to(#f5f5f5));
|
||||
background-image: -webkit-linear-gradient(top, #ebebeb 0%, #f5f5f5 100%);
|
||||
background-image: -moz-linear-gradient(top, #ebebeb 0%, #f5f5f5 100%);
|
||||
background-image: linear-gradient(to bottom, #ebebeb 0%, #f5f5f5 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffebebeb', endColorstr='#fff5f5f5', GradientType=0);
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#428bca), to(#3071a9));
|
||||
background-image: -webkit-linear-gradient(top, #428bca 0%, #3071a9 100%);
|
||||
background-image: -moz-linear-gradient(top, #428bca 0%, #3071a9 100%);
|
||||
background-image: linear-gradient(to bottom, #428bca 0%, #3071a9 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff3071a9', GradientType=0);
|
||||
}
|
||||
|
||||
.progress-bar-success {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#5cb85c), to(#449d44));
|
||||
background-image: -webkit-linear-gradient(top, #5cb85c 0%, #449d44 100%);
|
||||
background-image: -moz-linear-gradient(top, #5cb85c 0%, #449d44 100%);
|
||||
background-image: linear-gradient(to bottom, #5cb85c 0%, #449d44 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5cb85c', endColorstr='#ff449d44', GradientType=0);
|
||||
}
|
||||
|
||||
.progress-bar-info {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#5bc0de), to(#31b0d5));
|
||||
background-image: -webkit-linear-gradient(top, #5bc0de 0%, #31b0d5 100%);
|
||||
background-image: -moz-linear-gradient(top, #5bc0de 0%, #31b0d5 100%);
|
||||
background-image: linear-gradient(to bottom, #5bc0de 0%, #31b0d5 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff5bc0de', endColorstr='#ff31b0d5', GradientType=0);
|
||||
}
|
||||
|
||||
.progress-bar-warning {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f0ad4e), to(#ec971f));
|
||||
background-image: -webkit-linear-gradient(top, #f0ad4e 0%, #ec971f 100%);
|
||||
background-image: -moz-linear-gradient(top, #f0ad4e 0%, #ec971f 100%);
|
||||
background-image: linear-gradient(to bottom, #f0ad4e 0%, #ec971f 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff0ad4e', endColorstr='#ffec971f', GradientType=0);
|
||||
}
|
||||
|
||||
.progress-bar-danger {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#d9534f), to(#c9302c));
|
||||
background-image: -webkit-linear-gradient(top, #d9534f 0%, #c9302c 100%);
|
||||
background-image: -moz-linear-gradient(top, #d9534f 0%, #c9302c 100%);
|
||||
background-image: linear-gradient(to bottom, #d9534f 0%, #c9302c 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9534f', endColorstr='#ffc9302c', GradientType=0);
|
||||
}
|
||||
|
||||
.list-group {
|
||||
border-radius: 4px;
|
||||
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.075);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.075);
|
||||
}
|
||||
|
||||
.list-group-item.active,
|
||||
.list-group-item.active:hover,
|
||||
.list-group-item.active:focus {
|
||||
text-shadow: 0 -1px 0 #3071a9;
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#428bca), to(#3278b3));
|
||||
background-image: -webkit-linear-gradient(top, #428bca 0%, #3278b3 100%);
|
||||
background-image: -moz-linear-gradient(top, #428bca 0%, #3278b3 100%);
|
||||
background-image: linear-gradient(to bottom, #428bca 0%, #3278b3 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #3278b3;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff3278b3', GradientType=0);
|
||||
}
|
||||
|
||||
.panel {
|
||||
-webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.panel-default > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f5f5f5), to(#e8e8e8));
|
||||
background-image: -webkit-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-image: -moz-linear-gradient(top, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-image: linear-gradient(to bottom, #f5f5f5 0%, #e8e8e8 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff5f5f5', endColorstr='#ffe8e8e8', GradientType=0);
|
||||
}
|
||||
|
||||
.panel-primary > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#428bca), to(#357ebd));
|
||||
background-image: -webkit-linear-gradient(top, #428bca 0%, #357ebd 100%);
|
||||
background-image: -moz-linear-gradient(top, #428bca 0%, #357ebd 100%);
|
||||
background-image: linear-gradient(to bottom, #428bca 0%, #357ebd 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff428bca', endColorstr='#ff357ebd', GradientType=0);
|
||||
}
|
||||
|
||||
.panel-success > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#dff0d8), to(#d0e9c6));
|
||||
background-image: -webkit-linear-gradient(top, #dff0d8 0%, #d0e9c6 100%);
|
||||
background-image: -moz-linear-gradient(top, #dff0d8 0%, #d0e9c6 100%);
|
||||
background-image: linear-gradient(to bottom, #dff0d8 0%, #d0e9c6 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffdff0d8', endColorstr='#ffd0e9c6', GradientType=0);
|
||||
}
|
||||
|
||||
.panel-info > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#d9edf7), to(#c4e3f3));
|
||||
background-image: -webkit-linear-gradient(top, #d9edf7 0%, #c4e3f3 100%);
|
||||
background-image: -moz-linear-gradient(top, #d9edf7 0%, #c4e3f3 100%);
|
||||
background-image: linear-gradient(to bottom, #d9edf7 0%, #c4e3f3 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffd9edf7', endColorstr='#ffc4e3f3', GradientType=0);
|
||||
}
|
||||
|
||||
.panel-warning > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#fcf8e3), to(#faf2cc));
|
||||
background-image: -webkit-linear-gradient(top, #fcf8e3 0%, #faf2cc 100%);
|
||||
background-image: -moz-linear-gradient(top, #fcf8e3 0%, #faf2cc 100%);
|
||||
background-image: linear-gradient(to bottom, #fcf8e3 0%, #faf2cc 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fffcf8e3', endColorstr='#fffaf2cc', GradientType=0);
|
||||
}
|
||||
|
||||
.panel-danger > .panel-heading {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#f2dede), to(#ebcccc));
|
||||
background-image: -webkit-linear-gradient(top, #f2dede 0%, #ebcccc 100%);
|
||||
background-image: -moz-linear-gradient(top, #f2dede 0%, #ebcccc 100%);
|
||||
background-image: linear-gradient(to bottom, #f2dede 0%, #ebcccc 100%);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff2dede', endColorstr='#ffebcccc', GradientType=0);
|
||||
}
|
||||
|
||||
.well {
|
||||
background-image: -webkit-gradient(linear, left 0%, left 100%, from(#e8e8e8), to(#f5f5f5));
|
||||
background-image: -webkit-linear-gradient(top, #e8e8e8 0%, #f5f5f5 100%);
|
||||
background-image: -moz-linear-gradient(top, #e8e8e8 0%, #f5f5f5 100%);
|
||||
background-image: linear-gradient(to bottom, #e8e8e8 0%, #f5f5f5 100%);
|
||||
background-repeat: repeat-x;
|
||||
border-color: #dcdcdc;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffe8e8e8', endColorstr='#fff5f5f5', GradientType=0);
|
||||
-webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(255, 255, 255, 0.1);
|
||||
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(255, 255, 255, 0.1);
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,116 @@
|
|||
body
|
||||
{
|
||||
background:#FCFCFC;
|
||||
}
|
||||
.say-btn
|
||||
{
|
||||
text-align:right;
|
||||
margin-top:12px;
|
||||
}
|
||||
|
||||
#dialog
|
||||
{
|
||||
min-height:600px;
|
||||
background:#EEEEEE;
|
||||
}
|
||||
|
||||
.textarea
|
||||
{
|
||||
height:6em;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
#userlist
|
||||
{
|
||||
min-height:600px;
|
||||
background:#EEEEEE;
|
||||
}
|
||||
|
||||
#userlist > li
|
||||
{
|
||||
color:#1372A2;
|
||||
list-style:none;
|
||||
margin-left:12px;
|
||||
}
|
||||
|
||||
#userlist > h4
|
||||
{
|
||||
text-align:center;
|
||||
font-size:14px;
|
||||
font-weight:nold;
|
||||
}
|
||||
|
||||
.words
|
||||
{
|
||||
margin:8px;
|
||||
}
|
||||
|
||||
|
||||
.triangle-isosceles {
|
||||
position:relative;
|
||||
padding:10px;
|
||||
margin:10px 0 15px;
|
||||
color:#000;
|
||||
background:#D3FF93; /* default background for browsers without gradient support */
|
||||
background:-webkit-gradient(linear, 0 0, 0 100%, from(#EFFFD7), to(#D3FF93));
|
||||
background:-moz-linear-gradient(#EFFFD7, #D3FF93);
|
||||
background:-o-linear-gradient(#EFFFD7, #D3FF93);
|
||||
background:linear-gradient(#EFFFD7, #D3FF93);
|
||||
-webkit-border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
border-radius:10px;
|
||||
-moz-box-shadow:1px 1px 2px hsla(0, 0%, 0%, 0.3);
|
||||
-webkit-box-shadow:1px 1px 2px hsla(0, 0%, 0%, 0.3);
|
||||
box-shadow:1px 1px 2px hsla(0, 0%, 0%, 0.3);
|
||||
}
|
||||
|
||||
.triangle-isosceles:hover{
|
||||
top:-2px;
|
||||
left:-2px;
|
||||
-moz-box-shadow:3px 3px 2px hsla(0, 0%, 0%, 0.3);
|
||||
-webkit-box-shadow:3px 3px 2px hsla(0, 0%, 0%, 0.3);
|
||||
box-shadow:3px 3px 2x hsla(0, 0%, 0%, 0.3);
|
||||
}
|
||||
|
||||
.triangle-isosceles.top {
|
||||
background:-webkit-gradient(linear, 0 0, 0 100%, from(#D3FF93), to(#EFFFD7));
|
||||
background:-moz-linear-gradient(#D3FF93, #EFFFD7);
|
||||
background:-o-linear-gradient(#D3FF93, #EFFFD7);
|
||||
background:linear-gradient(#D3FF93, #EFFFD7);
|
||||
}
|
||||
|
||||
.triangle-isosceles:after {
|
||||
content:"";
|
||||
position:absolute;
|
||||
bottom:-9px;
|
||||
left:15px;
|
||||
border-width:9px 21px 0;
|
||||
border-style:solid;
|
||||
border-color:#D3FF93 transparent;
|
||||
display:block;
|
||||
width:0;
|
||||
}
|
||||
.triangle-isosceles.top:after {
|
||||
top:-9px;
|
||||
left:15px;
|
||||
bottom:auto;
|
||||
border-width:0 9px 9px;
|
||||
border-color:#D3FF93 transparent;
|
||||
}
|
||||
|
||||
.user_icon
|
||||
{
|
||||
float:left;border:1px solid #DDDDDD;padding:2px;margin:0 5px 0 5px;
|
||||
}
|
||||
|
||||
.cp
|
||||
{
|
||||
color:#888888;
|
||||
text-align:center;
|
||||
font-size:11px;
|
||||
}
|
||||
|
||||
.thumbnail
|
||||
{
|
||||
border:1px solid #CCCCCC;
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,159 @@
|
|||
<html><head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>workerman-chat PHP聊天室 Websocket(HTLM5/Flash)+PHP多进程socket实时推送技术</title>
|
||||
<script type="text/javascript">
|
||||
//WebSocket = null;
|
||||
</script>
|
||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/css/style.css" rel="stylesheet">
|
||||
<!-- Include these three JS files: -->
|
||||
<script type="text/javascript" src="/js/swfobject.js"></script>
|
||||
<script type="text/javascript" src="/js/web_socket.js"></script>
|
||||
<script type="text/javascript" src="/js/jquery.min.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
if (typeof console == "undefined") { this.console = { log: function (msg) { } };}
|
||||
// 如果浏览器不支持websocket,会使用这个flash自动模拟websocket协议,此过程对开发者透明
|
||||
WEB_SOCKET_SWF_LOCATION = "/swf/WebSocketMain.swf";
|
||||
// 开启flash的websocket debug
|
||||
WEB_SOCKET_DEBUG = true;
|
||||
|
||||
var ws, name, client_list={};
|
||||
|
||||
// 连接服务端
|
||||
function connect() {
|
||||
// 创建websocket
|
||||
ws = new WebSocket("wss://"+document.domain+":7272");
|
||||
// 当socket连接打开时,输入用户名
|
||||
ws.onopen = onopen;
|
||||
// 当有消息时根据消息类型显示不同信息
|
||||
ws.onmessage = onmessage;
|
||||
ws.onclose = function() {
|
||||
console.log("连接关闭,定时重连");
|
||||
connect();
|
||||
};
|
||||
ws.onerror = function() {
|
||||
console.log("出现错误");
|
||||
};
|
||||
}
|
||||
|
||||
// 连接建立时发送登录信息
|
||||
function onopen()
|
||||
{
|
||||
if(!name)
|
||||
{
|
||||
show_prompt();
|
||||
}
|
||||
// 登录
|
||||
var login_data = '{"type":"login","uid":100,"type_id":1}';
|
||||
console.log("websocket 登录成功,发送登录数据:"+login_data);
|
||||
ws.send(login_data);
|
||||
|
||||
var login_data = '{"type":"say","uid":100,"type_id":1,"content":"还有好几位"}';
|
||||
console.log("websocket 发送成功,发送登录数据:"+login_data);
|
||||
ws.send(login_data);
|
||||
}
|
||||
|
||||
// 服务端发来消息时
|
||||
function onmessage(e)
|
||||
{
|
||||
console.log(e.data);
|
||||
var data = eval("("+e.data+")");
|
||||
switch(data['type']){
|
||||
// 服务端ping客户端
|
||||
case 'ping':
|
||||
ws.send('{"type":"pong"}');
|
||||
break;;
|
||||
// 登录 更新用户列表
|
||||
case 'login':
|
||||
//{"type":"login","client_id":xxx,"client_name":"xxx","client_list":"[...]","time":"xxx"}
|
||||
say(data['client_id'], data['client_name'], data['client_name'] + ' 加入了聊天室', data['time']);
|
||||
// 发言
|
||||
case 'say':
|
||||
//{"type":"say","from_client_id":xxx,"to_client_id":"all/client_id","content":"xxx","time":"xxx"}
|
||||
console.log(data);
|
||||
say(data['from_client_id'], data['from_client_name'], data['content'], data['time']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 输入姓名
|
||||
function show_prompt(){
|
||||
name = prompt('输入你的名字:', '');
|
||||
if(!name || name=='null'){
|
||||
name = '游客';
|
||||
}
|
||||
}
|
||||
|
||||
// 提交对话
|
||||
function onSubmit() {
|
||||
var input = document.getElementById("textarea");
|
||||
var to_client_id = $("#client_list option:selected").attr("value");
|
||||
var to_client_name = $("#client_list option:selected").text();
|
||||
ws.send('{"type":"say","to_client_id":"'+to_client_id+'","to_client_name":"'+to_client_name+'","content":"'+input.value.replace(/"/g, '\\"').replace(/\n/g,'\\n').replace(/\r/g, '\\r')+'"}');
|
||||
input.value = "";
|
||||
input.focus();
|
||||
}
|
||||
|
||||
// 刷新用户列表框
|
||||
function flush_client_list(){
|
||||
var userlist_window = $("#userlist");
|
||||
var client_list_slelect = $("#client_list");
|
||||
userlist_window.empty();
|
||||
client_list_slelect.empty();
|
||||
userlist_window.append('<h4>在线用户</h4><ul>');
|
||||
client_list_slelect.append('<option value="all" id="cli_all">所有人</option>');
|
||||
for(var p in client_list){
|
||||
userlist_window.append('<li id="'+p+'">'+client_list[p]+'</li>');
|
||||
client_list_slelect.append('<option value="'+p+'">'+client_list[p]+'</option>');
|
||||
}
|
||||
$("#client_list").val(select_client_id);
|
||||
userlist_window.append('</ul>');
|
||||
}
|
||||
|
||||
// 发言
|
||||
function say(from_client_id, from_client_name, content, time){
|
||||
$("#dialog").append('<div class="speech_item"><img src="http://lorempixel.com/38/38/?'+from_client_id+'" class="user_icon" /> '+from_client_name+' <br> '+time+'<div style="clear:both;"></div><p class="triangle-isosceles top">'+content+'</p> </div>');
|
||||
}
|
||||
$(function(){
|
||||
select_client_id = 'all';
|
||||
$("#client_list").change(function(){
|
||||
select_client_id = $("#client_list option:selected").attr("value");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body onload="connect();">
|
||||
<div class="container">
|
||||
<div class="row clearfix">
|
||||
<div class="col-md-1 column">
|
||||
</div>
|
||||
<div class="col-md-6 column">
|
||||
<div class="thumbnail">
|
||||
<div class="caption" id="dialog"></div>
|
||||
</div>
|
||||
<form onsubmit="onSubmit(); return false;">
|
||||
<select style="margin-bottom:8px" id="client_list">
|
||||
<option value="all">所有人</option>
|
||||
</select>
|
||||
<textarea class="textarea thumbnail" id="textarea"></textarea>
|
||||
<div class="say-btn"><input type="submit" class="btn btn-default" value="发表" /></div>
|
||||
</form>
|
||||
<div>
|
||||
<b>房间列表:</b>(当前在 房间<?php echo isset($_GET['room_id'])&&intval($_GET['room_id'])>0 ? intval($_GET['room_id']):1; ?>)<br>
|
||||
<a href="/?room_id=1">房间1</a> <a href="/?room_id=2">房间2</a> <a href="/?room_id=3">房间3</a> <a href="/?room_id=4">房间4</a>
|
||||
<br><br>
|
||||
</div>
|
||||
<p class="cp">PHP多进程+Websocket(HTML5/Flash)+PHP Socket实时推送技术 Powered by <a href="http://www.workerman.net/workerman-chat" target="_blank">workerman-chat</a></p>
|
||||
</div>
|
||||
<div class="col-md-3 column">
|
||||
<div class="thumbnail">
|
||||
<div class="caption" id="userlist"></div>
|
||||
</div>
|
||||
<a href="http://workerman.net:8383" target="_blank"><img style="width:252px;margin-left:5px;" src="/img/workerman-todpole.png"></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F7b1919221e89d2aa5711e4deb935debd' type='text/javascript'%3E%3C/script%3E"));</script>
|
||||
</body>
|
||||
</html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,398 @@
|
|||
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
||||
// License: New BSD License
|
||||
// Reference: http://dev.w3.org/html5/websockets/
|
||||
// Reference: http://tools.ietf.org/html/rfc6455
|
||||
|
||||
(function() {
|
||||
|
||||
if (window.WEB_SOCKET_FORCE_FLASH) {
|
||||
// Keeps going.
|
||||
} else if (window.WebSocket) {
|
||||
return;
|
||||
} else if (window.MozWebSocket) {
|
||||
// Firefox.
|
||||
window.WebSocket = MozWebSocket;
|
||||
return;
|
||||
}
|
||||
|
||||
var logger;
|
||||
if (window.WEB_SOCKET_LOGGER) {
|
||||
logger = WEB_SOCKET_LOGGER;
|
||||
} else if (window.console && window.console.log && window.console.error) {
|
||||
// In some environment, console is defined but console.log or console.error is missing.
|
||||
logger = window.console;
|
||||
} else {
|
||||
logger = {log: function(){ }, error: function(){ }};
|
||||
}
|
||||
|
||||
// swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash.
|
||||
if (swfobject.getFlashPlayerVersion().major < 10) {
|
||||
logger.error("Flash Player >= 10.0.0 is required.");
|
||||
return;
|
||||
}
|
||||
if (location.protocol == "file:") {
|
||||
logger.error(
|
||||
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
||||
"unless you set Flash Security Settings properly. " +
|
||||
"Open the page via Web server i.e. http://...");
|
||||
}
|
||||
|
||||
/**
|
||||
* Our own implementation of WebSocket class using Flash.
|
||||
* @param {string} url
|
||||
* @param {array or string} protocols
|
||||
* @param {string} proxyHost
|
||||
* @param {int} proxyPort
|
||||
* @param {string} headers
|
||||
*/
|
||||
window.WebSocket = function(url, protocols, proxyHost, proxyPort, headers) {
|
||||
var self = this;
|
||||
self.__id = WebSocket.__nextId++;
|
||||
WebSocket.__instances[self.__id] = self;
|
||||
self.readyState = WebSocket.CONNECTING;
|
||||
self.bufferedAmount = 0;
|
||||
self.__events = {};
|
||||
if (!protocols) {
|
||||
protocols = [];
|
||||
} else if (typeof protocols == "string") {
|
||||
protocols = [protocols];
|
||||
}
|
||||
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
||||
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
||||
self.__createTask = setTimeout(function() {
|
||||
WebSocket.__addTask(function() {
|
||||
self.__createTask = null;
|
||||
WebSocket.__flash.create(
|
||||
self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
|
||||
});
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send data to the web socket.
|
||||
* @param {string} data The data to send to the socket.
|
||||
* @return {boolean} True for success, false for failure.
|
||||
*/
|
||||
WebSocket.prototype.send = function(data) {
|
||||
if (this.readyState == WebSocket.CONNECTING) {
|
||||
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
||||
}
|
||||
// We use encodeURIComponent() here, because FABridge doesn't work if
|
||||
// the argument includes some characters. We don't use escape() here
|
||||
// because of this:
|
||||
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
||||
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
||||
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
||||
// Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
|
||||
// additional testing.
|
||||
var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
|
||||
if (result < 0) { // success
|
||||
return true;
|
||||
} else {
|
||||
this.bufferedAmount += result;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Close this web socket gracefully.
|
||||
*/
|
||||
WebSocket.prototype.close = function() {
|
||||
if (this.__createTask) {
|
||||
clearTimeout(this.__createTask);
|
||||
this.__createTask = null;
|
||||
this.readyState = WebSocket.CLOSED;
|
||||
return;
|
||||
}
|
||||
if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
|
||||
return;
|
||||
}
|
||||
this.readyState = WebSocket.CLOSING;
|
||||
WebSocket.__flash.close(this.__id);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {function} listener
|
||||
* @param {boolean} useCapture
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
||||
if (!(type in this.__events)) {
|
||||
this.__events[type] = [];
|
||||
}
|
||||
this.__events[type].push(listener);
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {string} type
|
||||
* @param {function} listener
|
||||
* @param {boolean} useCapture
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
||||
if (!(type in this.__events)) return;
|
||||
var events = this.__events[type];
|
||||
for (var i = events.length - 1; i >= 0; --i) {
|
||||
if (events[i] === listener) {
|
||||
events.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||
*
|
||||
* @param {Event} event
|
||||
* @return void
|
||||
*/
|
||||
WebSocket.prototype.dispatchEvent = function(event) {
|
||||
var events = this.__events[event.type] || [];
|
||||
for (var i = 0; i < events.length; ++i) {
|
||||
events[i](event);
|
||||
}
|
||||
var handler = this["on" + event.type];
|
||||
if (handler) handler.apply(this, [event]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles an event from Flash.
|
||||
* @param {Object} flashEvent
|
||||
*/
|
||||
WebSocket.prototype.__handleEvent = function(flashEvent) {
|
||||
|
||||
if ("readyState" in flashEvent) {
|
||||
this.readyState = flashEvent.readyState;
|
||||
}
|
||||
if ("protocol" in flashEvent) {
|
||||
this.protocol = flashEvent.protocol;
|
||||
}
|
||||
|
||||
var jsEvent;
|
||||
if (flashEvent.type == "open" || flashEvent.type == "error") {
|
||||
jsEvent = this.__createSimpleEvent(flashEvent.type);
|
||||
} else if (flashEvent.type == "close") {
|
||||
jsEvent = this.__createSimpleEvent("close");
|
||||
jsEvent.wasClean = flashEvent.wasClean ? true : false;
|
||||
jsEvent.code = flashEvent.code;
|
||||
jsEvent.reason = flashEvent.reason;
|
||||
} else if (flashEvent.type == "message") {
|
||||
var data = decodeURIComponent(flashEvent.message);
|
||||
jsEvent = this.__createMessageEvent("message", data);
|
||||
} else {
|
||||
throw "unknown event type: " + flashEvent.type;
|
||||
}
|
||||
|
||||
this.dispatchEvent(jsEvent);
|
||||
|
||||
};
|
||||
|
||||
WebSocket.prototype.__createSimpleEvent = function(type) {
|
||||
if (document.createEvent && window.Event) {
|
||||
var event = document.createEvent("Event");
|
||||
event.initEvent(type, false, false);
|
||||
return event;
|
||||
} else {
|
||||
return {type: type, bubbles: false, cancelable: false};
|
||||
}
|
||||
};
|
||||
|
||||
WebSocket.prototype.__createMessageEvent = function(type, data) {
|
||||
if (window.MessageEvent && typeof(MessageEvent) == "function" && !window.opera) {
|
||||
return new MessageEvent("message", {
|
||||
"view": window,
|
||||
"bubbles": false,
|
||||
"cancelable": false,
|
||||
"data": data
|
||||
});
|
||||
} else if (document.createEvent && window.MessageEvent && !window.opera) {
|
||||
var event = document.createEvent("MessageEvent");
|
||||
event.initMessageEvent("message", false, false, data, null, null, window, null);
|
||||
return event;
|
||||
} else {
|
||||
// Old IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
|
||||
return {type: type, data: data, bubbles: false, cancelable: false};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Define the WebSocket readyState enumeration.
|
||||
*/
|
||||
WebSocket.CONNECTING = 0;
|
||||
WebSocket.OPEN = 1;
|
||||
WebSocket.CLOSING = 2;
|
||||
WebSocket.CLOSED = 3;
|
||||
|
||||
// Field to check implementation of WebSocket.
|
||||
WebSocket.__isFlashImplementation = true;
|
||||
WebSocket.__initialized = false;
|
||||
WebSocket.__flash = null;
|
||||
WebSocket.__instances = {};
|
||||
WebSocket.__tasks = [];
|
||||
WebSocket.__nextId = 0;
|
||||
|
||||
/**
|
||||
* Load a new flash security policy file.
|
||||
* @param {string} url
|
||||
*/
|
||||
WebSocket.loadFlashPolicyFile = function(url){
|
||||
WebSocket.__addTask(function() {
|
||||
WebSocket.__flash.loadManualPolicyFile(url);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
|
||||
*/
|
||||
WebSocket.__initialize = function() {
|
||||
|
||||
if (WebSocket.__initialized) return;
|
||||
WebSocket.__initialized = true;
|
||||
|
||||
if (WebSocket.__swfLocation) {
|
||||
// For backword compatibility.
|
||||
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
||||
}
|
||||
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
||||
logger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
||||
return;
|
||||
}
|
||||
if (!window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR &&
|
||||
!WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) &&
|
||||
WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) {
|
||||
var swfHost = RegExp.$1;
|
||||
if (location.host != swfHost) {
|
||||
logger.error(
|
||||
"[WebSocket] You must host HTML and WebSocketMain.swf in the same host " +
|
||||
"('" + location.host + "' != '" + swfHost + "'). " +
|
||||
"See also 'How to host HTML file and SWF file in different domains' section " +
|
||||
"in README.md. If you use WebSocketMainInsecure.swf, you can suppress this message " +
|
||||
"by WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;");
|
||||
}
|
||||
}
|
||||
var container = document.createElement("div");
|
||||
container.id = "webSocketContainer";
|
||||
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
||||
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
||||
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
||||
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
||||
// the best we can do as far as we know now.
|
||||
container.style.position = "absolute";
|
||||
if (WebSocket.__isFlashLite()) {
|
||||
container.style.left = "0px";
|
||||
container.style.top = "0px";
|
||||
} else {
|
||||
container.style.left = "-100px";
|
||||
container.style.top = "-100px";
|
||||
}
|
||||
var holder = document.createElement("div");
|
||||
holder.id = "webSocketFlash";
|
||||
container.appendChild(holder);
|
||||
document.body.appendChild(container);
|
||||
// See this article for hasPriority:
|
||||
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
||||
swfobject.embedSWF(
|
||||
WEB_SOCKET_SWF_LOCATION,
|
||||
"webSocketFlash",
|
||||
"1" /* width */,
|
||||
"1" /* height */,
|
||||
"10.0.0" /* SWF version */,
|
||||
null,
|
||||
null,
|
||||
{hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
|
||||
null,
|
||||
function(e) {
|
||||
if (!e.success) {
|
||||
logger.error("[WebSocket] swfobject.embedSWF failed");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Flash to notify JS that it's fully loaded and ready
|
||||
* for communication.
|
||||
*/
|
||||
WebSocket.__onFlashInitialized = function() {
|
||||
// We need to set a timeout here to avoid round-trip calls
|
||||
// to flash during the initialization process.
|
||||
setTimeout(function() {
|
||||
WebSocket.__flash = document.getElementById("webSocketFlash");
|
||||
WebSocket.__flash.setCallerUrl(location.href);
|
||||
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
||||
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
||||
WebSocket.__tasks[i]();
|
||||
}
|
||||
WebSocket.__tasks = [];
|
||||
}, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Flash to notify WebSockets events are fired.
|
||||
*/
|
||||
WebSocket.__onFlashEvent = function() {
|
||||
setTimeout(function() {
|
||||
try {
|
||||
// Gets events using receiveEvents() instead of getting it from event object
|
||||
// of Flash event. This is to make sure to keep message order.
|
||||
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
||||
var events = WebSocket.__flash.receiveEvents();
|
||||
for (var i = 0; i < events.length; ++i) {
|
||||
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(e);
|
||||
}
|
||||
}, 0);
|
||||
return true;
|
||||
};
|
||||
|
||||
// Called by Flash.
|
||||
WebSocket.__log = function(message) {
|
||||
logger.log(decodeURIComponent(message));
|
||||
};
|
||||
|
||||
// Called by Flash.
|
||||
WebSocket.__error = function(message) {
|
||||
logger.error(decodeURIComponent(message));
|
||||
};
|
||||
|
||||
WebSocket.__addTask = function(task) {
|
||||
if (WebSocket.__flash) {
|
||||
task();
|
||||
} else {
|
||||
WebSocket.__tasks.push(task);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Test if the browser is running flash lite.
|
||||
* @return {boolean} True if flash lite is running, false otherwise.
|
||||
*/
|
||||
WebSocket.__isFlashLite = function() {
|
||||
if (!window.navigator || !window.navigator.mimeTypes) {
|
||||
return false;
|
||||
}
|
||||
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
||||
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
|
||||
return false;
|
||||
}
|
||||
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
||||
};
|
||||
|
||||
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
||||
// NOTE:
|
||||
// This fires immediately if web_socket.js is dynamically loaded after
|
||||
// the document is loaded.
|
||||
swfobject.addDomLoadEvent(function() {
|
||||
WebSocket.__initialize();
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
Binary file not shown.
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of workerman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
use \Workerman\Worker;
|
||||
use \Workerman\WebServer;
|
||||
use \GatewayWorker\Gateway;
|
||||
use \GatewayWorker\BusinessWorker;
|
||||
use \Workerman\Autoloader;
|
||||
|
||||
|
||||
// 自动加载类
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
$context = array(
|
||||
// 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php
|
||||
'ssl' => array(
|
||||
// 请使用绝对路径
|
||||
'local_cert' => 'C:\phpStudy\PHPTutorial\Apache\cert\214589318510968.pem', // 也可以是crt文件
|
||||
'local_pk' => 'C:\phpStudy\PHPTutorial\Apache\cert\214589318510968.key',
|
||||
'verify_peer' => false,
|
||||
// 'allow_self_signed' => true, //如果是自签名证书需要开启此选项
|
||||
)
|
||||
);
|
||||
// WebServer
|
||||
$web = new WebServer("http://0.0.0.0:517");
|
||||
// WebServer数量
|
||||
$web->count = 2;
|
||||
// 设置站点根目录
|
||||
$web->addRoot('www.mobzhifu.com', __DIR__.'/Web');
|
||||
|
||||
// 如果不是在根目录启动,则运行runAll方法
|
||||
if(!defined('GLOBAL_START'))
|
||||
{
|
||||
Worker::runAll();
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of workerman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
use \Workerman\Worker;
|
||||
use \Workerman\WebServer;
|
||||
use \GatewayWorker\Gateway;
|
||||
use \GatewayWorker\BusinessWorker;
|
||||
use \Workerman\Autoloader;
|
||||
|
||||
// 自动加载类
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
// bussinessWorker 进程
|
||||
$worker = new BusinessWorker();
|
||||
// worker名称
|
||||
$worker->name = 'YourAppBusinessWorker';
|
||||
// bussinessWorker进程数量
|
||||
$worker->count = 4;
|
||||
// 服务注册地址
|
||||
$worker->registerAddress = '127.0.0.1:1239';
|
||||
|
||||
// 如果不是在根目录启动,则运行runAll方法
|
||||
if(!defined('GLOBAL_START'))
|
||||
{
|
||||
Worker::runAll();
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of workerman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
use \Workerman\Worker;
|
||||
use \GatewayWorker\Gateway;
|
||||
use \Workerman\Autoloader;
|
||||
|
||||
// 自动加载类
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
$context = array(
|
||||
// 更多ssl选项请参考手册 http://php.net/manual/zh/context.ssl.php
|
||||
'ssl' => array(
|
||||
// 请使用绝对路径
|
||||
// 'local_cert' => 'C:\phpStudy\PHPTutorial\Apache\cert\214589318510968.pem', // 也可以是crt文件
|
||||
// 'local_pk' => 'C:\phpStudy\PHPTutorial\Apache\cert\214589318510968.key',
|
||||
'verify_peer' => false,
|
||||
// 'allow_self_signed' => true, //如果是自签名证书需要开启此选项
|
||||
)
|
||||
);
|
||||
// gateway 进程
|
||||
$gateway = new Gateway("Websocket://0.0.0.0:7373");
|
||||
// 设置名称,方便status时查看
|
||||
$gateway->name = 'ChatGateway';
|
||||
// $gateway->transport = 'ssl';
|
||||
// 设置进程数,gateway进程数建议与cpu核数相同
|
||||
$gateway->count = 4;
|
||||
// 分布式部署时请设置成内网ip(非127.0.0.1)
|
||||
// $gateway->lanIp = '127.0.0.1';
|
||||
$gateway->lanIp = getHostByName(getHostName());
|
||||
// 内部通讯起始端口,假如$gateway->count=4,起始端口为4000
|
||||
// 则一般会使用4000 4001 4002 4003 4个端口作为内部通讯端口
|
||||
$gateway->startPort = 2400;
|
||||
// 心跳间隔
|
||||
$gateway->pingInterval = 10;
|
||||
// 心跳数据
|
||||
$gateway->pingData = "{'type':'ping'}";
|
||||
// 服务注册地址
|
||||
$gateway->registerAddress = '127.0.0.1:1239';
|
||||
|
||||
|
||||
/*
|
||||
// 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
|
||||
$gateway->onConnect = function($connection)
|
||||
{
|
||||
$connection->onWebSocketConnect = function($connection , $http_header)
|
||||
{
|
||||
// 可以在这里判断连接来源是否合法,不合法就关掉连接
|
||||
// $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接
|
||||
if($_SERVER['HTTP_ORIGIN'] != 'http://chat.workerman.net')
|
||||
{
|
||||
$connection->close();
|
||||
}
|
||||
// onWebSocketConnect 里面$_GET $_SERVER是可用的
|
||||
// var_dump($_GET, $_SERVER);
|
||||
};
|
||||
};
|
||||
*/
|
||||
|
||||
// 如果不是在根目录启动,则运行runAll方法
|
||||
if(!defined('GLOBAL_START'))
|
||||
{
|
||||
Worker::runAll();
|
||||
}
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
<?php
|
||||
|
||||
use \Workerman\Worker;
|
||||
use Workerman\Connection\TcpConnection;
|
||||
use Workerman\Protocols\Http\Request;
|
||||
|
||||
// 自动加载类
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
// 加载mysql
|
||||
require_once __DIR__ . '/../libs/mysql-master/src/Connection.php';
|
||||
|
||||
|
||||
// 创建一个Worker监听2345端口,使用http协议通讯
|
||||
$http_worker = new Worker("tcp://0.0.0.0:2345");
|
||||
$http_worker->name = "ImageDownloadWorker";
|
||||
|
||||
// 启动4个进程对外提供服务
|
||||
$http_worker->count = 4;
|
||||
|
||||
$http_worker->onWorkerStart = function ($worker) {
|
||||
if (!defined('__ROOT__')) {
|
||||
define('__ROOT__', '/');
|
||||
}
|
||||
// 读取配置
|
||||
$configPath = substr(__DIR__, 0, strpos(__DIR__, 'Worker')) . '/Application/Common/Conf/config.php';
|
||||
|
||||
global $config;
|
||||
$config = include($configPath);
|
||||
|
||||
// 初始化数据库
|
||||
global $mysql;
|
||||
$mysql = new \Workerman\MySQL\Connection($config['DB_HOST'], $config['DB_PORT'], $config['DB_USER'], $config['DB_PWD'], $config['DB_NAME']);
|
||||
|
||||
};
|
||||
|
||||
// 接收到浏览器发送的数据时回复hello world给浏览器
|
||||
$http_worker->onMessage = function (TcpConnection $connection, $data) {
|
||||
|
||||
global $mysql;
|
||||
global $config;
|
||||
|
||||
$isDebug = false;
|
||||
|
||||
$data = json_decode($data, true);
|
||||
|
||||
$isDebug && printf('--------------mission start-----------' . "\n");
|
||||
|
||||
$sql = "select * from ls_retail_goodsimport_logs where log_id = '{$data['logId']}' limit 1";
|
||||
$logInfos = $mysql->query($sql);
|
||||
$info = $logInfos[0];
|
||||
if (empty($info)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$imageUrls = json_decode($info['detail']);
|
||||
|
||||
$failArr = [];
|
||||
|
||||
foreach ($imageUrls as $imageUrl) {
|
||||
$extension = pathinfo($imageUrl, PATHINFO_EXTENSION);
|
||||
$extension = $extension ? ('.' . $extension) : '';
|
||||
$originName = pathinfo($imageUrl, PATHINFO_BASENAME);
|
||||
$saveName = md5_file($imageUrl) . $extension;
|
||||
$isDebug && printf("imageUrl: " . $imageUrl . "\n");
|
||||
|
||||
$isDev = !isset($config['SERVER_LOCATION']) || (isset($config['SERVER_LOCATION']) && $config['SERVER_LOCATION'] == 'cn');
|
||||
|
||||
if ($isDev) {
|
||||
$cxContext = stream_context_create([
|
||||
'http' => [
|
||||
'proxy' => 'tcp://192.168.15.217:1080',
|
||||
'request_fulluri' => true,
|
||||
],
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$imageData = file_get_contents($imageUrl, false, $cxContext ?? null);
|
||||
if ($imageData !== false) {
|
||||
$headers = get_headers($imageUrl, 1);
|
||||
$fileSize = $headers['Content-Length'];
|
||||
$mimetype = $headers['Content-Type'];
|
||||
// print_r(json_encode($headers) . "\n");
|
||||
try {
|
||||
$s3Client = new \Aws\S3\S3Client([
|
||||
'region' => 'sa-east-1',
|
||||
'credentials' => [
|
||||
'key' => 'AKIARKKH7TUORIJGGKFX',
|
||||
'secret' => 'HzjwqQV1f2GF4uxw1EABT5VsXR5T2VZTz0qW3C8h'
|
||||
]
|
||||
]);
|
||||
$prefix = $isDev ? 'phizshop/dev' : 'phizshop/pro';
|
||||
$key = $prefix . '/Store/Goods/' . date('Y-m-d') . '/' . time() . uniqid() . $extension;
|
||||
|
||||
$params = [
|
||||
'Bucket' => 'phizclip-assets',
|
||||
'ACL' => 'public-read',
|
||||
'Key' => $key,
|
||||
'Body' => $imageData,
|
||||
'ContentType' => $mimetype
|
||||
];
|
||||
$result = $s3Client->putObject($params);
|
||||
|
||||
$isDebug && print_r(json_encode([
|
||||
'params' => $params['Key'],
|
||||
'result' => $result['@metadata']
|
||||
]) . "\n");
|
||||
|
||||
if (!$result || $result['@metadata']['statusCode'] != 200) {
|
||||
$failArr[] = $imageUrl;
|
||||
continue;
|
||||
}
|
||||
|
||||
$filePath = $result['@metadata']['effectiveUri'];
|
||||
|
||||
$isDebug && print_r("effectiveUri: " . $filePath . "\n");
|
||||
} catch (\Aws\Exception\AwsException $e) {
|
||||
$failArr[] = $imageUrl;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$failArr[] = $imageUrl;
|
||||
continue;
|
||||
}
|
||||
|
||||
$agentId = $data['agentId'] ?: 0;
|
||||
$merchantId = $data['merchantId'] ?: 0;
|
||||
$storeId = $data['storeId'] ?: 0;
|
||||
$sql = "update ls_image_gallery
|
||||
set path = '{$filePath}',
|
||||
name = '{$saveName}',
|
||||
original_name = '{$originName}',
|
||||
size = '{$fileSize}',
|
||||
catalog = 'Uploads/Store/Goods',
|
||||
agent_id = {$agentId},
|
||||
merchant_id = {$merchantId},
|
||||
store_id = {$storeId}
|
||||
where path = '{$imageUrl}'
|
||||
";
|
||||
$num = $mysql->query($sql);
|
||||
// printf("num: " . $num . "\n");
|
||||
if ($num <= 0) {
|
||||
$failArr[] = $imageUrl;
|
||||
}
|
||||
|
||||
// $sql = "update ls_retail_goodsimport set good_image = '{$imgId}' where good_image = '{$imageUrl}'";
|
||||
// $mysql->query($sql);
|
||||
|
||||
}
|
||||
|
||||
$isDebug && printf("failArr: " . json_encode($failArr) . "\n");
|
||||
|
||||
$finishTime = date('Y-m-d H:i:s', time());
|
||||
$failDetail = json_encode($failArr);
|
||||
$successNum = $info['total'] - count($failArr);
|
||||
$failNum = count($failArr);
|
||||
$sql = "update ls_retail_goodsimport_logs
|
||||
set success_num = {$successNum},
|
||||
fail_num = {$failNum},
|
||||
status = 1,
|
||||
finish_time = '{$finishTime}',
|
||||
fail_detail = '{$failDetail}'
|
||||
where log_id = '{$data['logId']}'
|
||||
";
|
||||
$mysql->query($sql);
|
||||
|
||||
$connection->send(json_encode(['code' => 0, 'msg' => 'success']));
|
||||
|
||||
$isDebug && printf('--------------mission end-----------' . "\n\n");
|
||||
|
||||
};
|
||||
|
||||
if (!defined('GLOBAL_START')) {
|
||||
Worker::runAll();
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of workerman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
use \Workerman\Worker;
|
||||
use \GatewayWorker\Register;
|
||||
|
||||
// 自动加载类
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
// register 必须是text协议
|
||||
$register = new Register('text://0.0.0.0:1239');
|
||||
|
||||
// 如果不是在根目录启动,则运行runAll方法
|
||||
if(!defined('GLOBAL_START'))
|
||||
{
|
||||
Worker::runAll();
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
use \Workerman\Worker;
|
||||
use \GatewayWorker\Gateway;
|
||||
use \Workerman\Autoloader;
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
Autoloader::setRootPath(__DIR__);
|
||||
|
||||
// #### 内部推送端口(假设当前服务器内网ip为192.168.100.100) ####
|
||||
// #### 端口不能与原来start_gateway.php中一样 ####
|
||||
$internal_gateway = new Gateway("Text://0.0.0.0:7273");
|
||||
$internal_gateway->name='internalGateway';
|
||||
// #### 不要与原来start_gateway.php的一样####
|
||||
// #### 比原来跨度大一些,比如在原有startPort基础上+1000 ####
|
||||
$internal_gateway->startPort = 3400;
|
||||
// #### 这里设置成与原start_gateway.php 一样 ####
|
||||
$internal_gateway->registerAddress = '127.0.0.1:1239';
|
||||
// #### 内部推送端口设置完毕 ####
|
||||
|
||||
if(!defined('GLOBAL_START'))
|
||||
{
|
||||
Worker::runAll();
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
# Workerman\Mysql\Connection
|
||||
|
||||
Long-living MySQL connection for daemon.
|
||||
|
||||
# Install
|
||||
```composer require workerman/mysql```
|
||||
|
||||
# Usage
|
||||
```php
|
||||
$db = new Workerman\MySQL\Connection($mysql_host, $mysql_port, $user, $password, $db_bname);
|
||||
|
||||
// Get all rows.
|
||||
$db1->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->query();
|
||||
// Equivalent to.
|
||||
$db1->select('ID,Sex')->from('Persons')->where("sex='F'")->query();
|
||||
// Equivalent to.
|
||||
$db->query("SELECT ID,Sex FROM `Persons` WHERE sex='M'");
|
||||
|
||||
|
||||
// Get one row.
|
||||
$db->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->row();
|
||||
// Equivalent to.
|
||||
$db->select('ID,Sex')->from('Persons')->where("sex= 'F' ")->row();
|
||||
// Equivalent to.
|
||||
$db->row("SELECT ID,Sex FROM `Persons` WHERE sex='M'");
|
||||
|
||||
|
||||
// Get a column.
|
||||
$db->select('ID')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->column();
|
||||
// Equivalent to.
|
||||
$db->select('ID')->from('Persons')->where("sex= 'F' ")->column();
|
||||
// Equivalent to.
|
||||
$db->column("SELECT `ID` FROM `Persons` WHERE sex='M'");
|
||||
|
||||
// Get single.
|
||||
$db->select('ID,Sex')->from('Persons')->where('sex= :sex')->bindValues(array('sex'=>'M'))->single();
|
||||
// Equivalent to.
|
||||
$db->select('ID,Sex')->from('Persons')->where("sex= 'F' ")->single();
|
||||
// Equivalent to.
|
||||
$db->single("SELECT ID,Sex FROM `Persons` WHERE sex='M'");
|
||||
|
||||
// Complex query.
|
||||
$db->select('*')->from('table1')->innerJoin('table2','table1.uid = table2.uid')->where('age > :age')
|
||||
->groupBy(array('aid'))->having('foo="foo"')->orderByASC/*orderByDESC*/(array('did'))
|
||||
->limit(10)->offset(20)->bindValues(array('age' => 13));
|
||||
// Equivalent to.
|
||||
$db->query(SELECT * FROM `table1` INNER JOIN `table2` ON `table1`.`uid` = `table2`.`uid` WHERE age > 13
|
||||
GROUP BY aid HAVING foo="foo" ORDER BY did LIMIT 10 OFFSET 20“);
|
||||
|
||||
// Insert.
|
||||
$insert_id = $db->insert('Persons')->cols(array(
|
||||
'Firstname'=>'abc',
|
||||
'Lastname'=>'efg',
|
||||
'Sex'=>'M',
|
||||
'Age'=>13))->query();
|
||||
// Equivalent to.
|
||||
$insert_id = $db->query("INSERT INTO `Persons` ( `Firstname`,`Lastname`,`Sex`,`Age`)
|
||||
VALUES ( 'abc', 'efg', 'M', 13)");
|
||||
|
||||
// Update.
|
||||
$row_count = $db->update('Persons')->cols(array('sex'))->where('ID=1')
|
||||
->bindValue('sex', 'F')->query();
|
||||
// Equivalent to.
|
||||
$row_count = $db->update('Persons')->cols(array('sex'=>'F'))->where('ID=1')->query();
|
||||
// Equivalent to.
|
||||
$row_count = $db->query("UPDATE `Persons` SET `sex` = 'F' WHERE ID=1");
|
||||
|
||||
// Delete.
|
||||
$row_count = $db->delete('Persons')->where('ID=9')->query();
|
||||
// Equivalent to.
|
||||
$row_count = $db->query("DELETE FROM `Persons` WHERE ID=9");
|
||||
|
||||
// Transaction.
|
||||
$db1->beginTrans();
|
||||
....
|
||||
$db1->commitTrans(); // or $db1->rollBackTrans();
|
||||
|
||||
```
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name" : "workerman/mysql",
|
||||
"type" : "library",
|
||||
"keywords": ["mysql", "pdo", "pdo_mysql"],
|
||||
"homepage": "http://www.workerman.net",
|
||||
"license" : "MIT",
|
||||
"description": "Long-living MySQL connection for daemon.",
|
||||
"require": {
|
||||
"php": ">=5.3",
|
||||
"ext-pdo": "*",
|
||||
"ext-pdo_mysql": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {"Workerman\\MySQL\\": "./src"}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
|||
FROM docker-dev.xyue.zip:8443/nginx-php-fpm:7.4
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制 admin_panel_backend 目录所有文件到容器的/app目录下
|
||||
COPY . .
|
||||
|
||||
# 复制php-fpm配置文件
|
||||
COPY www.conf /usr/local/etc/php-fpm.d/worker.conf
|
||||
|
||||
# 复制nginx配置文件
|
||||
COPY nginx.conf /etc/nginx/worker.conf
|
||||
|
||||
# Composer 安装
|
||||
RUN composer install --no-dev --prefer-dist
|
||||
|
||||
# 增加执行权限
|
||||
RUN chmod a+rwx /app/Applications/YourApp
|
||||
|
||||
# 暴露 Nginx 监听的端口
|
||||
EXPOSE 80
|
||||
EXPOSE 7373
|
||||
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
# CMD to execute startup script
|
||||
CMD ["/app/start.sh"]
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License
|
||||
|
||||
Copyright (c) 2009-2015 walkor<walkor@workerman.net> and contributors (see https://github.com/walkor/workerman/contributors)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,46 @@
|
|||
GatewayWorker windows 版本
|
||||
=================
|
||||
|
||||
GatewayWorker基于[Workerman](https://github.com/walkor/Workerman)开发的一个项目框架,用于快速开发长连接应用,例如app推送服务端、即时IM服务端、游戏服务端、物联网、智能家居等等。
|
||||
|
||||
GatewayWorker使用经典的Gateway和Worker进程模型。Gateway进程负责维持客户端连接,并转发客户端的数据给Worker进程处理;Worker进程负责处理实际的业务逻辑,并将结果推送给对应的客户端。Gateway服务和Worker服务可以分开部署在不同的服务器上,实现分布式集群。
|
||||
|
||||
GatewayWorker提供非常方便的API,可以全局广播数据、可以向某个群体广播数据、也可以向某个特定客户端推送数据。配合Workerman的定时器,也可以定时推送数据。
|
||||
|
||||
GatewayWorker Linux 版本
|
||||
======================
|
||||
Linux 版本GatewayWorker 在这里 https://github.com/walkor/GatewayWorker
|
||||
|
||||
启动
|
||||
=======
|
||||
双击start_for_win.bat
|
||||
|
||||
Applications\YourApp测试方法
|
||||
======
|
||||
使用telnet命令测试(不要使用windows自带的telnet)
|
||||
```shell
|
||||
telnet 127.0.0.1 8282
|
||||
Trying 127.0.0.1...
|
||||
Connected to 127.0.0.1.
|
||||
Escape character is '^]'.
|
||||
Hello 3
|
||||
3 login
|
||||
haha
|
||||
3 said haha
|
||||
```
|
||||
|
||||
手册
|
||||
=======
|
||||
http://www.workerman.net/gatewaydoc/
|
||||
|
||||
使用GatewayWorker-for-win开发的项目
|
||||
=======
|
||||
## [tadpole](http://kedou.workerman.net/)
|
||||
[Live demo](http://kedou.workerman.net/)
|
||||
[Source code](https://github.com/walkor/workerman)
|
||||
![workerman-todpole](http://www.workerman.net/img/workerman-todpole.png)
|
||||
|
||||
## [chat room](http://chat.workerman.net/)
|
||||
[Live demo](http://chat.workerman.net/)
|
||||
[Source code](https://github.com/walkor/workerman-chat)
|
||||
![workerman-chat](http://www.workerman.net/img/workerman-chat.png)
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"name" : "workerman/gateway-worker-demo",
|
||||
"keywords": ["distributed","communication"],
|
||||
"homepage": "http://www.workerman.net",
|
||||
"license" : "MIT",
|
||||
"require": {
|
||||
"workerman/gateway-worker" : ">=3.0.0",
|
||||
"aws/aws-sdk-php": "^3.295"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,92 @@
|
|||
user www-data;
|
||||
worker_processes auto;
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections 768;
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
types_hash_max_size 2048;
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip on;
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
server_name localhost;
|
||||
index index.php;
|
||||
|
||||
client_max_body_size 20m;
|
||||
root /app;
|
||||
|
||||
location / {
|
||||
if (!-e $request_filename) {
|
||||
rewrite ^(.*)$ /index.php?s=/$1 last;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
location ~ \.php$ {
|
||||
root /app;
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_param PATH_INFO $fastcgi_path_info;
|
||||
include fastcgi_params;
|
||||
}
|
||||
|
||||
location ~ \.php/?.*$ {
|
||||
root /app;
|
||||
fastcgi_pass 127.0.0.1:9000;
|
||||
fastcgi_index index.php;
|
||||
#加载Nginx默认"服务器环境变量"配置
|
||||
# include fastcgi.conf;
|
||||
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量
|
||||
set $fastcgi_script_name2 $fastcgi_script_name;
|
||||
if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
|
||||
set $fastcgi_script_name2 $1;
|
||||
set $path_info $2;
|
||||
}
|
||||
fastcgi_param PATH_INFO $path_info;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2;
|
||||
fastcgi_param SCRIPT_NAME $fastcgi_script_name2;
|
||||
include fastcgi_params;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* run with command
|
||||
* php start.php start
|
||||
*/
|
||||
|
||||
ini_set('display_errors', 'on');
|
||||
use Workerman\Worker;
|
||||
|
||||
if(strpos(strtolower(PHP_OS), 'win') === 0)
|
||||
{
|
||||
exit("start.php not support windows, please use start_for_win.bat\n");
|
||||
}
|
||||
|
||||
// 检查扩展
|
||||
if(!extension_loaded('pcntl'))
|
||||
{
|
||||
exit("Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
|
||||
}
|
||||
|
||||
if(!extension_loaded('posix'))
|
||||
{
|
||||
exit("Please install posix extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
|
||||
}
|
||||
|
||||
// 标记是全局启动
|
||||
define('GLOBAL_START', 1);
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
// 加载所有Applications/*/start.php,以便启动所有服务
|
||||
foreach(glob(__DIR__.'/Applications/*/start*.php') as $start_file)
|
||||
{
|
||||
require_once $start_file;
|
||||
}
|
||||
// 运行所有服务
|
||||
Worker::runAll();
|
|
@ -0,0 +1,7 @@
|
|||
#! /bin/bash
|
||||
|
||||
php ./start.php restart -d
|
||||
|
||||
php-fpm &
|
||||
|
||||
nginx -g 'daemon off;'
|
|
@ -0,0 +1,2 @@
|
|||
php Applications\YourApp\start_register.php Applications\YourApp\start_text_gateway.php php Applications\YourApp\start_web.php Applications\YourApp\start_gateway.php Applications\YourApp\start_businessworker.php
|
||||
pause
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
// autoload.php @generated by Composer
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit848e074079eb7d01a0bf7aba9ba31924::getLoader();
|
|
@ -0,0 +1,4 @@
|
|||
## Code of Conduct
|
||||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
||||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
||||
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
|
@ -0,0 +1,175 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
|
@ -0,0 +1 @@
|
|||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
@ -0,0 +1,117 @@
|
|||
# AWS Common Runtime PHP bindings
|
||||
|
||||
## Requirements
|
||||
|
||||
* PHP 5.5+ on UNIX platforms, 7.2+ on Windows
|
||||
* CMake 3.x
|
||||
* GCC 4.4+, clang 3.8+ on UNIX, Visual Studio build tools on Windows
|
||||
* Tests require [Composer](https://getcomposer.org)
|
||||
|
||||
## Installing with Composer and PECL
|
||||
|
||||
The package has two different package published to [composer](https://packagist.org/packages/aws/aws-crt-php) and [PECL](https://pecl.php.net/package/awscrt).
|
||||
|
||||
On UNIX, you can get the package from package manager or build from source:
|
||||
|
||||
```
|
||||
pecl install awscrt
|
||||
composer require aws/aws-crt-php
|
||||
```
|
||||
|
||||
On Windows, you need to build from source as instruction written below for the native extension `php_awscrt.dll` . And, follow https://www.php.net/manual/en/install.pecl.windows.php#install.pecl.windows.loading to load extension. After that:
|
||||
|
||||
```
|
||||
composer require aws/aws-crt-php
|
||||
```
|
||||
|
||||
## Building from Github source
|
||||
|
||||
```sh
|
||||
$ git clone --recursive https://github.com/awslabs/aws-crt-php.git
|
||||
$ cd aws-crt-php
|
||||
$ phpize
|
||||
$ ./configure
|
||||
$ make
|
||||
$ ./dev-scripts/run_tests.sh
|
||||
```
|
||||
|
||||
## Building on Windows
|
||||
|
||||
### Requirements for Windows
|
||||
|
||||
* Ensure you have the [windows PHP SDK](https://github.com/microsoft/php-sdk-binary-tools) (this example assumes installation of the SDK to C:\php-sdk and that you've checked out the PHP source to php-src within the build directory) and it works well on your machine.
|
||||
|
||||
* Ensure you have "Development package (SDK to develop PHP extensions)" and PHP available from your system path. You can download them from https://windows.php.net/download/. You can check if they are available by running `phpize -v` and `php -v`
|
||||
|
||||
### Instructions
|
||||
|
||||
From Command Prompt (not powershell). The instruction is based on Visual Studio 2019 on 64bit Windows.
|
||||
|
||||
```bat
|
||||
> git clone --recursive https://github.com/awslabs/aws-crt-php.git
|
||||
> git clone https://github.com/microsoft/php-sdk-binary-tools.git C:\php-sdk
|
||||
> C:\php-sdk\phpsdk-vs16-x64.bat
|
||||
|
||||
C:\php-sdk\
|
||||
$ cd <your-path-to-aws-crt-php>
|
||||
|
||||
<your-path-to-aws-crt-php>\
|
||||
$ phpize
|
||||
|
||||
# --with-prefix only required when your php runtime in system path is different than the runtime you wish to use.
|
||||
<your-path-to-aws-crt-php>\
|
||||
$ configure --enable-awscrt=shared --with-prefix=<your-path-to-php-prefix>
|
||||
|
||||
<your-path-to-aws-crt-php>\
|
||||
$ nmake
|
||||
|
||||
<your-path-to-aws-crt-php>\
|
||||
$ nmake generate-php-ini
|
||||
|
||||
# check .\php-win.ini, it now has the full path to php_awscrt.dll that you can manually load to your php runtime, or you can run the following command to run tests and load the required native extension for awscrt.
|
||||
<your-path-to-aws-crt-php>\
|
||||
$ .\dev-scripts\run_tests.bat <your-path-to-php-binary>
|
||||
```
|
||||
|
||||
Note: for VS2017, Cmake will default to build for Win32, refer to [here](https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2015%202017.html). If you are building for x64 php, you can set environment variable as follow to let cmake pick x64 compiler.
|
||||
|
||||
```bat
|
||||
set CMAKE_GENERATOR=Visual Studio 15 2017
|
||||
set CMAKE_GENERATOR_PLATFORM=x64
|
||||
```
|
||||
|
||||
## Debugging
|
||||
|
||||
Using [PHPBrew](https://github.com/phpbrew/phpbrew) to build/manage multiple versions of PHP is helpful.
|
||||
|
||||
Note: You must use a debug build of PHP to debug native extensions.
|
||||
See the [PHP Internals Book](https://www.phpinternalsbook.com/php7/build_system/building_php.html) for more info
|
||||
|
||||
```shell
|
||||
# PHP 8 example
|
||||
$ phpbrew install --stdout -j 8 8.0 +default -- CFLAGS=-Wno-error --disable-cgi --enable-debug
|
||||
# PHP 5.5 example
|
||||
$ phpbrew install --stdout -j 8 5.5 +default -openssl -mbstring -- CFLAGS="-w -Wno-error" --enable-debug --with-zlib=/usr/local/opt/zlib
|
||||
$ phpbrew switch php-8.0.6 # or whatever version is current, it'll be at the end of the build output
|
||||
$ phpize
|
||||
$ ./configure
|
||||
$ make CMAKE_BUILD_TYPE=Debug
|
||||
```
|
||||
|
||||
Ensure that the php you launch from your debugger is the result of `which php` , not just
|
||||
the system default php.
|
||||
|
||||
## Security
|
||||
|
||||
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
|
||||
|
||||
## Known OpenSSL related issue (Unix only)
|
||||
|
||||
* When your php loads a different version of openssl than your system openssl version, awscrt may fail to load or weirdly crash. You can find the openssl version php linked via: `php -i | grep 'OpenSSL'`, and awscrt linked from the build log, which will be `Found OpenSSL: * (found version *)`
|
||||
|
||||
The easiest workaround to those issue is to build from source and get aws-lc for awscrt to depend on instead.
|
||||
TO do that, same instructions as [here](#building-from-github-source), but use `USE_OPENSSL=OFF make` instead of `make`
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the Apache-2.0 License.
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name": "aws/aws-crt-php",
|
||||
"homepage": "https://github.com/awslabs/aws-crt-php",
|
||||
"description": "AWS Common Runtime for PHP",
|
||||
"keywords": ["aws","amazon","sdk","crt"],
|
||||
"type": "library",
|
||||
"authors": [
|
||||
{
|
||||
"name": "AWS SDK Common Runtime Team",
|
||||
"email": "aws-sdk-common-runtime@amazon.com"
|
||||
}
|
||||
],
|
||||
"minimum-stability": "alpha",
|
||||
"require": {
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit":"^4.8.35||^5.6.3||^9.5",
|
||||
"yoast/phpunit-polyfills": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"suggest": {
|
||||
"ext-awscrt": "Make sure you install awscrt native extension to use any of the functionality."
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./dev-scripts/run_tests.sh",
|
||||
"test-extension": "@test",
|
||||
"test-win": ".\\dev-scripts\\run_tests.bat"
|
||||
},
|
||||
"license": "Apache-2.0"
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
use AWS\CRT\Options as Options;
|
||||
|
||||
/**
|
||||
* Represents a set of AWS credentials
|
||||
*
|
||||
* @param array options:
|
||||
* - string access_key_id - AWS Access Key Id
|
||||
* - string secret_access_key - AWS Secret Access Key
|
||||
* - string session_token - Optional STS session token
|
||||
* - int expiration_timepoint_seconds - Optional time to expire these credentials
|
||||
*/
|
||||
final class AwsCredentials extends NativeResource {
|
||||
|
||||
static function defaults() {
|
||||
return [
|
||||
'access_key_id' => '',
|
||||
'secret_access_key' => '',
|
||||
'session_token' => '',
|
||||
'expiration_timepoint_seconds' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
private $access_key_id;
|
||||
private $secret_access_key;
|
||||
private $session_token;
|
||||
private $expiration_timepoint_seconds = 0;
|
||||
|
||||
public function __get($name) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
function __construct(array $options = []) {
|
||||
parent::__construct();
|
||||
|
||||
$options = new Options($options, self::defaults());
|
||||
$this->access_key_id = $options->access_key_id->asString();
|
||||
$this->secret_access_key = $options->secret_access_key->asString();
|
||||
$this->session_token = $options->session_token ? $options->session_token->asString() : null;
|
||||
$this->expiration_timepoint_seconds = $options->expiration_timepoint_seconds->asInt();
|
||||
|
||||
if (strlen($this->access_key_id) == 0) {
|
||||
throw new \InvalidArgumentException("access_key_id must be provided");
|
||||
}
|
||||
if (strlen($this->secret_access_key) == 0) {
|
||||
throw new \InvalidArgumentException("secret_access_key must be provided");
|
||||
}
|
||||
|
||||
$creds_options = self::$crt->aws_credentials_options_new();
|
||||
self::$crt->aws_credentials_options_set_access_key_id($creds_options, $this->access_key_id);
|
||||
self::$crt->aws_credentials_options_set_secret_access_key($creds_options, $this->secret_access_key);
|
||||
self::$crt->aws_credentials_options_set_session_token($creds_options, $this->session_token);
|
||||
self::$crt->aws_credentials_options_set_expiration_timepoint_seconds($creds_options, $this->expiration_timepoint_seconds);
|
||||
$this->acquire(self::$crt->aws_credentials_new($creds_options));
|
||||
self::$crt->aws_credentials_options_release($creds_options);
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
self::$crt->aws_credentials_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
|
||||
/**
|
||||
* Base class for credentials providers
|
||||
*/
|
||||
abstract class CredentialsProvider extends NativeResource {
|
||||
|
||||
function __construct(array $options = []) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
self::$crt->credentials_provider_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\IO\InputStream;
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
|
||||
class Signable extends NativeResource {
|
||||
|
||||
public static function fromHttpRequest($http_message) {
|
||||
return new Signable(function() use ($http_message) {
|
||||
return self::$crt->signable_new_from_http_request($http_message->native);
|
||||
});
|
||||
}
|
||||
|
||||
public static function fromChunk($chunk_stream, $previous_signature="") {
|
||||
if (!($chunk_stream instanceof InputStream)) {
|
||||
$chunk_stream = new InputStream($chunk_stream);
|
||||
}
|
||||
return new Signable(function() use($chunk_stream, $previous_signature) {
|
||||
return self::$crt->signable_new_from_chunk($chunk_stream->native, $previous_signature);
|
||||
});
|
||||
}
|
||||
|
||||
public static function fromCanonicalRequest($canonical_request) {
|
||||
return new Signable(function() use($canonical_request) {
|
||||
return self::$crt->signable_new_from_canonical_request($canonical_request);
|
||||
});
|
||||
}
|
||||
|
||||
protected function __construct($ctor) {
|
||||
parent::__construct();
|
||||
$this->acquire($ctor());
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
self::$crt->signable_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
class SignatureType {
|
||||
const HTTP_REQUEST_HEADERS = 0;
|
||||
const HTTP_REQUEST_QUERY_PARAMS = 1;
|
||||
const HTTP_REQUEST_CHUNK = 2;
|
||||
const HTTP_REQUEST_EVENT = 3;
|
||||
const CANONICAL_REQUEST_HEADERS = 4;
|
||||
const CANONICAL_REQUEST_QUERY_PARAMS = 5;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
class SignedBodyHeaderType {
|
||||
const NONE = 0;
|
||||
const X_AMZ_CONTENT_SHA256 = 1;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\NativeResource;
|
||||
|
||||
abstract class Signing extends NativeResource {
|
||||
static function signRequestAws($signable, $signing_config, $on_complete) {
|
||||
return self::$crt->sign_request_aws($signable->native, $signing_config->native,
|
||||
function($result, $error_code) use ($on_complete) {
|
||||
$signing_result = SigningResult::fromNative($result);
|
||||
$on_complete($signing_result, $error_code);
|
||||
}, null);
|
||||
}
|
||||
|
||||
static function testVerifySigV4ASigning($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) {
|
||||
return self::$crt->test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
class SigningAlgorithm {
|
||||
const SIGv4 = 0;
|
||||
const SIGv4_ASYMMETRIC = 1;
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
use AWS\CRT\Options as Options;
|
||||
|
||||
class SigningConfigAWS extends NativeResource {
|
||||
|
||||
public static function defaults() {
|
||||
return [
|
||||
'algorithm' => SigningAlgorithm::SIGv4,
|
||||
'signature_type' => SignatureType::HTTP_REQUEST_HEADERS,
|
||||
'credentials_provider' => null,
|
||||
'region' => null,
|
||||
'service' => null,
|
||||
'use_double_uri_encode' => false,
|
||||
'should_normalize_uri_path' => false,
|
||||
'omit_session_token' => false,
|
||||
'signed_body_value' => null,
|
||||
'signed_body_header_type' => SignedBodyHeaderType::NONE,
|
||||
'expiration_in_seconds' => 0,
|
||||
'date' => time(),
|
||||
'should_sign_header' => null,
|
||||
];
|
||||
}
|
||||
|
||||
private $options;
|
||||
|
||||
public function __construct(array $options = []) {
|
||||
parent::__construct();
|
||||
$this->options = $options = new Options($options, self::defaults());
|
||||
$sc = $this->acquire(self::$crt->signing_config_aws_new());
|
||||
self::$crt->signing_config_aws_set_algorithm($sc, $options->algorithm->asInt());
|
||||
self::$crt->signing_config_aws_set_signature_type($sc, $options->signature_type->asInt());
|
||||
if ($credentials_provider = $options->credentials_provider->asObject()) {
|
||||
self::$crt->signing_config_aws_set_credentials_provider(
|
||||
$sc,
|
||||
$credentials_provider->native);
|
||||
}
|
||||
self::$crt->signing_config_aws_set_region(
|
||||
$sc, $options->region->asString());
|
||||
self::$crt->signing_config_aws_set_service(
|
||||
$sc, $options->service->asString());
|
||||
self::$crt->signing_config_aws_set_use_double_uri_encode(
|
||||
$sc, $options->use_double_uri_encode->asBool());
|
||||
self::$crt->signing_config_aws_set_should_normalize_uri_path(
|
||||
$sc, $options->should_normalize_uri_path->asBool());
|
||||
self::$crt->signing_config_aws_set_omit_session_token(
|
||||
$sc, $options->omit_session_token->asBool());
|
||||
self::$crt->signing_config_aws_set_signed_body_value(
|
||||
$sc, $options->signed_body_value->asString());
|
||||
self::$crt->signing_config_aws_set_signed_body_header_type(
|
||||
$sc, $options->signed_body_header_type->asInt());
|
||||
self::$crt->signing_config_aws_set_expiration_in_seconds(
|
||||
$sc, $options->expiration_in_seconds->asInt());
|
||||
self::$crt->signing_config_aws_set_date($sc, $options->date->asInt());
|
||||
if ($should_sign_header = $options->should_sign_header->asCallable()) {
|
||||
self::$crt->signing_config_aws_set_should_sign_header_fn($sc, $should_sign_header);
|
||||
}
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
self::$crt->signing_config_aws_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return $this->options->get($name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
use AWS\CRT\NativeResource;
|
||||
use AWS\CRT\HTTP\Request;
|
||||
|
||||
class SigningResult extends NativeResource {
|
||||
protected function __construct($native) {
|
||||
parent::__construct();
|
||||
|
||||
$this->acquire($native);
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
// No destruction necessary, SigningResults are transient, just release
|
||||
$this->release();
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public static function fromNative($ptr) {
|
||||
return new SigningResult($ptr);
|
||||
}
|
||||
|
||||
public function applyToHttpRequest(&$http_request) {
|
||||
self::$crt->signing_result_apply_to_http_request($this->native, $http_request->native);
|
||||
// Update http_request from native
|
||||
$http_request = Request::unmarshall($http_request->toBlob());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Auth;
|
||||
|
||||
/**
|
||||
* Provides a static set of AWS credentials
|
||||
*
|
||||
* @param array options:
|
||||
* - string access_key_id - AWS Access Key Id
|
||||
* - string secret_access_key - AWS Secret Access Key
|
||||
* - string session_token - Optional STS session token
|
||||
*/
|
||||
final class StaticCredentialsProvider extends CredentialsProvider {
|
||||
|
||||
private $credentials;
|
||||
|
||||
public function __get($name) {
|
||||
return $this->$name;
|
||||
}
|
||||
|
||||
function __construct(array $options = []) {
|
||||
parent::__construct();
|
||||
$this->credentials = new AwsCredentials($options);
|
||||
|
||||
$provider_options = self::$crt->credentials_provider_static_options_new();
|
||||
self::$crt->credentials_provider_static_options_set_access_key_id($provider_options, $this->credentials->access_key_id);
|
||||
self::$crt->credentials_provider_static_options_set_secret_access_key($provider_options, $this->credentials->secret_access_key);
|
||||
self::$crt->credentials_provider_static_options_set_session_token($provider_options, $this->credentials->session_token);
|
||||
$this->acquire(self::$crt->credentials_provider_static_new($provider_options));
|
||||
self::$crt->credentials_provider_static_options_release($provider_options);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,358 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT;
|
||||
|
||||
use AWS\CRT\Internal\Extension;
|
||||
|
||||
use \RuntimeException;
|
||||
|
||||
/**
|
||||
* Wrapper for the interface to the CRT. There only ever needs to be one of these, but
|
||||
* additional instances won't cost anything other than their memory.
|
||||
* Creating an instance of any NativeResource will activate the CRT binding. User code
|
||||
* should only need to create one of these if they are only accessing CRT:: static functions.
|
||||
*/
|
||||
final class CRT {
|
||||
|
||||
private static $impl = null;
|
||||
private static $refcount = 0;
|
||||
|
||||
function __construct() {
|
||||
if (is_null(self::$impl)) {
|
||||
try {
|
||||
self::$impl = new Extension();
|
||||
} catch (RuntimeException $rex) {
|
||||
throw new RuntimeException("Unable to initialize AWS CRT via awscrt extension: \n$rex", -1);
|
||||
}
|
||||
}
|
||||
++self::$refcount;
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
if (--self::$refcount == 0) {
|
||||
self::$impl = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool whether or not the CRT is currently loaded
|
||||
*/
|
||||
public static function isLoaded() {
|
||||
return !is_null(self::$impl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool whether or not the CRT is available via one of the possible backends
|
||||
*/
|
||||
public static function isAvailable() {
|
||||
try {
|
||||
new CRT();
|
||||
return true;
|
||||
} catch (RuntimeException $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer last error code reported within the CRT
|
||||
*/
|
||||
public static function last_error() {
|
||||
return self::$impl->aws_crt_last_error();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
|
||||
* @return string Human-readable description of the provided error code
|
||||
*/
|
||||
public static function error_str($error) {
|
||||
return self::$impl->aws_crt_error_str((int) $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $error Error code from the CRT, usually delivered via callback or {@see last_error}
|
||||
* @return string Name/enum identifier for the provided error code
|
||||
*/
|
||||
public static function error_name($error) {
|
||||
return self::$impl->aws_crt_error_name((int) $error);
|
||||
}
|
||||
|
||||
public static function log_to_stdout() {
|
||||
return self::$impl->aws_crt_log_to_stdout();
|
||||
}
|
||||
|
||||
public static function log_to_stderr() {
|
||||
return self::$impl->aws_crt_log_to_stderr();
|
||||
}
|
||||
|
||||
public static function log_to_file($filename) {
|
||||
return self::$impl->aws_crt_log_to_file($filename);
|
||||
}
|
||||
|
||||
public static function log_to_stream($stream) {
|
||||
return self::$impl->aws_crt_log_to_stream($stream);
|
||||
}
|
||||
|
||||
public static function log_set_level($level) {
|
||||
return self::$impl->aws_crt_log_set_level($level);
|
||||
}
|
||||
|
||||
public static function log_stop() {
|
||||
return self::$impl->aws_crt_log_stop();
|
||||
}
|
||||
|
||||
public static function log_message($level, $message) {
|
||||
return self::$impl->aws_crt_log_message($level, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object Pointer to native event_loop_group_options
|
||||
*/
|
||||
function event_loop_group_options_new() {
|
||||
return self::$impl->aws_crt_event_loop_group_options_new();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $elg_options Pointer to native event_loop_group_options
|
||||
*/
|
||||
function event_loop_group_options_release($elg_options) {
|
||||
self::$impl->aws_crt_event_loop_group_options_release($elg_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $elg_options Pointer to native event_loop_group_options
|
||||
* @param integer $max_threads Maximum number of threads to allow the event loop group to use, default: 0/1 per CPU core
|
||||
*/
|
||||
function event_loop_group_options_set_max_threads($elg_options, $max_threads) {
|
||||
self::$impl->aws_crt_event_loop_group_options_set_max_threads($elg_options, (int)$max_threads);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object Pointer to event_loop_group_options, {@see event_loop_group_options_new}
|
||||
* @return object Pointer to the new event loop group
|
||||
*/
|
||||
function event_loop_group_new($options) {
|
||||
return self::$impl->aws_crt_event_loop_group_new($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $elg Pointer to the event loop group to release
|
||||
*/
|
||||
function event_loop_group_release($elg) {
|
||||
self::$impl->aws_crt_event_loop_group_release($elg);
|
||||
}
|
||||
|
||||
/**
|
||||
* return object Pointer to native AWS credentials options
|
||||
*/
|
||||
function aws_credentials_options_new() {
|
||||
return self::$impl->aws_crt_credentials_options_new();
|
||||
}
|
||||
|
||||
function aws_credentials_options_release($options) {
|
||||
self::$impl->aws_crt_credentials_options_release($options);
|
||||
}
|
||||
|
||||
function aws_credentials_options_set_access_key_id($options, $access_key_id) {
|
||||
self::$impl->aws_crt_credentials_options_set_access_key_id($options, $access_key_id);
|
||||
}
|
||||
|
||||
function aws_credentials_options_set_secret_access_key($options, $secret_access_key) {
|
||||
self::$impl->aws_crt_credentials_options_set_secret_access_key($options, $secret_access_key);
|
||||
}
|
||||
|
||||
function aws_credentials_options_set_session_token($options, $session_token) {
|
||||
self::$impl->aws_crt_credentials_options_set_session_token($options, $session_token);
|
||||
}
|
||||
|
||||
function aws_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds) {
|
||||
self::$impl->aws_crt_credentials_options_set_expiration_timepoint_seconds($options, $expiration_timepoint_seconds);
|
||||
}
|
||||
|
||||
function aws_credentials_new($options) {
|
||||
return self::$impl->aws_crt_credentials_new($options);
|
||||
}
|
||||
|
||||
function aws_credentials_release($credentials) {
|
||||
self::$impl->aws_crt_credentials_release($credentials);
|
||||
}
|
||||
|
||||
function credentials_provider_release($provider) {
|
||||
self::$impl->aws_crt_credentials_provider_release($provider);
|
||||
}
|
||||
|
||||
function credentials_provider_static_options_new() {
|
||||
return self::$impl->aws_crt_credentials_provider_static_options_new();
|
||||
}
|
||||
|
||||
function credentials_provider_static_options_release($options) {
|
||||
self::$impl->aws_crt_credentials_provider_static_options_release($options);
|
||||
}
|
||||
|
||||
function credentials_provider_static_options_set_access_key_id($options, $access_key_id) {
|
||||
self::$impl->aws_crt_credentials_provider_static_options_set_access_key_id($options, $access_key_id);
|
||||
}
|
||||
|
||||
function credentials_provider_static_options_set_secret_access_key($options, $secret_access_key) {
|
||||
self::$impl->aws_crt_credentials_provider_static_options_set_secret_access_key($options, $secret_access_key);
|
||||
}
|
||||
|
||||
function credentials_provider_static_options_set_session_token($options, $session_token) {
|
||||
self::$impl->aws_crt_credentials_provider_static_options_set_session_token($options, $session_token);
|
||||
}
|
||||
|
||||
function credentials_provider_static_new($options) {
|
||||
return self::$impl->aws_crt_credentials_provider_static_new($options);
|
||||
}
|
||||
|
||||
function input_stream_options_new() {
|
||||
return self::$impl->aws_crt_input_stream_options_new();
|
||||
}
|
||||
|
||||
function input_stream_options_release($options) {
|
||||
self::$impl->aws_crt_input_stream_options_release($options);
|
||||
}
|
||||
|
||||
function input_stream_options_set_user_data($options, $user_data) {
|
||||
self::$impl->aws_crt_input_stream_options_set_user_data($options, $user_data);
|
||||
}
|
||||
|
||||
function input_stream_new($options) {
|
||||
return self::$impl->aws_crt_input_stream_new($options);
|
||||
}
|
||||
|
||||
function input_stream_release($stream) {
|
||||
self::$impl->aws_crt_input_stream_release($stream);
|
||||
}
|
||||
|
||||
function input_stream_seek($stream, $offset, $basis) {
|
||||
return self::$impl->aws_crt_input_stream_seek($stream, $offset, $basis);
|
||||
}
|
||||
|
||||
function input_stream_read($stream, $length) {
|
||||
return self::$impl->aws_crt_input_stream_read($stream, $length);
|
||||
}
|
||||
|
||||
function input_stream_eof($stream) {
|
||||
return self::$impl->aws_crt_input_stream_eof($stream);
|
||||
}
|
||||
|
||||
function input_stream_get_length($stream) {
|
||||
return self::$impl->aws_crt_input_stream_get_length($stream);
|
||||
}
|
||||
|
||||
function http_message_new_from_blob($blob) {
|
||||
return self::$impl->aws_crt_http_message_new_from_blob($blob);
|
||||
}
|
||||
|
||||
function http_message_to_blob($message) {
|
||||
return self::$impl->aws_crt_http_message_to_blob($message);
|
||||
}
|
||||
|
||||
function http_message_release($message) {
|
||||
self::$impl->aws_crt_http_message_release($message);
|
||||
}
|
||||
|
||||
function signing_config_aws_new() {
|
||||
return self::$impl->aws_crt_signing_config_aws_new();
|
||||
}
|
||||
|
||||
function signing_config_aws_release($signing_config) {
|
||||
return self::$impl->aws_crt_signing_config_aws_release($signing_config);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_algorithm($signing_config, $algorithm) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_algorithm($signing_config, (int)$algorithm);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_signature_type($signing_config, $signature_type) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_signature_type($signing_config, (int)$signature_type);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_credentials_provider($signing_config, $credentials_provider) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_credentials_provider($signing_config, $credentials_provider);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_region($signing_config, $region) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_region($signing_config, $region);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_service($signing_config, $service) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_service($signing_config, $service);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_use_double_uri_encode($signing_config, $use_double_uri_encode);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_should_normalize_uri_path($signing_config, $should_normalize_uri_path);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_omit_session_token($signing_config, $omit_session_token) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_omit_session_token($signing_config, $omit_session_token);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_signed_body_value($signing_config, $signed_body_value) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_signed_body_value($signing_config, $signed_body_value);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_signed_body_header_type($signing_config, $signed_body_header_type);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_expiration_in_seconds($signing_config, $expiration_in_seconds);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_date($signing_config, $timestamp) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_date($signing_config, $timestamp);
|
||||
}
|
||||
|
||||
function signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn) {
|
||||
self::$impl->aws_crt_signing_config_aws_set_should_sign_header_fn($signing_config, $should_sign_header_fn);
|
||||
}
|
||||
|
||||
function signable_new_from_http_request($http_message) {
|
||||
return self::$impl->aws_crt_signable_new_from_http_request($http_message);
|
||||
}
|
||||
|
||||
function signable_new_from_chunk($chunk_stream, $previous_signature) {
|
||||
return self::$impl->aws_crt_signable_new_from_chunk($chunk_stream, $previous_signature);
|
||||
}
|
||||
|
||||
function signable_new_from_canonical_request($canonical_request) {
|
||||
return self::$impl->aws_crt_signable_new_from_canonical_request($canonical_request);
|
||||
}
|
||||
|
||||
function signable_release($signable) {
|
||||
self::$impl->aws_crt_signable_release($signable);
|
||||
}
|
||||
|
||||
function signing_result_release($signing_result) {
|
||||
self::$impl->aws_crt_signing_result_release($signing_result);
|
||||
}
|
||||
|
||||
function signing_result_apply_to_http_request($signing_result, $http_message) {
|
||||
return self::$impl->aws_crt_signing_result_apply_to_http_request(
|
||||
$signing_result, $http_message);
|
||||
}
|
||||
|
||||
function sign_request_aws($signable, $signing_config, $on_complete, $user_data) {
|
||||
return self::$impl->aws_crt_sign_request_aws($signable, $signing_config, $on_complete, $user_data);
|
||||
}
|
||||
|
||||
function test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y) {
|
||||
return self::$impl->aws_crt_test_verify_sigv4a_signing($signable, $signing_config, $expected_canonical_request, $signature, $ecc_key_pub_x, $ecc_key_pub_y);
|
||||
}
|
||||
|
||||
public static function crc32($input, $previous = 0) {
|
||||
return self::$impl->aws_crt_crc32($input, $previous);
|
||||
}
|
||||
|
||||
public static function crc32c($input, $previous = 0) {
|
||||
return self::$impl->aws_crt_crc32c($input, $previous);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\Internal\Encoding;
|
||||
|
||||
final class Headers {
|
||||
private $headers;
|
||||
|
||||
public function __construct($headers = []) {
|
||||
$this->headers = $headers;
|
||||
}
|
||||
|
||||
public static function marshall($headers) {
|
||||
$buf = "";
|
||||
foreach ($headers->headers as $header => $value) {
|
||||
$buf .= Encoding::encodeString($header);
|
||||
$buf .= Encoding::encodeString($value);
|
||||
}
|
||||
return $buf;
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
$strings = Encoding::readStrings($buf);
|
||||
$headers = [];
|
||||
for ($idx = 0; $idx < count($strings);) {
|
||||
$headers[$strings[$idx++]] = $strings[$idx++];
|
||||
}
|
||||
return new Headers($headers);
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->headers);
|
||||
}
|
||||
|
||||
public function get($header) {
|
||||
return isset($this->headers[$header]) ? $this->headers[$header] : null;
|
||||
}
|
||||
|
||||
public function set($header, $value) {
|
||||
$this->headers[$header] = $value;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\NativeResource;
|
||||
use AWS\CRT\Internal\Encoding;
|
||||
|
||||
abstract class Message extends NativeResource {
|
||||
private $method;
|
||||
private $path;
|
||||
private $query;
|
||||
private $headers;
|
||||
|
||||
public function __construct($method, $path, $query = [], $headers = []) {
|
||||
parent::__construct();
|
||||
$this->method = $method;
|
||||
$this->path = $path;
|
||||
$this->query = $query;
|
||||
$this->headers = new Headers($headers);
|
||||
$this->acquire(self::$crt->http_message_new_from_blob(self::marshall($this)));
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
self::$crt->http_message_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function toBlob() {
|
||||
return self::$crt->http_message_to_blob($this->native);
|
||||
}
|
||||
|
||||
protected static function marshall($msg) {
|
||||
$buf = "";
|
||||
$buf .= Encoding::encodeString($msg->method);
|
||||
$buf .= Encoding::encodeString($msg->pathAndQuery());
|
||||
$buf .= Headers::marshall($msg->headers);
|
||||
return $buf;
|
||||
}
|
||||
|
||||
protected static function _unmarshall($buf, $class=Message::class) {
|
||||
$method = Encoding::readString($buf);
|
||||
$path_and_query = Encoding::readString($buf);
|
||||
$parts = explode("?", $path_and_query, 2);
|
||||
$path = isset($parts[0]) ? $parts[0] : "";
|
||||
$query = isset($parts[1]) ? $parts[1] : "";
|
||||
$headers = Headers::unmarshall($buf);
|
||||
|
||||
// Turn query params back into a dictionary
|
||||
if (strlen($query)) {
|
||||
$query = rawurldecode($query);
|
||||
$query = explode("&", $query);
|
||||
$query = array_reduce($query, function($params, $pair) {
|
||||
list($param, $value) = explode("=", $pair, 2);
|
||||
$params[$param] = $value;
|
||||
return $params;
|
||||
}, []);
|
||||
} else {
|
||||
$query = [];
|
||||
}
|
||||
|
||||
return new $class($method, $path, $query, $headers->toArray());
|
||||
}
|
||||
|
||||
public function pathAndQuery() {
|
||||
$path = $this->path;
|
||||
$queries = [];
|
||||
foreach ($this->query as $param => $value) {
|
||||
$queries []= urlencode($param) . "=" . urlencode($value);
|
||||
}
|
||||
$query = implode("&", $queries);
|
||||
if (strlen($query)) {
|
||||
$path = implode("?", [$path, $query]);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
public function method() {
|
||||
return $this->method;
|
||||
}
|
||||
|
||||
public function path() {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function query() {
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
public function headers() {
|
||||
return $this->headers;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
use AWS\CRT\IO\InputStream;
|
||||
|
||||
class Request extends Message {
|
||||
private $body_stream = null;
|
||||
|
||||
public function __construct($method, $path, $query = [], $headers = [], $body_stream = null) {
|
||||
parent::__construct($method, $path, $query, $headers);
|
||||
if (!is_null($body_stream) && !($body_stream instanceof InputStream)) {
|
||||
throw new \InvalidArgumentException('body_stream must be an instance of ' . InputStream::class);
|
||||
}
|
||||
$this->body_stream = $body_stream;
|
||||
}
|
||||
|
||||
public static function marshall($request) {
|
||||
return parent::marshall($request);
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
return parent::_unmarshall($buf, Request::class);
|
||||
}
|
||||
|
||||
public function body_stream() {
|
||||
return $this->body_stream;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\HTTP;
|
||||
|
||||
class Response extends Message {
|
||||
private $status_code;
|
||||
|
||||
public function __construct($method, $path, $query, $headers, $status_code) {
|
||||
parent::__construct($method, $path, $query, $headers);
|
||||
$this->status_code = $status_code;
|
||||
}
|
||||
|
||||
public static function marshall($response) {
|
||||
return parent::marshall($response);
|
||||
}
|
||||
|
||||
public static function unmarshall($buf) {
|
||||
return parent::_unmarshall($buf, Response::class);
|
||||
}
|
||||
|
||||
public function status_code() {
|
||||
return $this->status_code;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\IO;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
use AWS\CRT\Options as Options;
|
||||
|
||||
/**
|
||||
* Represents 1 or more event loops (1 per thread) for doing I/O and background tasks.
|
||||
* Typically, every application has one EventLoopGroup.
|
||||
*
|
||||
* @param array options:
|
||||
* - int num_threads - Number of worker threads in the EventLoopGroup. Defaults to 0/1 per logical core.
|
||||
*/
|
||||
final class EventLoopGroup extends NativeResource {
|
||||
|
||||
static function defaults() {
|
||||
return [
|
||||
'max_threads' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
function __construct(array $options = []) {
|
||||
parent::__construct();
|
||||
$options = new Options($options, self::defaults());
|
||||
$elg_options = self::$crt->event_loop_group_options_new();
|
||||
self::$crt->event_loop_group_options_set_max_threads($elg_options, $options->getInt('max_threads'));
|
||||
$this->acquire(self::$crt->event_loop_group_new($elg_options));
|
||||
self::$crt->event_loop_group_options_release($elg_options);
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
self::$crt->event_loop_group_release($this->release());
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\IO;
|
||||
|
||||
use AWS\CRT\NativeResource as NativeResource;
|
||||
|
||||
final class InputStream extends NativeResource {
|
||||
private $stream = null;
|
||||
|
||||
const SEEK_BEGIN = 0;
|
||||
const SEEK_END = 2;
|
||||
|
||||
public function __construct($stream) {
|
||||
parent::__construct();
|
||||
$this->stream = $stream;
|
||||
$options = self::$crt->input_stream_options_new();
|
||||
// The stream implementation in native just converts the PHP stream into
|
||||
// a native php_stream* and executes operations entirely in native
|
||||
self::$crt->input_stream_options_set_user_data($options, $stream);
|
||||
$this->acquire(self::$crt->input_stream_new($options));
|
||||
self::$crt->input_stream_options_release($options);
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->release();
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function eof() {
|
||||
return self::$crt->input_stream_eof($this->native);
|
||||
}
|
||||
|
||||
public function length() {
|
||||
return self::$crt->input_stream_get_length($this->native);
|
||||
}
|
||||
|
||||
public function read($length = 0) {
|
||||
if ($length == 0) {
|
||||
$length = $this->length();
|
||||
}
|
||||
return self::$crt->input_stream_read($this->native, $length);
|
||||
}
|
||||
|
||||
public function seek($offset, $basis) {
|
||||
return self::$crt->input_stream_seek($this->native, $offset, $basis);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Internal;
|
||||
|
||||
final class Encoding {
|
||||
public static function readString(&$buffer) {
|
||||
list($len, $str) = self::decodeString($buffer);
|
||||
// Advance by sizeof(length) + strlen(str)
|
||||
$buffer = substr($buffer, 4 + $len);
|
||||
return $str;
|
||||
}
|
||||
|
||||
public static function readStrings($buffer) {
|
||||
$strings = [];
|
||||
while (strlen($buffer)) {
|
||||
$strings []= self::readString($buffer);
|
||||
}
|
||||
return $strings;
|
||||
}
|
||||
|
||||
public static function decodeString($buffer) {
|
||||
$len = unpack("N", $buffer)[1];
|
||||
$buffer = substr($buffer, 4);
|
||||
$str = unpack("a{$len}", $buffer)[1];
|
||||
return [$len, $str];
|
||||
}
|
||||
|
||||
public static function encodeString($str) {
|
||||
if (is_array($str)) {
|
||||
$str = $str[0];
|
||||
}
|
||||
return pack("Na*", strlen($str), $str);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT\Internal;
|
||||
|
||||
use \RuntimeException;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Forwards calls on to awscrt PHP extension functions
|
||||
*/
|
||||
final class Extension {
|
||||
function __construct() {
|
||||
if (!extension_loaded('awscrt')) {
|
||||
throw new RuntimeException('awscrt extension is not loaded');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards any call made on this object to the extension function of the
|
||||
* same name with the supplied arguments. Argument type hinting and checking
|
||||
* occurs at the CRT wrapper.
|
||||
*/
|
||||
function __call($name, $args) {
|
||||
return call_user_func_array($name, $args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT;
|
||||
use AWS\CRT\CRT;
|
||||
|
||||
final class Log {
|
||||
const NONE = 0;
|
||||
const FATAL = 1;
|
||||
const ERROR = 2;
|
||||
const WARN = 3;
|
||||
const INFO = 4;
|
||||
const DEBUG = 5;
|
||||
const TRACE = 6;
|
||||
|
||||
public static function toStdout() {
|
||||
CRT::log_to_stdout();
|
||||
}
|
||||
|
||||
public static function toStderr() {
|
||||
CRT::log_to_stderr();
|
||||
}
|
||||
|
||||
public static function toFile($filename) {
|
||||
CRT::log_to_file($filename);
|
||||
}
|
||||
|
||||
public static function toStream($stream) {
|
||||
assert(get_resource_type($stream) == "stream");
|
||||
CRT::log_to_stream($stream);
|
||||
}
|
||||
|
||||
public static function stop() {
|
||||
CRT::log_stop();
|
||||
}
|
||||
|
||||
public static function setLogLevel($level) {
|
||||
assert($level >= self::NONE && $level <= self::TRACE);
|
||||
CRT::log_set_level($level);
|
||||
}
|
||||
|
||||
public static function log($level, $message) {
|
||||
CRT::log_message($level, $message);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT;
|
||||
|
||||
use AWS\CRT\CRT as CRT;
|
||||
|
||||
/**
|
||||
* Base class for all native resources, tracks all outstanding resources
|
||||
* and provides basic leak checking
|
||||
*/
|
||||
abstract class NativeResource {
|
||||
protected static $crt = null;
|
||||
protected static $resources = [];
|
||||
protected $native = null;
|
||||
|
||||
protected function __construct() {
|
||||
if (is_null(self::$crt)) {
|
||||
self::$crt = new CRT();
|
||||
}
|
||||
|
||||
self::$resources[spl_object_hash($this)] = 1;
|
||||
}
|
||||
|
||||
protected function acquire($handle) {
|
||||
return $this->native = $handle;
|
||||
}
|
||||
|
||||
protected function release() {
|
||||
$native = $this->native;
|
||||
$this->native = null;
|
||||
return $native;
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
// Should have been destroyed and released by derived resource
|
||||
assert($this->native == null);
|
||||
unset(self::$resources[spl_object_hash($this)]);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0.
|
||||
*/
|
||||
namespace AWS\CRT;
|
||||
|
||||
final class OptionValue {
|
||||
private $value;
|
||||
function __construct($value) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function asObject() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function asMixed() {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function asInt() {
|
||||
return empty($this->value) ? 0 : (int)$this->value;
|
||||
}
|
||||
|
||||
public function asBool() {
|
||||
return boolval($this->value);
|
||||
}
|
||||
|
||||
public function asString() {
|
||||
return !empty($this->value) ? strval($this->value) : "";
|
||||
}
|
||||
|
||||
public function asArray() {
|
||||
return is_array($this->value) ? $this->value : (!empty($this->value) ? [$this->value] : []);
|
||||
}
|
||||
|
||||
public function asCallable() {
|
||||
return is_callable($this->value) ? $this->value : null;
|
||||
}
|
||||
}
|
||||
|
||||
final class Options {
|
||||
private $options;
|
||||
|
||||
public function __construct($opts = [], $defaults = []) {
|
||||
$this->options = array_replace($defaults, empty($opts) ? [] : $opts);
|
||||
}
|
||||
|
||||
public function __get($name) {
|
||||
return $this->get($name);
|
||||
}
|
||||
|
||||
public function asArray() {
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return array_merge_recursive([], $this->options);
|
||||
}
|
||||
|
||||
public function get($name) {
|
||||
return new OptionValue($this->options[$name]);
|
||||
}
|
||||
|
||||
public function getInt($name) {
|
||||
return $this->get($name)->asInt();
|
||||
}
|
||||
|
||||
public function getString($name) {
|
||||
return $this->get($name)->asString();
|
||||
}
|
||||
|
||||
public function getBool($name) {
|
||||
return $this->get($name)->asBool();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
## Code of Conduct
|
||||
This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
|
||||
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
|
||||
opensource-codeofconduct@amazon.com with any additional questions or comments.
|
|
@ -0,0 +1,4 @@
|
|||
## Building and enabling the Common Run Time
|
||||
|
||||
1. **Follow instructions on crt repo** – Clone and build the repo as shown [here][https://github.com/awslabs/aws-crt-php].
|
||||
1. **Enable the CRT** – add the following line to your php.ini file `extension=path/to/aws-crt-php/modules/awscrt.so`
|
|
@ -0,0 +1,141 @@
|
|||
# Apache License
|
||||
Version 2.0, January 2004
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
## 1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1
|
||||
through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the
|
||||
License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled
|
||||
by, or are under common control with that entity. For the purposes of this definition, "control" means
|
||||
(i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract
|
||||
or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
|
||||
ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including but not limited to software
|
||||
source code, documentation source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form,
|
||||
including but not limited to compiled object code, generated documentation, and conversions to other media
|
||||
types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License,
|
||||
as indicated by a copyright notice that is included in or attached to the work (an example is provided in the
|
||||
Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from)
|
||||
the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent,
|
||||
as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not
|
||||
include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work
|
||||
and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version of the Work and any
|
||||
modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to
|
||||
Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to
|
||||
submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of
|
||||
electronic, verbal, or written communication sent to the Licensor or its representatives, including but not
|
||||
limited to communication on electronic mailing lists, source code control systems, and issue tracking systems
|
||||
that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been
|
||||
received by Licensor and subsequently incorporated within the Work.
|
||||
|
||||
## 2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare
|
||||
Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
## 3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
||||
license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such
|
||||
license applies only to those patent claims licensable by such Contributor that are necessarily infringed by
|
||||
their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such
|
||||
Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim
|
||||
or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work
|
||||
constitutes direct or contributory patent infringement, then any patent licenses granted to You under this
|
||||
License for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
## 4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You meet the following conditions:
|
||||
|
||||
1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
||||
|
||||
2. You must cause any modified files to carry prominent notices stating that You changed the files; and
|
||||
|
||||
3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent,
|
||||
trademark, and attribution notices from the Source form of the Work, excluding those notices that do
|
||||
not pertain to any part of the Derivative Works; and
|
||||
|
||||
4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that
|
||||
You distribute must include a readable copy of the attribution notices contained within such NOTICE
|
||||
file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed as part of the Derivative Works; within
|
||||
the Source form or documentation, if provided along with the Derivative Works; or, within a display
|
||||
generated by the Derivative Works, if and wherever such third-party notices normally appear. The
|
||||
contents of the NOTICE file are for informational purposes only and do not modify the License. You may
|
||||
add Your own attribution notices within Derivative Works that You distribute, alongside or as an
|
||||
addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be
|
||||
construed as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and may provide additional or different license
|
||||
terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative
|
||||
Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the
|
||||
conditions stated in this License.
|
||||
|
||||
## 5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by
|
||||
You to the Licensor shall be under the terms and conditions of this License, without any additional terms or
|
||||
conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate
|
||||
license agreement you may have executed with Licensor regarding such Contributions.
|
||||
|
||||
## 6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks, service marks, or product names of
|
||||
the Licensor, except as required for reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
## 7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor
|
||||
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
||||
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
## 8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless
|
||||
required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any
|
||||
Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential
|
||||
damages of any character arising as a result of this License or out of the use or inability to use the Work
|
||||
(including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has been advised of the possibility
|
||||
of such damages.
|
||||
|
||||
## 9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
||||
acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole
|
||||
responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold
|
||||
each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
|
@ -0,0 +1,17 @@
|
|||
# AWS SDK for PHP
|
||||
|
||||
<http://aws.amazon.com/php>
|
||||
|
||||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License").
|
||||
You may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,84 @@
|
|||
The AWS SDK for PHP includes the following third-party software/licensing:
|
||||
|
||||
|
||||
** Guzzle - https://github.com/guzzle/guzzle
|
||||
|
||||
Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
----------------
|
||||
|
||||
** jmespath.php - https://github.com/mtdowling/jmespath.php
|
||||
|
||||
Copyright (c) 2014 Michael Dowling, https://github.com/mtdowling
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
----------------
|
||||
|
||||
** phpunit-mock-objects -- https://github.com/sebastianbergmann/phpunit-mock-objects
|
||||
|
||||
Copyright (c) 2002-2018, Sebastian Bergmann <sebastian@phpunit.de>.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
* Neither the name of Sebastian Bergmann nor the names of his
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,74 @@
|
|||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
"homepage": "http://aws.amazon.com/sdkforphp",
|
||||
"description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
|
||||
"keywords": ["aws","amazon","sdk","s3","ec2","dynamodb","cloud","glacier"],
|
||||
"type": "library",
|
||||
"license": "Apache-2.0",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Amazon Web Services",
|
||||
"homepage": "http://aws.amazon.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
|
||||
"issues": "https://github.com/aws/aws-sdk-php/issues"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.5",
|
||||
"guzzlehttp/guzzle": "^6.5.8 || ^7.4.5",
|
||||
"guzzlehttp/psr7": "^1.9.1 || ^2.4.5",
|
||||
"guzzlehttp/promises": "^1.4.0 || ^2.0",
|
||||
"mtdowling/jmespath.php": "^2.6",
|
||||
"ext-pcre": "*",
|
||||
"ext-json": "*",
|
||||
"ext-simplexml": "*",
|
||||
"aws/aws-crt-php": "^1.2.3",
|
||||
"psr/http-message": "^1.0 || ^2.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer" : "^1.10.22",
|
||||
"ext-openssl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-pcntl": "*",
|
||||
"ext-sockets": "*",
|
||||
"phpunit/phpunit": "^5.6.3 || ^8.5 || ^9.5",
|
||||
"behat/behat": "~3.0",
|
||||
"doctrine/cache": "~1.4",
|
||||
"aws/aws-php-sns-message-validator": "~1.0",
|
||||
"nette/neon": "^2.3",
|
||||
"andrewsville/php-token-reflection": "^1.4",
|
||||
"psr/cache": "^1.0",
|
||||
"psr/simple-cache": "^1.0",
|
||||
"paragonie/random_compat": ">= 2",
|
||||
"sebastian/comparator": "^1.2.3 || ^4.0",
|
||||
"yoast/phpunit-polyfills": "^1.0",
|
||||
"dms/phpunit-arraysubset-asserts": "^0.4.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
|
||||
"ext-curl": "To send requests using cURL",
|
||||
"ext-sockets": "To use client-side monitoring",
|
||||
"doctrine/cache": "To use the DoctrineCacheAdapter",
|
||||
"aws/aws-php-sns-message-validator": "To validate incoming SNS notifications"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Aws\\": "src/"
|
||||
},
|
||||
"files": ["src/functions.php"]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Aws\\Test\\": "tests/"
|
||||
},
|
||||
"classmap": ["build/"]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
namespace Aws\ACMPCA;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS Certificate Manager Private Certificate Authority** service.
|
||||
* @method \Aws\Result createCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result createCertificateAuthorityAuditReport(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createCertificateAuthorityAuditReportAsync(array $args = [])
|
||||
* @method \Aws\Result createPermission(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createPermissionAsync(array $args = [])
|
||||
* @method \Aws\Result deleteCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result deletePermission(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deletePermissionAsync(array $args = [])
|
||||
* @method \Aws\Result deletePolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deletePolicyAsync(array $args = [])
|
||||
* @method \Aws\Result describeCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise describeCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result describeCertificateAuthorityAuditReport(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise describeCertificateAuthorityAuditReportAsync(array $args = [])
|
||||
* @method \Aws\Result getCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result getCertificateAuthorityCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getCertificateAuthorityCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result getCertificateAuthorityCsr(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getCertificateAuthorityCsrAsync(array $args = [])
|
||||
* @method \Aws\Result getPolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getPolicyAsync(array $args = [])
|
||||
* @method \Aws\Result importCertificateAuthorityCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise importCertificateAuthorityCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result issueCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise issueCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result listCertificateAuthorities(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listCertificateAuthoritiesAsync(array $args = [])
|
||||
* @method \Aws\Result listPermissions(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listPermissionsAsync(array $args = [])
|
||||
* @method \Aws\Result listTags(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsAsync(array $args = [])
|
||||
* @method \Aws\Result putPolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putPolicyAsync(array $args = [])
|
||||
* @method \Aws\Result restoreCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise restoreCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result revokeCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise revokeCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result tagCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise tagCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result untagCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise untagCertificateAuthorityAsync(array $args = [])
|
||||
* @method \Aws\Result updateCertificateAuthority(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateCertificateAuthorityAsync(array $args = [])
|
||||
*/
|
||||
class ACMPCAClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\ACMPCA\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS Certificate Manager Private Certificate Authority** service.
|
||||
*/
|
||||
class ACMPCAException extends AwsException {}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
namespace Aws\ARCZonalShift;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS ARC - Zonal Shift** service.
|
||||
* @method \Aws\Result cancelZonalShift(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise cancelZonalShiftAsync(array $args = [])
|
||||
* @method \Aws\Result createPracticeRunConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createPracticeRunConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result deletePracticeRunConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deletePracticeRunConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getManagedResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getManagedResourceAsync(array $args = [])
|
||||
* @method \Aws\Result listAutoshifts(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAutoshiftsAsync(array $args = [])
|
||||
* @method \Aws\Result listManagedResources(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listManagedResourcesAsync(array $args = [])
|
||||
* @method \Aws\Result listZonalShifts(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listZonalShiftsAsync(array $args = [])
|
||||
* @method \Aws\Result startZonalShift(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startZonalShiftAsync(array $args = [])
|
||||
* @method \Aws\Result updatePracticeRunConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updatePracticeRunConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result updateZonalAutoshiftConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateZonalAutoshiftConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result updateZonalShift(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateZonalShiftAsync(array $args = [])
|
||||
*/
|
||||
class ARCZonalShiftClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\ARCZonalShift\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS ARC - Zonal Shift** service.
|
||||
*/
|
||||
class ARCZonalShiftException extends AwsException {}
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
namespace Aws;
|
||||
|
||||
use GuzzleHttp\Promise;
|
||||
|
||||
/**
|
||||
* A configuration provider is a function that returns a promise that is
|
||||
* fulfilled with a configuration object. This class provides base functionality
|
||||
* usable by specific configuration provider implementations
|
||||
*/
|
||||
abstract class AbstractConfigurationProvider
|
||||
{
|
||||
const ENV_PROFILE = 'AWS_PROFILE';
|
||||
const ENV_CONFIG_FILE = 'AWS_CONFIG_FILE';
|
||||
|
||||
public static $cacheKey;
|
||||
|
||||
protected static $interfaceClass;
|
||||
protected static $exceptionClass;
|
||||
|
||||
/**
|
||||
* Wraps a config provider and saves provided configuration in an
|
||||
* instance of Aws\CacheInterface. Forwards calls when no config found
|
||||
* in cache and updates cache with the results.
|
||||
*
|
||||
* @param callable $provider Configuration provider function to wrap
|
||||
* @param CacheInterface $cache Cache to store configuration
|
||||
* @param string|null $cacheKey (optional) Cache key to use
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function cache(
|
||||
callable $provider,
|
||||
CacheInterface $cache,
|
||||
$cacheKey = null
|
||||
) {
|
||||
$cacheKey = $cacheKey ?: static::$cacheKey;
|
||||
|
||||
return function () use ($provider, $cache, $cacheKey) {
|
||||
$found = $cache->get($cacheKey);
|
||||
if ($found instanceof static::$interfaceClass) {
|
||||
return Promise\Create::promiseFor($found);
|
||||
}
|
||||
|
||||
return $provider()
|
||||
->then(function ($config) use (
|
||||
$cache,
|
||||
$cacheKey
|
||||
) {
|
||||
$cache->set($cacheKey, $config);
|
||||
return $config;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an aggregate configuration provider that invokes the provided
|
||||
* variadic providers one after the other until a provider returns
|
||||
* configuration.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function chain()
|
||||
{
|
||||
$links = func_get_args();
|
||||
if (empty($links)) {
|
||||
throw new \InvalidArgumentException('No providers in chain');
|
||||
}
|
||||
|
||||
return function () use ($links) {
|
||||
/** @var callable $parent */
|
||||
$parent = array_shift($links);
|
||||
$promise = $parent();
|
||||
while ($next = array_shift($links)) {
|
||||
$promise = $promise->otherwise($next);
|
||||
}
|
||||
return $promise;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the environment's HOME directory if available.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
protected static function getHomeDir()
|
||||
{
|
||||
// On Linux/Unix-like systems, use the HOME environment variable
|
||||
if ($homeDir = getenv('HOME')) {
|
||||
return $homeDir;
|
||||
}
|
||||
|
||||
// Get the HOMEDRIVE and HOMEPATH values for Windows hosts
|
||||
$homeDrive = getenv('HOMEDRIVE');
|
||||
$homePath = getenv('HOMEPATH');
|
||||
|
||||
return ($homeDrive && $homePath) ? $homeDrive . $homePath : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets default config file location from environment, falling back to aws
|
||||
* default location
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getDefaultConfigFilename()
|
||||
{
|
||||
if ($filename = getenv(self::ENV_CONFIG_FILE)) {
|
||||
return $filename;
|
||||
}
|
||||
return self::getHomeDir() . '/.aws/config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a config provider and caches previously provided configuration.
|
||||
*
|
||||
* @param callable $provider Config provider function to wrap.
|
||||
*
|
||||
* @return callable
|
||||
*/
|
||||
public static function memoize(callable $provider)
|
||||
{
|
||||
return function () use ($provider) {
|
||||
static $result;
|
||||
static $isConstant;
|
||||
|
||||
// Constant config will be returned constantly.
|
||||
if ($isConstant) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Create the initial promise that will be used as the cached value
|
||||
if (null === $result) {
|
||||
$result = $provider();
|
||||
}
|
||||
|
||||
// Return config and set flag that provider is already set
|
||||
return $result
|
||||
->then(function ($config) use (&$isConstant) {
|
||||
$isConstant = true;
|
||||
return $config;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject promise with standardized exception.
|
||||
*
|
||||
* @param $msg
|
||||
* @return Promise\RejectedPromise
|
||||
*/
|
||||
protected static function reject($msg)
|
||||
{
|
||||
$exceptionClass = static::$exceptionClass;
|
||||
return new Promise\RejectedPromise(new $exceptionClass($msg));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
namespace Aws\AccessAnalyzer;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **Access Analyzer** service.
|
||||
* @method \Aws\Result applyArchiveRule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise applyArchiveRuleAsync(array $args = [])
|
||||
* @method \Aws\Result cancelPolicyGeneration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise cancelPolicyGenerationAsync(array $args = [])
|
||||
* @method \Aws\Result checkAccessNotGranted(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise checkAccessNotGrantedAsync(array $args = [])
|
||||
* @method \Aws\Result checkNoNewAccess(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise checkNoNewAccessAsync(array $args = [])
|
||||
* @method \Aws\Result createAccessPreview(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createAccessPreviewAsync(array $args = [])
|
||||
* @method \Aws\Result createAnalyzer(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createAnalyzerAsync(array $args = [])
|
||||
* @method \Aws\Result createArchiveRule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createArchiveRuleAsync(array $args = [])
|
||||
* @method \Aws\Result deleteAnalyzer(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteAnalyzerAsync(array $args = [])
|
||||
* @method \Aws\Result deleteArchiveRule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteArchiveRuleAsync(array $args = [])
|
||||
* @method \Aws\Result getAccessPreview(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAccessPreviewAsync(array $args = [])
|
||||
* @method \Aws\Result getAnalyzedResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAnalyzedResourceAsync(array $args = [])
|
||||
* @method \Aws\Result getAnalyzer(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAnalyzerAsync(array $args = [])
|
||||
* @method \Aws\Result getArchiveRule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getArchiveRuleAsync(array $args = [])
|
||||
* @method \Aws\Result getFinding(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getFindingAsync(array $args = [])
|
||||
* @method \Aws\Result getFindingV2(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getFindingV2Async(array $args = [])
|
||||
* @method \Aws\Result getGeneratedPolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getGeneratedPolicyAsync(array $args = [])
|
||||
* @method \Aws\Result listAccessPreviewFindings(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAccessPreviewFindingsAsync(array $args = [])
|
||||
* @method \Aws\Result listAccessPreviews(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAccessPreviewsAsync(array $args = [])
|
||||
* @method \Aws\Result listAnalyzedResources(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAnalyzedResourcesAsync(array $args = [])
|
||||
* @method \Aws\Result listAnalyzers(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAnalyzersAsync(array $args = [])
|
||||
* @method \Aws\Result listArchiveRules(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listArchiveRulesAsync(array $args = [])
|
||||
* @method \Aws\Result listFindings(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listFindingsAsync(array $args = [])
|
||||
* @method \Aws\Result listFindingsV2(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listFindingsV2Async(array $args = [])
|
||||
* @method \Aws\Result listPolicyGenerations(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listPolicyGenerationsAsync(array $args = [])
|
||||
* @method \Aws\Result listTagsForResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsForResourceAsync(array $args = [])
|
||||
* @method \Aws\Result startPolicyGeneration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startPolicyGenerationAsync(array $args = [])
|
||||
* @method \Aws\Result startResourceScan(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startResourceScanAsync(array $args = [])
|
||||
* @method \Aws\Result tagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result untagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result updateArchiveRule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateArchiveRuleAsync(array $args = [])
|
||||
* @method \Aws\Result updateFindings(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateFindingsAsync(array $args = [])
|
||||
* @method \Aws\Result validatePolicy(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise validatePolicyAsync(array $args = [])
|
||||
*/
|
||||
class AccessAnalyzerClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\AccessAnalyzer\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **Access Analyzer** service.
|
||||
*/
|
||||
class AccessAnalyzerException extends AwsException {}
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
namespace Aws\Account;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS Account** service.
|
||||
* @method \Aws\Result deleteAlternateContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteAlternateContactAsync(array $args = [])
|
||||
* @method \Aws\Result disableRegion(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disableRegionAsync(array $args = [])
|
||||
* @method \Aws\Result enableRegion(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise enableRegionAsync(array $args = [])
|
||||
* @method \Aws\Result getAlternateContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAlternateContactAsync(array $args = [])
|
||||
* @method \Aws\Result getContactInformation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getContactInformationAsync(array $args = [])
|
||||
* @method \Aws\Result getRegionOptStatus(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getRegionOptStatusAsync(array $args = [])
|
||||
* @method \Aws\Result listRegions(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listRegionsAsync(array $args = [])
|
||||
* @method \Aws\Result putAlternateContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putAlternateContactAsync(array $args = [])
|
||||
* @method \Aws\Result putContactInformation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putContactInformationAsync(array $args = [])
|
||||
*/
|
||||
class AccountClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\Account\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS Account** service.
|
||||
*/
|
||||
class AccountException extends AwsException {}
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
namespace Aws\Acm;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS Certificate Manager** service.
|
||||
*
|
||||
* @method \Aws\Result addTagsToCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise addTagsToCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result deleteCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result describeCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise describeCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result exportCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise exportCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result getAccountConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAccountConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result importCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise importCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result listCertificates(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listCertificatesAsync(array $args = [])
|
||||
* @method \Aws\Result listTagsForCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsForCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result putAccountConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putAccountConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result removeTagsFromCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise removeTagsFromCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result renewCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise renewCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result requestCertificate(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise requestCertificateAsync(array $args = [])
|
||||
* @method \Aws\Result resendValidationEmail(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise resendValidationEmailAsync(array $args = [])
|
||||
* @method \Aws\Result updateCertificateOptions(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateCertificateOptionsAsync(array $args = [])
|
||||
*/
|
||||
class AcmClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\Acm\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS Certificate Manager** service.
|
||||
*/
|
||||
class AcmException extends AwsException {}
|
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
namespace Aws\AlexaForBusiness;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **Alexa For Business** service.
|
||||
* @method \Aws\Result approveSkill(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise approveSkillAsync(array $args = [])
|
||||
* @method \Aws\Result associateContactWithAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateContactWithAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result associateDeviceWithNetworkProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateDeviceWithNetworkProfileAsync(array $args = [])
|
||||
* @method \Aws\Result associateDeviceWithRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateDeviceWithRoomAsync(array $args = [])
|
||||
* @method \Aws\Result associateSkillGroupWithRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateSkillGroupWithRoomAsync(array $args = [])
|
||||
* @method \Aws\Result associateSkillWithSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateSkillWithSkillGroupAsync(array $args = [])
|
||||
* @method \Aws\Result associateSkillWithUsers(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise associateSkillWithUsersAsync(array $args = [])
|
||||
* @method \Aws\Result createAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result createBusinessReportSchedule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBusinessReportScheduleAsync(array $args = [])
|
||||
* @method \Aws\Result createConferenceProvider(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createConferenceProviderAsync(array $args = [])
|
||||
* @method \Aws\Result createContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createContactAsync(array $args = [])
|
||||
* @method \Aws\Result createGatewayGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createGatewayGroupAsync(array $args = [])
|
||||
* @method \Aws\Result createNetworkProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createNetworkProfileAsync(array $args = [])
|
||||
* @method \Aws\Result createProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createProfileAsync(array $args = [])
|
||||
* @method \Aws\Result createRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createRoomAsync(array $args = [])
|
||||
* @method \Aws\Result createSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createSkillGroupAsync(array $args = [])
|
||||
* @method \Aws\Result createUser(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createUserAsync(array $args = [])
|
||||
* @method \Aws\Result deleteAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBusinessReportSchedule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBusinessReportScheduleAsync(array $args = [])
|
||||
* @method \Aws\Result deleteConferenceProvider(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteConferenceProviderAsync(array $args = [])
|
||||
* @method \Aws\Result deleteContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteContactAsync(array $args = [])
|
||||
* @method \Aws\Result deleteDevice(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteDeviceAsync(array $args = [])
|
||||
* @method \Aws\Result deleteDeviceUsageData(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteDeviceUsageDataAsync(array $args = [])
|
||||
* @method \Aws\Result deleteGatewayGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteGatewayGroupAsync(array $args = [])
|
||||
* @method \Aws\Result deleteNetworkProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteNetworkProfileAsync(array $args = [])
|
||||
* @method \Aws\Result deleteProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteProfileAsync(array $args = [])
|
||||
* @method \Aws\Result deleteRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteRoomAsync(array $args = [])
|
||||
* @method \Aws\Result deleteRoomSkillParameter(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteRoomSkillParameterAsync(array $args = [])
|
||||
* @method \Aws\Result deleteSkillAuthorization(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteSkillAuthorizationAsync(array $args = [])
|
||||
* @method \Aws\Result deleteSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteSkillGroupAsync(array $args = [])
|
||||
* @method \Aws\Result deleteUser(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteUserAsync(array $args = [])
|
||||
* @method \Aws\Result disassociateContactFromAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disassociateContactFromAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result disassociateDeviceFromRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disassociateDeviceFromRoomAsync(array $args = [])
|
||||
* @method \Aws\Result disassociateSkillFromSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disassociateSkillFromSkillGroupAsync(array $args = [])
|
||||
* @method \Aws\Result disassociateSkillFromUsers(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disassociateSkillFromUsersAsync(array $args = [])
|
||||
* @method \Aws\Result disassociateSkillGroupFromRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise disassociateSkillGroupFromRoomAsync(array $args = [])
|
||||
* @method \Aws\Result forgetSmartHomeAppliances(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise forgetSmartHomeAppliancesAsync(array $args = [])
|
||||
* @method \Aws\Result getAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result getConferencePreference(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getConferencePreferenceAsync(array $args = [])
|
||||
* @method \Aws\Result getConferenceProvider(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getConferenceProviderAsync(array $args = [])
|
||||
* @method \Aws\Result getContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getContactAsync(array $args = [])
|
||||
* @method \Aws\Result getDevice(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getDeviceAsync(array $args = [])
|
||||
* @method \Aws\Result getGateway(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getGatewayAsync(array $args = [])
|
||||
* @method \Aws\Result getGatewayGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getGatewayGroupAsync(array $args = [])
|
||||
* @method \Aws\Result getInvitationConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getInvitationConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result getNetworkProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getNetworkProfileAsync(array $args = [])
|
||||
* @method \Aws\Result getProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getProfileAsync(array $args = [])
|
||||
* @method \Aws\Result getRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getRoomAsync(array $args = [])
|
||||
* @method \Aws\Result getRoomSkillParameter(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getRoomSkillParameterAsync(array $args = [])
|
||||
* @method \Aws\Result getSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getSkillGroupAsync(array $args = [])
|
||||
* @method \Aws\Result listBusinessReportSchedules(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBusinessReportSchedulesAsync(array $args = [])
|
||||
* @method \Aws\Result listConferenceProviders(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listConferenceProvidersAsync(array $args = [])
|
||||
* @method \Aws\Result listDeviceEvents(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listDeviceEventsAsync(array $args = [])
|
||||
* @method \Aws\Result listGatewayGroups(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listGatewayGroupsAsync(array $args = [])
|
||||
* @method \Aws\Result listGateways(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listGatewaysAsync(array $args = [])
|
||||
* @method \Aws\Result listSkills(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listSkillsAsync(array $args = [])
|
||||
* @method \Aws\Result listSkillsStoreCategories(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listSkillsStoreCategoriesAsync(array $args = [])
|
||||
* @method \Aws\Result listSkillsStoreSkillsByCategory(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listSkillsStoreSkillsByCategoryAsync(array $args = [])
|
||||
* @method \Aws\Result listSmartHomeAppliances(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listSmartHomeAppliancesAsync(array $args = [])
|
||||
* @method \Aws\Result listTags(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsAsync(array $args = [])
|
||||
* @method \Aws\Result putConferencePreference(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putConferencePreferenceAsync(array $args = [])
|
||||
* @method \Aws\Result putInvitationConfiguration(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putInvitationConfigurationAsync(array $args = [])
|
||||
* @method \Aws\Result putRoomSkillParameter(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putRoomSkillParameterAsync(array $args = [])
|
||||
* @method \Aws\Result putSkillAuthorization(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putSkillAuthorizationAsync(array $args = [])
|
||||
* @method \Aws\Result registerAVSDevice(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise registerAVSDeviceAsync(array $args = [])
|
||||
* @method \Aws\Result rejectSkill(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise rejectSkillAsync(array $args = [])
|
||||
* @method \Aws\Result resolveRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise resolveRoomAsync(array $args = [])
|
||||
* @method \Aws\Result revokeInvitation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise revokeInvitationAsync(array $args = [])
|
||||
* @method \Aws\Result searchAddressBooks(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchAddressBooksAsync(array $args = [])
|
||||
* @method \Aws\Result searchContacts(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchContactsAsync(array $args = [])
|
||||
* @method \Aws\Result searchDevices(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchDevicesAsync(array $args = [])
|
||||
* @method \Aws\Result searchNetworkProfiles(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchNetworkProfilesAsync(array $args = [])
|
||||
* @method \Aws\Result searchProfiles(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchProfilesAsync(array $args = [])
|
||||
* @method \Aws\Result searchRooms(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchRoomsAsync(array $args = [])
|
||||
* @method \Aws\Result searchSkillGroups(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchSkillGroupsAsync(array $args = [])
|
||||
* @method \Aws\Result searchUsers(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise searchUsersAsync(array $args = [])
|
||||
* @method \Aws\Result sendAnnouncement(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise sendAnnouncementAsync(array $args = [])
|
||||
* @method \Aws\Result sendInvitation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise sendInvitationAsync(array $args = [])
|
||||
* @method \Aws\Result startDeviceSync(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startDeviceSyncAsync(array $args = [])
|
||||
* @method \Aws\Result startSmartHomeApplianceDiscovery(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startSmartHomeApplianceDiscoveryAsync(array $args = [])
|
||||
* @method \Aws\Result tagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result untagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result updateAddressBook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateAddressBookAsync(array $args = [])
|
||||
* @method \Aws\Result updateBusinessReportSchedule(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBusinessReportScheduleAsync(array $args = [])
|
||||
* @method \Aws\Result updateConferenceProvider(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateConferenceProviderAsync(array $args = [])
|
||||
* @method \Aws\Result updateContact(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateContactAsync(array $args = [])
|
||||
* @method \Aws\Result updateDevice(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateDeviceAsync(array $args = [])
|
||||
* @method \Aws\Result updateGateway(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateGatewayAsync(array $args = [])
|
||||
* @method \Aws\Result updateGatewayGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateGatewayGroupAsync(array $args = [])
|
||||
* @method \Aws\Result updateNetworkProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateNetworkProfileAsync(array $args = [])
|
||||
* @method \Aws\Result updateProfile(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateProfileAsync(array $args = [])
|
||||
* @method \Aws\Result updateRoom(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateRoomAsync(array $args = [])
|
||||
* @method \Aws\Result updateSkillGroup(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateSkillGroupAsync(array $args = [])
|
||||
*/
|
||||
class AlexaForBusinessClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\AlexaForBusiness\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **Alexa For Business** service.
|
||||
*/
|
||||
class AlexaForBusinessException extends AwsException {}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
namespace Aws\Amplify;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS Amplify** service.
|
||||
* @method \Aws\Result createApp(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createAppAsync(array $args = [])
|
||||
* @method \Aws\Result createBackendEnvironment(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendEnvironmentAsync(array $args = [])
|
||||
* @method \Aws\Result createBranch(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBranchAsync(array $args = [])
|
||||
* @method \Aws\Result createDeployment(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createDeploymentAsync(array $args = [])
|
||||
* @method \Aws\Result createDomainAssociation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createDomainAssociationAsync(array $args = [])
|
||||
* @method \Aws\Result createWebhook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createWebhookAsync(array $args = [])
|
||||
* @method \Aws\Result deleteApp(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteAppAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBackendEnvironment(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBackendEnvironmentAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBranch(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBranchAsync(array $args = [])
|
||||
* @method \Aws\Result deleteDomainAssociation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteDomainAssociationAsync(array $args = [])
|
||||
* @method \Aws\Result deleteJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteJobAsync(array $args = [])
|
||||
* @method \Aws\Result deleteWebhook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteWebhookAsync(array $args = [])
|
||||
* @method \Aws\Result generateAccessLogs(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise generateAccessLogsAsync(array $args = [])
|
||||
* @method \Aws\Result getApp(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getAppAsync(array $args = [])
|
||||
* @method \Aws\Result getArtifactUrl(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getArtifactUrlAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendEnvironment(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendEnvironmentAsync(array $args = [])
|
||||
* @method \Aws\Result getBranch(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBranchAsync(array $args = [])
|
||||
* @method \Aws\Result getDomainAssociation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getDomainAssociationAsync(array $args = [])
|
||||
* @method \Aws\Result getJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getJobAsync(array $args = [])
|
||||
* @method \Aws\Result getWebhook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getWebhookAsync(array $args = [])
|
||||
* @method \Aws\Result listApps(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listAppsAsync(array $args = [])
|
||||
* @method \Aws\Result listArtifacts(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listArtifactsAsync(array $args = [])
|
||||
* @method \Aws\Result listBackendEnvironments(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBackendEnvironmentsAsync(array $args = [])
|
||||
* @method \Aws\Result listBranches(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBranchesAsync(array $args = [])
|
||||
* @method \Aws\Result listDomainAssociations(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listDomainAssociationsAsync(array $args = [])
|
||||
* @method \Aws\Result listJobs(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listJobsAsync(array $args = [])
|
||||
* @method \Aws\Result listTagsForResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsForResourceAsync(array $args = [])
|
||||
* @method \Aws\Result listWebhooks(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listWebhooksAsync(array $args = [])
|
||||
* @method \Aws\Result startDeployment(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startDeploymentAsync(array $args = [])
|
||||
* @method \Aws\Result startJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startJobAsync(array $args = [])
|
||||
* @method \Aws\Result stopJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise stopJobAsync(array $args = [])
|
||||
* @method \Aws\Result tagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result untagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result updateApp(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateAppAsync(array $args = [])
|
||||
* @method \Aws\Result updateBranch(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBranchAsync(array $args = [])
|
||||
* @method \Aws\Result updateDomainAssociation(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateDomainAssociationAsync(array $args = [])
|
||||
* @method \Aws\Result updateWebhook(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateWebhookAsync(array $args = [])
|
||||
*/
|
||||
class AmplifyClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\Amplify\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS Amplify** service.
|
||||
*/
|
||||
class AmplifyException extends AwsException {}
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
namespace Aws\AmplifyBackend;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AmplifyBackend** service.
|
||||
* @method \Aws\Result cloneBackend(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise cloneBackendAsync(array $args = [])
|
||||
* @method \Aws\Result createBackend(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendAsync(array $args = [])
|
||||
* @method \Aws\Result createBackendAPI(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendAPIAsync(array $args = [])
|
||||
* @method \Aws\Result createBackendAuth(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendAuthAsync(array $args = [])
|
||||
* @method \Aws\Result createBackendConfig(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendConfigAsync(array $args = [])
|
||||
* @method \Aws\Result createBackendStorage(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createBackendStorageAsync(array $args = [])
|
||||
* @method \Aws\Result createToken(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createTokenAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBackend(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBackendAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBackendAPI(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBackendAPIAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBackendAuth(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBackendAuthAsync(array $args = [])
|
||||
* @method \Aws\Result deleteBackendStorage(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteBackendStorageAsync(array $args = [])
|
||||
* @method \Aws\Result deleteToken(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteTokenAsync(array $args = [])
|
||||
* @method \Aws\Result generateBackendAPIModels(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise generateBackendAPIModelsAsync(array $args = [])
|
||||
* @method \Aws\Result getBackend(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendAPI(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendAPIAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendAPIModels(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendAPIModelsAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendAuth(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendAuthAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendJobAsync(array $args = [])
|
||||
* @method \Aws\Result getBackendStorage(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getBackendStorageAsync(array $args = [])
|
||||
* @method \Aws\Result getToken(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getTokenAsync(array $args = [])
|
||||
* @method \Aws\Result importBackendAuth(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise importBackendAuthAsync(array $args = [])
|
||||
* @method \Aws\Result importBackendStorage(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise importBackendStorageAsync(array $args = [])
|
||||
* @method \Aws\Result listBackendJobs(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listBackendJobsAsync(array $args = [])
|
||||
* @method \Aws\Result listS3Buckets(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listS3BucketsAsync(array $args = [])
|
||||
* @method \Aws\Result removeAllBackends(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise removeAllBackendsAsync(array $args = [])
|
||||
* @method \Aws\Result removeBackendConfig(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise removeBackendConfigAsync(array $args = [])
|
||||
* @method \Aws\Result updateBackendAPI(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBackendAPIAsync(array $args = [])
|
||||
* @method \Aws\Result updateBackendAuth(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBackendAuthAsync(array $args = [])
|
||||
* @method \Aws\Result updateBackendConfig(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBackendConfigAsync(array $args = [])
|
||||
* @method \Aws\Result updateBackendJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBackendJobAsync(array $args = [])
|
||||
* @method \Aws\Result updateBackendStorage(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateBackendStorageAsync(array $args = [])
|
||||
*/
|
||||
class AmplifyBackendClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\AmplifyBackend\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AmplifyBackend** service.
|
||||
*/
|
||||
class AmplifyBackendException extends AwsException {}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
namespace Aws\AmplifyUIBuilder;
|
||||
|
||||
use Aws\AwsClient;
|
||||
|
||||
/**
|
||||
* This client is used to interact with the **AWS Amplify UI Builder** service.
|
||||
* @method \Aws\Result createComponent(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createComponentAsync(array $args = [])
|
||||
* @method \Aws\Result createForm(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createFormAsync(array $args = [])
|
||||
* @method \Aws\Result createTheme(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise createThemeAsync(array $args = [])
|
||||
* @method \Aws\Result deleteComponent(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteComponentAsync(array $args = [])
|
||||
* @method \Aws\Result deleteForm(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteFormAsync(array $args = [])
|
||||
* @method \Aws\Result deleteTheme(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise deleteThemeAsync(array $args = [])
|
||||
* @method \Aws\Result exchangeCodeForToken(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise exchangeCodeForTokenAsync(array $args = [])
|
||||
* @method \Aws\Result exportComponents(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise exportComponentsAsync(array $args = [])
|
||||
* @method \Aws\Result exportForms(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise exportFormsAsync(array $args = [])
|
||||
* @method \Aws\Result exportThemes(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise exportThemesAsync(array $args = [])
|
||||
* @method \Aws\Result getCodegenJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getCodegenJobAsync(array $args = [])
|
||||
* @method \Aws\Result getComponent(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getComponentAsync(array $args = [])
|
||||
* @method \Aws\Result getForm(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getFormAsync(array $args = [])
|
||||
* @method \Aws\Result getMetadata(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getMetadataAsync(array $args = [])
|
||||
* @method \Aws\Result getTheme(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise getThemeAsync(array $args = [])
|
||||
* @method \Aws\Result listCodegenJobs(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listCodegenJobsAsync(array $args = [])
|
||||
* @method \Aws\Result listComponents(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listComponentsAsync(array $args = [])
|
||||
* @method \Aws\Result listForms(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listFormsAsync(array $args = [])
|
||||
* @method \Aws\Result listTagsForResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listTagsForResourceAsync(array $args = [])
|
||||
* @method \Aws\Result listThemes(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise listThemesAsync(array $args = [])
|
||||
* @method \Aws\Result putMetadataFlag(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise putMetadataFlagAsync(array $args = [])
|
||||
* @method \Aws\Result refreshToken(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise refreshTokenAsync(array $args = [])
|
||||
* @method \Aws\Result startCodegenJob(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise startCodegenJobAsync(array $args = [])
|
||||
* @method \Aws\Result tagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result untagResource(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = [])
|
||||
* @method \Aws\Result updateComponent(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateComponentAsync(array $args = [])
|
||||
* @method \Aws\Result updateForm(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateFormAsync(array $args = [])
|
||||
* @method \Aws\Result updateTheme(array $args = [])
|
||||
* @method \GuzzleHttp\Promise\Promise updateThemeAsync(array $args = [])
|
||||
*/
|
||||
class AmplifyUIBuilderClient extends AwsClient {}
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
namespace Aws\AmplifyUIBuilder\Exception;
|
||||
|
||||
use Aws\Exception\AwsException;
|
||||
|
||||
/**
|
||||
* Represents an error interacting with the **AWS Amplify UI Builder** service.
|
||||
*/
|
||||
class AmplifyUIBuilderException extends AwsException {}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
/**
|
||||
* Base class that is used by most API shapes
|
||||
*/
|
||||
abstract class AbstractModel implements \ArrayAccess
|
||||
{
|
||||
/** @var array */
|
||||
protected $definition;
|
||||
|
||||
/** @var ShapeMap */
|
||||
protected $shapeMap;
|
||||
|
||||
/** @var array */
|
||||
protected $contextParam;
|
||||
|
||||
/**
|
||||
* @param array $definition Service description
|
||||
* @param ShapeMap $shapeMap Shapemap used for creating shapes
|
||||
*/
|
||||
public function __construct(array $definition, ShapeMap $shapeMap)
|
||||
{
|
||||
$this->definition = $definition;
|
||||
$this->shapeMap = $shapeMap;
|
||||
if (isset($definition['contextParam'])) {
|
||||
$this->contextParam = $definition['contextParam'];
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return $this->definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return isset($this->definition[$offset])
|
||||
? $this->definition[$offset] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->definition[$offset] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->definition[$offset]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->definition[$offset]);
|
||||
}
|
||||
|
||||
protected function shapeAt($key)
|
||||
{
|
||||
if (!isset($this->definition[$key])) {
|
||||
throw new \InvalidArgumentException('Expected shape definition at '
|
||||
. $key);
|
||||
}
|
||||
|
||||
return $this->shapeFor($this->definition[$key]);
|
||||
}
|
||||
|
||||
protected function shapeFor(array $definition)
|
||||
{
|
||||
return isset($definition['shape'])
|
||||
? $this->shapeMap->resolve($definition)
|
||||
: Shape::create($definition, $this->shapeMap);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
use Aws\Exception\UnresolvedApiException;
|
||||
|
||||
/**
|
||||
* API providers.
|
||||
*
|
||||
* An API provider is a function that accepts a type, service, and version and
|
||||
* returns an array of API data on success or NULL if no API data can be created
|
||||
* for the provided arguments.
|
||||
*
|
||||
* You can wrap your calls to an API provider with the
|
||||
* {@see ApiProvider::resolve} method to ensure that API data is created. If the
|
||||
* API data is not created, then the resolve() method will throw a
|
||||
* {@see Aws\Exception\UnresolvedApiException}.
|
||||
*
|
||||
* use Aws\Api\ApiProvider;
|
||||
* $provider = ApiProvider::defaultProvider();
|
||||
* // Returns an array or NULL.
|
||||
* $data = $provider('api', 's3', '2006-03-01');
|
||||
* // Returns an array or throws.
|
||||
* $data = ApiProvider::resolve($provider, 'api', 'elasticfood', '2020-01-01');
|
||||
*
|
||||
* You can compose multiple providers into a single provider using
|
||||
* {@see Aws\or_chain}. This method accepts providers as arguments and
|
||||
* returns a new function that will invoke each provider until a non-null value
|
||||
* is returned.
|
||||
*
|
||||
* $a = ApiProvider::filesystem(sys_get_temp_dir() . '/aws-beta-models');
|
||||
* $b = ApiProvider::manifest();
|
||||
*
|
||||
* $c = \Aws\or_chain($a, $b);
|
||||
* $data = $c('api', 'betaservice', '2015-08-08'); // $a handles this.
|
||||
* $data = $c('api', 's3', '2006-03-01'); // $b handles this.
|
||||
* $data = $c('api', 'invalid', '2014-12-15'); // Neither handles this.
|
||||
*/
|
||||
class ApiProvider
|
||||
{
|
||||
/** @var array A map of public API type names to their file suffix. */
|
||||
private static $typeMap = [
|
||||
'api' => 'api-2',
|
||||
'paginator' => 'paginators-1',
|
||||
'waiter' => 'waiters-2',
|
||||
'docs' => 'docs-2',
|
||||
];
|
||||
|
||||
/** @var array API manifest */
|
||||
private $manifest;
|
||||
|
||||
/** @var string The directory containing service models. */
|
||||
private $modelsDir;
|
||||
|
||||
/**
|
||||
* Resolves an API provider and ensures a non-null return value.
|
||||
*
|
||||
* @param callable $provider Provider function to invoke.
|
||||
* @param string $type Type of data ('api', 'waiter', 'paginator').
|
||||
* @param string $service Service name.
|
||||
* @param string $version API version.
|
||||
*
|
||||
* @return array
|
||||
* @throws UnresolvedApiException
|
||||
*/
|
||||
public static function resolve(callable $provider, $type, $service, $version)
|
||||
{
|
||||
// Execute the provider and return the result, if there is one.
|
||||
$result = $provider($type, $service, $version);
|
||||
if (is_array($result)) {
|
||||
if (!isset($result['metadata']['serviceIdentifier'])) {
|
||||
$result['metadata']['serviceIdentifier'] = $service;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Throw an exception with a message depending on the inputs.
|
||||
if (!isset(self::$typeMap[$type])) {
|
||||
$msg = "The type must be one of: " . implode(', ', self::$typeMap);
|
||||
} elseif ($service) {
|
||||
$msg = "The {$service} service does not have version: {$version}.";
|
||||
} else {
|
||||
$msg = "You must specify a service name to retrieve its API data.";
|
||||
}
|
||||
|
||||
throw new UnresolvedApiException($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default SDK API provider.
|
||||
*
|
||||
* This provider loads pre-built manifest data from the `data` directory.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function defaultProvider()
|
||||
{
|
||||
return new self(__DIR__ . '/../data', \Aws\manifest());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads API data after resolving the version to the latest, compatible,
|
||||
* available version based on the provided manifest data.
|
||||
*
|
||||
* Manifest data is essentially an associative array of service names to
|
||||
* associative arrays of API version aliases.
|
||||
*
|
||||
* [
|
||||
* ...
|
||||
* 'ec2' => [
|
||||
* 'latest' => '2014-10-01',
|
||||
* '2014-10-01' => '2014-10-01',
|
||||
* '2014-09-01' => '2014-10-01',
|
||||
* '2014-06-15' => '2014-10-01',
|
||||
* ...
|
||||
* ],
|
||||
* 'ecs' => [...],
|
||||
* 'elasticache' => [...],
|
||||
* ...
|
||||
* ]
|
||||
*
|
||||
* @param string $dir Directory containing service models.
|
||||
* @param array $manifest The API version manifest data.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public static function manifest($dir, array $manifest)
|
||||
{
|
||||
return new self($dir, $manifest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads API data from the specified directory.
|
||||
*
|
||||
* If "latest" is specified as the version, this provider must glob the
|
||||
* directory to find which is the latest available version.
|
||||
*
|
||||
* @param string $dir Directory containing service models.
|
||||
*
|
||||
* @return self
|
||||
* @throws \InvalidArgumentException if the provided `$dir` is invalid.
|
||||
*/
|
||||
public static function filesystem($dir)
|
||||
{
|
||||
return new self($dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of valid versions for the specified service.
|
||||
*
|
||||
* @param string $service Service name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVersions($service)
|
||||
{
|
||||
if (!isset($this->manifest)) {
|
||||
$this->buildVersionsList($service);
|
||||
}
|
||||
|
||||
if (!isset($this->manifest[$service]['versions'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_values(array_unique($this->manifest[$service]['versions']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the provider.
|
||||
*
|
||||
* @param string $type Type of data ('api', 'waiter', 'paginator').
|
||||
* @param string $service Service name.
|
||||
* @param string $version API version.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function __invoke($type, $service, $version)
|
||||
{
|
||||
// Resolve the type or return null.
|
||||
if (isset(self::$typeMap[$type])) {
|
||||
$type = self::$typeMap[$type];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Resolve the version or return null.
|
||||
if (!isset($this->manifest)) {
|
||||
$this->buildVersionsList($service);
|
||||
}
|
||||
|
||||
if (!isset($this->manifest[$service]['versions'][$version])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$version = $this->manifest[$service]['versions'][$version];
|
||||
$path = "{$this->modelsDir}/{$service}/{$version}/{$type}.json";
|
||||
|
||||
try {
|
||||
return \Aws\load_compiled_json($path);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $modelsDir Directory containing service models.
|
||||
* @param array $manifest The API version manifest data.
|
||||
*/
|
||||
private function __construct($modelsDir, array $manifest = null)
|
||||
{
|
||||
$this->manifest = $manifest;
|
||||
$this->modelsDir = rtrim($modelsDir, '/');
|
||||
if (!is_dir($this->modelsDir)) {
|
||||
throw new \InvalidArgumentException(
|
||||
"The specified models directory, {$modelsDir}, was not found."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the versions list for the specified service by globbing the dir.
|
||||
*/
|
||||
private function buildVersionsList($service)
|
||||
{
|
||||
$dir = "{$this->modelsDir}/{$service}/";
|
||||
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get versions, remove . and .., and sort in descending order.
|
||||
$results = array_diff(scandir($dir, SCANDIR_SORT_DESCENDING), ['..', '.']);
|
||||
|
||||
if (!$results) {
|
||||
$this->manifest[$service] = ['versions' => []];
|
||||
} else {
|
||||
$this->manifest[$service] = [
|
||||
'versions' => [
|
||||
'latest' => $results[0]
|
||||
]
|
||||
];
|
||||
$this->manifest[$service]['versions'] += array_combine($results, $results);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace Aws\Api;
|
||||
|
||||
use Aws\Api\Parser\Exception\ParserException;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* DateTime overrides that make DateTime work more seamlessly as a string,
|
||||
* with JSON documents, and with JMESPath.
|
||||
*/
|
||||
class DateTimeResult extends \DateTime implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Create a new DateTimeResult from a unix timestamp.
|
||||
* The Unix epoch (or Unix time or POSIX time or Unix
|
||||
* timestamp) is the number of seconds that have elapsed since
|
||||
* January 1, 1970 (midnight UTC/GMT).
|
||||
*
|
||||
* @return DateTimeResult
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromEpoch($unixTimestamp)
|
||||
{
|
||||
if (!is_numeric($unixTimestamp)) {
|
||||
throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromEpoch');
|
||||
}
|
||||
|
||||
// PHP 5.5 does not support sub-second precision
|
||||
if (\PHP_VERSION_ID < 56000) {
|
||||
return new self(gmdate('c', $unixTimestamp));
|
||||
}
|
||||
|
||||
$decimalSeparator = isset(localeconv()['decimal_point']) ? localeconv()['decimal_point'] : ".";
|
||||
$formatString = "U" . $decimalSeparator . "u";
|
||||
$dateTime = DateTime::createFromFormat(
|
||||
$formatString,
|
||||
sprintf('%0.6f', $unixTimestamp),
|
||||
new DateTimeZone('UTC')
|
||||
);
|
||||
|
||||
if (false === $dateTime) {
|
||||
throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromEpoch');
|
||||
}
|
||||
|
||||
return new self(
|
||||
$dateTime->format('Y-m-d H:i:s.u'),
|
||||
new DateTimeZone('UTC')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTimeResult
|
||||
*/
|
||||
public static function fromISO8601($iso8601Timestamp)
|
||||
{
|
||||
if (is_numeric($iso8601Timestamp) || !is_string($iso8601Timestamp)) {
|
||||
throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromISO8601');
|
||||
}
|
||||
|
||||
return new DateTimeResult($iso8601Timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new DateTimeResult from an unknown timestamp.
|
||||
*
|
||||
* @return DateTimeResult
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function fromTimestamp($timestamp, $expectedFormat = null)
|
||||
{
|
||||
if (empty($timestamp)) {
|
||||
return self::fromEpoch(0);
|
||||
}
|
||||
|
||||
if (!(is_string($timestamp) || is_numeric($timestamp))) {
|
||||
throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromTimestamp');
|
||||
}
|
||||
|
||||
try {
|
||||
if ($expectedFormat == 'iso8601') {
|
||||
try {
|
||||
return self::fromISO8601($timestamp);
|
||||
} catch (Exception $exception) {
|
||||
return self::fromEpoch($timestamp);
|
||||
}
|
||||
} else if ($expectedFormat == 'unixTimestamp') {
|
||||
try {
|
||||
return self::fromEpoch($timestamp);
|
||||
} catch (Exception $exception) {
|
||||
return self::fromISO8601($timestamp);
|
||||
}
|
||||
} else if (\Aws\is_valid_epoch($timestamp)) {
|
||||
return self::fromEpoch($timestamp);
|
||||
}
|
||||
return self::fromISO8601($timestamp);
|
||||
} catch (Exception $exception) {
|
||||
throw new ParserException('Invalid timestamp value passed to DateTimeResult::fromTimestamp');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the DateTimeResult as an ISO 8601 date string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->format('c');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the date as an ISO 8601 date when serializing as JSON.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return (string) $this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
/**
|
||||
* Encapsulates the documentation strings for a given service-version and
|
||||
* provides methods for extracting the desired parts related to a service,
|
||||
* operation, error, or shape (i.e., parameter).
|
||||
*/
|
||||
class DocModel
|
||||
{
|
||||
/** @var array */
|
||||
private $docs;
|
||||
|
||||
/**
|
||||
* @param array $docs
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function __construct(array $docs)
|
||||
{
|
||||
if (!extension_loaded('tidy')) {
|
||||
throw new \RuntimeException('The "tidy" PHP extension is required.');
|
||||
}
|
||||
|
||||
$this->docs = $docs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the doc model to an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return $this->docs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves documentation about the service.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getServiceDocs()
|
||||
{
|
||||
return isset($this->docs['service']) ? $this->docs['service'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves documentation about an operation.
|
||||
*
|
||||
* @param string $operation Name of the operation
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getOperationDocs($operation)
|
||||
{
|
||||
return isset($this->docs['operations'][$operation])
|
||||
? $this->docs['operations'][$operation]
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves documentation about an error.
|
||||
*
|
||||
* @param string $error Name of the error
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getErrorDocs($error)
|
||||
{
|
||||
return isset($this->docs['shapes'][$error]['base'])
|
||||
? $this->docs['shapes'][$error]['base']
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves documentation about a shape, specific to the context.
|
||||
*
|
||||
* @param string $shapeName Name of the shape.
|
||||
* @param string $parentName Name of the parent/context shape.
|
||||
* @param string $ref Name used by the context to reference the shape.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getShapeDocs($shapeName, $parentName, $ref)
|
||||
{
|
||||
if (!isset($this->docs['shapes'][$shapeName])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$result = '';
|
||||
$d = $this->docs['shapes'][$shapeName];
|
||||
if (isset($d['refs']["{$parentName}\${$ref}"])) {
|
||||
$result = $d['refs']["{$parentName}\${$ref}"];
|
||||
} elseif (isset($d['base'])) {
|
||||
$result = $d['base'];
|
||||
}
|
||||
|
||||
if (isset($d['append'])) {
|
||||
if (!isset($d['excludeAppend'])
|
||||
|| !in_array($parentName, $d['excludeAppend'])
|
||||
) {
|
||||
$result .= $d['append'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($d['appendOnly'])
|
||||
&& in_array($parentName, $d['appendOnly']['shapes'])
|
||||
) {
|
||||
$result .= $d['appendOnly']['message'];
|
||||
}
|
||||
|
||||
return $this->clean($result);
|
||||
}
|
||||
|
||||
private function clean($content)
|
||||
{
|
||||
if (!$content) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$tidy = new \tidy();
|
||||
$tidy->parseString($content, [
|
||||
'indent' => true,
|
||||
'doctype' => 'omit',
|
||||
'output-html' => true,
|
||||
'show-body-only' => true,
|
||||
'drop-empty-paras' => true,
|
||||
'drop-font-tags' => true,
|
||||
'drop-proprietary-attributes' => true,
|
||||
'hide-comments' => true,
|
||||
'logical-emphasis' => true
|
||||
]);
|
||||
$tidy->cleanRepair();
|
||||
|
||||
return (string) $content;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\MetadataParserTrait;
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Aws\Api\Service;
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
abstract class AbstractErrorParser
|
||||
{
|
||||
use MetadataParserTrait;
|
||||
use PayloadParserTrait;
|
||||
|
||||
/**
|
||||
* @var Service
|
||||
*/
|
||||
protected $api;
|
||||
|
||||
/**
|
||||
* @param Service $api
|
||||
*/
|
||||
public function __construct(Service $api = null)
|
||||
{
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
abstract protected function payload(
|
||||
ResponseInterface $response,
|
||||
StructureShape $member
|
||||
);
|
||||
|
||||
protected function extractPayload(
|
||||
StructureShape $member,
|
||||
ResponseInterface $response
|
||||
) {
|
||||
if ($member instanceof StructureShape) {
|
||||
// Structure members parse top-level data into a specific key.
|
||||
return $this->payload($response, $member);
|
||||
} else {
|
||||
// Streaming data is just the stream from the response body.
|
||||
return $response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
protected function populateShape(
|
||||
array &$data,
|
||||
ResponseInterface $response,
|
||||
CommandInterface $command = null
|
||||
) {
|
||||
$data['body'] = [];
|
||||
|
||||
if (!empty($command) && !empty($this->api)) {
|
||||
|
||||
// If modeled error code is indicated, check for known error shape
|
||||
if (!empty($data['code'])) {
|
||||
|
||||
$errors = $this->api->getOperation($command->getName())->getErrors();
|
||||
foreach ($errors as $key => $error) {
|
||||
|
||||
// If error code matches a known error shape, populate the body
|
||||
if ($data['code'] == $error['name']
|
||||
&& $error instanceof StructureShape
|
||||
) {
|
||||
$modeledError = $error;
|
||||
$data['body'] = $this->extractPayload(
|
||||
$modeledError,
|
||||
$response
|
||||
);
|
||||
$data['error_shape'] = $modeledError;
|
||||
|
||||
foreach ($error->getMembers() as $name => $member) {
|
||||
switch ($member['location']) {
|
||||
case 'header':
|
||||
$this->extractHeader($name, $member, $response, $data['body']);
|
||||
break;
|
||||
case 'headers':
|
||||
$this->extractHeaders($name, $member, $response, $data['body']);
|
||||
break;
|
||||
case 'statusCode':
|
||||
$this->extractStatus($name, $response, $data['body']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Aws\Api\StructureShape;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Provides basic JSON error parsing functionality.
|
||||
*/
|
||||
trait JsonParserTrait
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
private function genericHandler(ResponseInterface $response)
|
||||
{
|
||||
$code = (string) $response->getStatusCode();
|
||||
if ($this->api
|
||||
&& !is_null($this->api->getMetadata('awsQueryCompatible'))
|
||||
&& $response->getHeaderLine('x-amzn-query-error')
|
||||
) {
|
||||
$queryError = $response->getHeaderLine('x-amzn-query-error');
|
||||
$parts = explode(';', $queryError);
|
||||
if (isset($parts) && count($parts) == 2 && $parts[0] && $parts[1]) {
|
||||
$error_code = $parts[0];
|
||||
$error_type = $parts[1];
|
||||
}
|
||||
}
|
||||
if (!isset($error_type)) {
|
||||
$error_type = $code[0] == '4' ? 'client' : 'server';
|
||||
}
|
||||
|
||||
return [
|
||||
'request_id' => (string) $response->getHeaderLine('x-amzn-requestid'),
|
||||
'code' => isset($error_code) ? $error_code : null,
|
||||
'message' => null,
|
||||
'type' => $error_type,
|
||||
'parsed' => $this->parseJson($response->getBody(), $response)
|
||||
];
|
||||
}
|
||||
|
||||
protected function payload(
|
||||
ResponseInterface $response,
|
||||
StructureShape $member
|
||||
) {
|
||||
$jsonBody = $this->parseJson($response->getBody(), $response);
|
||||
|
||||
if ($jsonBody) {
|
||||
return $this->parser->parse($member, $jsonBody);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\JsonParser;
|
||||
use Aws\Api\Service;
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parsers JSON-RPC errors.
|
||||
*/
|
||||
class JsonRpcErrorParser extends AbstractErrorParser
|
||||
{
|
||||
use JsonParserTrait;
|
||||
|
||||
private $parser;
|
||||
|
||||
public function __construct(Service $api = null, JsonParser $parser = null)
|
||||
{
|
||||
parent::__construct($api);
|
||||
$this->parser = $parser ?: new JsonParser();
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
ResponseInterface $response,
|
||||
CommandInterface $command = null
|
||||
) {
|
||||
$data = $this->genericHandler($response);
|
||||
|
||||
// Make the casing consistent across services.
|
||||
if ($data['parsed']) {
|
||||
$data['parsed'] = array_change_key_case($data['parsed']);
|
||||
}
|
||||
|
||||
if (isset($data['parsed']['__type'])) {
|
||||
if (!isset($data['code'])) {
|
||||
$parts = explode('#', $data['parsed']['__type']);
|
||||
$data['code'] = isset($parts[1]) ? $parts[1] : $parts[0];
|
||||
}
|
||||
$data['message'] = isset($data['parsed']['message'])
|
||||
? $data['parsed']['message']
|
||||
: null;
|
||||
}
|
||||
|
||||
$this->populateShape($data, $response, $command);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\JsonParser;
|
||||
use Aws\Api\Service;
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parses JSON-REST errors.
|
||||
*/
|
||||
class RestJsonErrorParser extends AbstractErrorParser
|
||||
{
|
||||
use JsonParserTrait;
|
||||
|
||||
private $parser;
|
||||
|
||||
public function __construct(Service $api = null, JsonParser $parser = null)
|
||||
{
|
||||
parent::__construct($api);
|
||||
$this->parser = $parser ?: new JsonParser();
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
ResponseInterface $response,
|
||||
CommandInterface $command = null
|
||||
) {
|
||||
$data = $this->genericHandler($response);
|
||||
|
||||
// Merge in error data from the JSON body
|
||||
if ($json = $data['parsed']) {
|
||||
$data = array_replace($data, $json);
|
||||
}
|
||||
|
||||
// Correct error type from services like Amazon Glacier
|
||||
if (!empty($data['type'])) {
|
||||
$data['type'] = strtolower($data['type']);
|
||||
}
|
||||
|
||||
// Retrieve the error code from services like Amazon Elastic Transcoder
|
||||
if ($code = $response->getHeaderLine('x-amzn-errortype')) {
|
||||
$colon = strpos($code, ':');
|
||||
$data['code'] = $colon ? substr($code, 0, $colon) : $code;
|
||||
}
|
||||
|
||||
// Retrieve error message directly
|
||||
$data['message'] = isset($data['parsed']['message'])
|
||||
? $data['parsed']['message']
|
||||
: (isset($data['parsed']['Message'])
|
||||
? $data['parsed']['Message']
|
||||
: null);
|
||||
|
||||
$this->populateShape($data, $response, $command);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Aws\Api\Parser\XmlParser;
|
||||
use Aws\Api\Service;
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parses XML errors.
|
||||
*/
|
||||
class XmlErrorParser extends AbstractErrorParser
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
protected $parser;
|
||||
|
||||
public function __construct(Service $api = null, XmlParser $parser = null)
|
||||
{
|
||||
parent::__construct($api);
|
||||
$this->parser = $parser ?: new XmlParser();
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
ResponseInterface $response,
|
||||
CommandInterface $command = null
|
||||
) {
|
||||
$code = (string) $response->getStatusCode();
|
||||
|
||||
$data = [
|
||||
'type' => $code[0] == '4' ? 'client' : 'server',
|
||||
'request_id' => null,
|
||||
'code' => null,
|
||||
'message' => null,
|
||||
'parsed' => null
|
||||
];
|
||||
|
||||
$body = $response->getBody();
|
||||
if ($body->getSize() > 0) {
|
||||
$this->parseBody($this->parseXml($body, $response), $data);
|
||||
} else {
|
||||
$this->parseHeaders($response, $data);
|
||||
}
|
||||
|
||||
$this->populateShape($data, $response, $command);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function parseHeaders(ResponseInterface $response, array &$data)
|
||||
{
|
||||
if ($response->getStatusCode() == '404') {
|
||||
$data['code'] = 'NotFound';
|
||||
}
|
||||
|
||||
$data['message'] = $response->getStatusCode() . ' '
|
||||
. $response->getReasonPhrase();
|
||||
|
||||
if ($requestId = $response->getHeaderLine('x-amz-request-id')) {
|
||||
$data['request_id'] = $requestId;
|
||||
$data['message'] .= " (Request-ID: $requestId)";
|
||||
}
|
||||
}
|
||||
|
||||
private function parseBody(\SimpleXMLElement $body, array &$data)
|
||||
{
|
||||
$data['parsed'] = $body;
|
||||
$prefix = $this->registerNamespacePrefix($body);
|
||||
|
||||
if ($tempXml = $body->xpath("//{$prefix}Code[1]")) {
|
||||
$data['code'] = (string) $tempXml[0];
|
||||
}
|
||||
|
||||
if ($tempXml = $body->xpath("//{$prefix}Message[1]")) {
|
||||
$data['message'] = (string) $tempXml[0];
|
||||
}
|
||||
|
||||
$tempXml = $body->xpath("//{$prefix}RequestId[1]");
|
||||
if (isset($tempXml[0])) {
|
||||
$data['request_id'] = (string)$tempXml[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected function registerNamespacePrefix(\SimpleXMLElement $element)
|
||||
{
|
||||
$namespaces = $element->getDocNamespaces();
|
||||
if (!isset($namespaces[''])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Account for the default namespace being defined and PHP not
|
||||
// being able to handle it :(.
|
||||
$element->registerXPathNamespace('ns', $namespaces['']);
|
||||
return 'ns:';
|
||||
}
|
||||
|
||||
protected function payload(
|
||||
ResponseInterface $response,
|
||||
StructureShape $member
|
||||
) {
|
||||
$xmlBody = $this->parseXml($response->getBody(), $response);
|
||||
$prefix = $this->registerNamespacePrefix($xmlBody);
|
||||
$errorBody = $xmlBody->xpath("//{$prefix}Error");
|
||||
|
||||
if (is_array($errorBody) && !empty($errorBody[0])) {
|
||||
return $this->parser->parse($member, $errorBody[0]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
/**
|
||||
* Represents a list shape.
|
||||
*/
|
||||
class ListShape extends Shape
|
||||
{
|
||||
private $member;
|
||||
|
||||
public function __construct(array $definition, ShapeMap $shapeMap)
|
||||
{
|
||||
$definition['type'] = 'list';
|
||||
parent::__construct($definition, $shapeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Shape
|
||||
* @throws \RuntimeException if no member is specified
|
||||
*/
|
||||
public function getMember()
|
||||
{
|
||||
if (!$this->member) {
|
||||
if (!isset($this->definition['member'])) {
|
||||
throw new \RuntimeException('No member attribute specified');
|
||||
}
|
||||
$this->member = Shape::create(
|
||||
$this->definition['member'],
|
||||
$this->shapeMap
|
||||
);
|
||||
}
|
||||
|
||||
return $this->member;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
/**
|
||||
* Represents a map shape.
|
||||
*/
|
||||
class MapShape extends Shape
|
||||
{
|
||||
/** @var Shape */
|
||||
private $value;
|
||||
|
||||
/** @var Shape */
|
||||
private $key;
|
||||
|
||||
public function __construct(array $definition, ShapeMap $shapeMap)
|
||||
{
|
||||
$definition['type'] = 'map';
|
||||
parent::__construct($definition, $shapeMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Shape
|
||||
* @throws \RuntimeException if no value is specified
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
if (!$this->value) {
|
||||
if (!isset($this->definition['value'])) {
|
||||
throw new \RuntimeException('No value specified');
|
||||
}
|
||||
|
||||
$this->value = Shape::create(
|
||||
$this->definition['value'],
|
||||
$this->shapeMap
|
||||
);
|
||||
}
|
||||
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Shape
|
||||
*/
|
||||
public function getKey()
|
||||
{
|
||||
if (!$this->key) {
|
||||
$this->key = isset($this->definition['key'])
|
||||
? Shape::create($this->definition['key'], $this->shapeMap)
|
||||
: new Shape(['type' => 'string'], $this->shapeMap);
|
||||
}
|
||||
|
||||
return $this->key;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
<?php
|
||||
namespace Aws\Api;
|
||||
|
||||
/**
|
||||
* Represents an API operation.
|
||||
*/
|
||||
class Operation extends AbstractModel
|
||||
{
|
||||
private $input;
|
||||
private $output;
|
||||
private $errors;
|
||||
private $staticContextParams = [];
|
||||
private $contextParams;
|
||||
|
||||
public function __construct(array $definition, ShapeMap $shapeMap)
|
||||
{
|
||||
$definition['type'] = 'structure';
|
||||
|
||||
if (!isset($definition['http']['method'])) {
|
||||
$definition['http']['method'] = 'POST';
|
||||
}
|
||||
|
||||
if (!isset($definition['http']['requestUri'])) {
|
||||
$definition['http']['requestUri'] = '/';
|
||||
}
|
||||
|
||||
if (isset($definition['staticContextParams'])) {
|
||||
$this->staticContextParams = $definition['staticContextParams'];
|
||||
}
|
||||
|
||||
parent::__construct($definition, $shapeMap);
|
||||
$this->contextParams = $this->setContextParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array of the HTTP attribute of the operation:
|
||||
*
|
||||
* - method: HTTP method of the operation
|
||||
* - requestUri: URI of the request (can include URI template placeholders)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHttp()
|
||||
{
|
||||
return $this->definition['http'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the input shape of the operation.
|
||||
*
|
||||
* @return StructureShape
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
if (!$this->input) {
|
||||
if ($input = $this['input']) {
|
||||
$this->input = $this->shapeFor($input);
|
||||
} else {
|
||||
$this->input = new StructureShape([], $this->shapeMap);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output shape of the operation.
|
||||
*
|
||||
* @return StructureShape
|
||||
*/
|
||||
public function getOutput()
|
||||
{
|
||||
if (!$this->output) {
|
||||
if ($output = $this['output']) {
|
||||
$this->output = $this->shapeFor($output);
|
||||
} else {
|
||||
$this->output = new StructureShape([], $this->shapeMap);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of operation error shapes.
|
||||
*
|
||||
* @return Shape[]
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
if ($this->errors === null) {
|
||||
if ($errors = $this['errors']) {
|
||||
foreach ($errors as $key => $error) {
|
||||
$errors[$key] = $this->shapeFor($error);
|
||||
}
|
||||
$this->errors = $errors;
|
||||
} else {
|
||||
$this->errors = [];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets static modeled static values used for
|
||||
* endpoint resolution.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStaticContextParams()
|
||||
{
|
||||
return $this->staticContextParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets definition of modeled dynamic values used
|
||||
* for endpoint resolution
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getContextParams()
|
||||
{
|
||||
return $this->contextParams;
|
||||
}
|
||||
|
||||
private function setContextParams()
|
||||
{
|
||||
$members = $this->getInput()->getMembers();
|
||||
$contextParams = [];
|
||||
|
||||
foreach($members as $name => $shape) {
|
||||
if (!empty($contextParam = $shape->getContextParam())) {
|
||||
$contextParams[$contextParam['name']] = [
|
||||
'shape' => $name,
|
||||
'type' => $shape->getType()
|
||||
];
|
||||
}
|
||||
}
|
||||
return $contextParams;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace Aws\Api\Parser;
|
||||
|
||||
use Aws\Api\Service;
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\CommandInterface;
|
||||
use Aws\ResultInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractParser
|
||||
{
|
||||
/** @var \Aws\Api\Service Representation of the service API*/
|
||||
protected $api;
|
||||
|
||||
/** @var callable */
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @param Service $api Service description.
|
||||
*/
|
||||
public function __construct(Service $api)
|
||||
{
|
||||
$this->api = $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommandInterface $command Command that was executed.
|
||||
* @param ResponseInterface $response Response that was received.
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
abstract public function __invoke(
|
||||
CommandInterface $command,
|
||||
ResponseInterface $response
|
||||
);
|
||||
|
||||
abstract public function parseMemberFromStream(
|
||||
StreamInterface $stream,
|
||||
StructureShape $member,
|
||||
$response
|
||||
);
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
<?php
|
||||
namespace Aws\Api\Parser;
|
||||
|
||||
use Aws\Api\DateTimeResult;
|
||||
use Aws\Api\Shape;
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\Result;
|
||||
use Aws\CommandInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
abstract class AbstractRestParser extends AbstractParser
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
/**
|
||||
* Parses a payload from a response.
|
||||
*
|
||||
* @param ResponseInterface $response Response to parse.
|
||||
* @param StructureShape $member Member to parse
|
||||
* @param array $result Result value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function payload(
|
||||
ResponseInterface $response,
|
||||
StructureShape $member,
|
||||
array &$result
|
||||
);
|
||||
|
||||
public function __invoke(
|
||||
CommandInterface $command,
|
||||
ResponseInterface $response
|
||||
) {
|
||||
$output = $this->api->getOperation($command->getName())->getOutput();
|
||||
$result = [];
|
||||
|
||||
if ($payload = $output['payload']) {
|
||||
$this->extractPayload($payload, $output, $response, $result);
|
||||
}
|
||||
|
||||
foreach ($output->getMembers() as $name => $member) {
|
||||
switch ($member['location']) {
|
||||
case 'header':
|
||||
$this->extractHeader($name, $member, $response, $result);
|
||||
break;
|
||||
case 'headers':
|
||||
$this->extractHeaders($name, $member, $response, $result);
|
||||
break;
|
||||
case 'statusCode':
|
||||
$this->extractStatus($name, $response, $result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$payload
|
||||
&& $response->getBody()->getSize() > 0
|
||||
&& count($output->getMembers()) > 0
|
||||
) {
|
||||
// if no payload was found, then parse the contents of the body
|
||||
$this->payload($response, $output, $result);
|
||||
}
|
||||
|
||||
return new Result($result);
|
||||
}
|
||||
|
||||
private function extractPayload(
|
||||
$payload,
|
||||
StructureShape $output,
|
||||
ResponseInterface $response,
|
||||
array &$result
|
||||
) {
|
||||
$member = $output->getMember($payload);
|
||||
|
||||
if (!empty($member['eventstream'])) {
|
||||
$result[$payload] = new EventParsingIterator(
|
||||
$response->getBody(),
|
||||
$member,
|
||||
$this
|
||||
);
|
||||
} else if ($member instanceof StructureShape) {
|
||||
// Structure members parse top-level data into a specific key.
|
||||
$result[$payload] = [];
|
||||
$this->payload($response, $member, $result[$payload]);
|
||||
} else {
|
||||
// Streaming data is just the stream from the response body.
|
||||
$result[$payload] = $response->getBody();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a single header from the response into the result.
|
||||
*/
|
||||
private function extractHeader(
|
||||
$name,
|
||||
Shape $shape,
|
||||
ResponseInterface $response,
|
||||
&$result
|
||||
) {
|
||||
$value = $response->getHeaderLine($shape['locationName'] ?: $name);
|
||||
|
||||
switch ($shape->getType()) {
|
||||
case 'float':
|
||||
case 'double':
|
||||
$value = (float) $value;
|
||||
break;
|
||||
case 'long':
|
||||
$value = (int) $value;
|
||||
break;
|
||||
case 'boolean':
|
||||
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
case 'blob':
|
||||
$value = base64_decode($value);
|
||||
break;
|
||||
case 'timestamp':
|
||||
try {
|
||||
$value = DateTimeResult::fromTimestamp(
|
||||
$value,
|
||||
!empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null
|
||||
);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
// If the value cannot be parsed, then do not add it to the
|
||||
// output structure.
|
||||
return;
|
||||
}
|
||||
case 'string':
|
||||
try {
|
||||
if ($shape['jsonvalue']) {
|
||||
$value = $this->parseJson(base64_decode($value), $response);
|
||||
}
|
||||
|
||||
// If value is not set, do not add to output structure.
|
||||
if (!isset($value)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
//If the value cannot be parsed, then do not add it to the
|
||||
//output structure.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$result[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract a map of headers with an optional prefix from the response.
|
||||
*/
|
||||
private function extractHeaders(
|
||||
$name,
|
||||
Shape $shape,
|
||||
ResponseInterface $response,
|
||||
&$result
|
||||
) {
|
||||
// Check if the headers are prefixed by a location name
|
||||
$result[$name] = [];
|
||||
$prefix = $shape['locationName'];
|
||||
$prefixLen = $prefix !== null ? strlen($prefix) : 0;
|
||||
|
||||
foreach ($response->getHeaders() as $k => $values) {
|
||||
if (!$prefixLen) {
|
||||
$result[$name][$k] = implode(', ', $values);
|
||||
} elseif (stripos($k, $prefix) === 0) {
|
||||
$result[$name][substr($k, $prefixLen)] = implode(', ', $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Places the status code of the response into the result array.
|
||||
*/
|
||||
private function extractStatus(
|
||||
$name,
|
||||
ResponseInterface $response,
|
||||
array &$result
|
||||
) {
|
||||
$result[$name] = (int) $response->getStatusCode();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
namespace Aws\Api\Parser;
|
||||
|
||||
use Aws\Api\StructureShape;
|
||||
use Aws\CommandInterface;
|
||||
use Aws\Exception\AwsException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use GuzzleHttp\Psr7;
|
||||
|
||||
/**
|
||||
* @internal Decorates a parser and validates the x-amz-crc32 header.
|
||||
*/
|
||||
class Crc32ValidatingParser extends AbstractParser
|
||||
{
|
||||
/**
|
||||
* @param callable $parser Parser to wrap.
|
||||
*/
|
||||
public function __construct(callable $parser)
|
||||
{
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
public function __invoke(
|
||||
CommandInterface $command,
|
||||
ResponseInterface $response
|
||||
) {
|
||||
if ($expected = $response->getHeaderLine('x-amz-crc32')) {
|
||||
$hash = hexdec(Psr7\Utils::hash($response->getBody(), 'crc32b'));
|
||||
if ($expected != $hash) {
|
||||
throw new AwsException(
|
||||
"crc32 mismatch. Expected {$expected}, found {$hash}.",
|
||||
$command,
|
||||
[
|
||||
'code' => 'ClientChecksumMismatch',
|
||||
'connection_error' => true,
|
||||
'response' => $response
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$fn = $this->parser;
|
||||
return $fn($command, $response);
|
||||
}
|
||||
|
||||
public function parseMemberFromStream(
|
||||
StreamInterface $stream,
|
||||
StructureShape $member,
|
||||
$response
|
||||
) {
|
||||
return $this->parser->parseMemberFromStream($stream, $member, $response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,345 @@
|
|||
<?php
|
||||
|
||||
namespace Aws\Api\Parser;
|
||||
|
||||
use \Iterator;
|
||||
use Aws\Api\DateTimeResult;
|
||||
use GuzzleHttp\Psr7;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Aws\Api\Parser\Exception\ParserException;
|
||||
|
||||
/**
|
||||
* @internal Implements a decoder for a binary encoded event stream that will
|
||||
* decode, validate, and provide individual events from the stream.
|
||||
*/
|
||||
class DecodingEventStreamIterator implements Iterator
|
||||
{
|
||||
const HEADERS = 'headers';
|
||||
const PAYLOAD = 'payload';
|
||||
|
||||
const LENGTH_TOTAL = 'total_length';
|
||||
const LENGTH_HEADERS = 'headers_length';
|
||||
|
||||
const CRC_PRELUDE = 'prelude_crc';
|
||||
|
||||
const BYTES_PRELUDE = 12;
|
||||
const BYTES_TRAILING = 4;
|
||||
|
||||
private static $preludeFormat = [
|
||||
self::LENGTH_TOTAL => 'decodeUint32',
|
||||
self::LENGTH_HEADERS => 'decodeUint32',
|
||||
self::CRC_PRELUDE => 'decodeUint32',
|
||||
];
|
||||
|
||||
private static $lengthFormatMap = [
|
||||
1 => 'decodeUint8',
|
||||
2 => 'decodeUint16',
|
||||
4 => 'decodeUint32',
|
||||
8 => 'decodeUint64',
|
||||
];
|
||||
|
||||
private static $headerTypeMap = [
|
||||
0 => 'decodeBooleanTrue',
|
||||
1 => 'decodeBooleanFalse',
|
||||
2 => 'decodeInt8',
|
||||
3 => 'decodeInt16',
|
||||
4 => 'decodeInt32',
|
||||
5 => 'decodeInt64',
|
||||
6 => 'decodeBytes',
|
||||
7 => 'decodeString',
|
||||
8 => 'decodeTimestamp',
|
||||
9 => 'decodeUuid',
|
||||
];
|
||||
|
||||
/** @var StreamInterface Stream of eventstream shape to parse. */
|
||||
protected $stream;
|
||||
|
||||
/** @var array Currently parsed event. */
|
||||
protected $currentEvent;
|
||||
|
||||
/** @var int Current in-order event key. */
|
||||
protected $key;
|
||||
|
||||
/** @var resource|\HashContext CRC32 hash context for event validation */
|
||||
protected $hashContext;
|
||||
|
||||
/** @var int $currentPosition */
|
||||
protected $currentPosition;
|
||||
|
||||
/**
|
||||
* DecodingEventStreamIterator constructor.
|
||||
*
|
||||
* @param StreamInterface $stream
|
||||
*/
|
||||
public function __construct(StreamInterface $stream)
|
||||
{
|
||||
$this->stream = $stream;
|
||||
$this->rewind();
|
||||
}
|
||||
|
||||
protected function parseHeaders($headerBytes)
|
||||
{
|
||||
$headers = [];
|
||||
$bytesRead = 0;
|
||||
|
||||
while ($bytesRead < $headerBytes) {
|
||||
list($key, $numBytes) = $this->decodeString(1);
|
||||
$bytesRead += $numBytes;
|
||||
|
||||
list($type, $numBytes) = $this->decodeUint8();
|
||||
$bytesRead += $numBytes;
|
||||
|
||||
$f = self::$headerTypeMap[$type];
|
||||
list($value, $numBytes) = $this->{$f}();
|
||||
$bytesRead += $numBytes;
|
||||
|
||||
if (isset($headers[$key])) {
|
||||
throw new ParserException('Duplicate key in event headers.');
|
||||
}
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
|
||||
return [$headers, $bytesRead];
|
||||
}
|
||||
|
||||
protected function parsePrelude()
|
||||
{
|
||||
$prelude = [];
|
||||
$bytesRead = 0;
|
||||
|
||||
$calculatedCrc = null;
|
||||
foreach (self::$preludeFormat as $key => $decodeFunction) {
|
||||
if ($key === self::CRC_PRELUDE) {
|
||||
$hashCopy = hash_copy($this->hashContext);
|
||||
$calculatedCrc = hash_final($this->hashContext, true);
|
||||
$this->hashContext = $hashCopy;
|
||||
}
|
||||
list($value, $numBytes) = $this->{$decodeFunction}();
|
||||
$bytesRead += $numBytes;
|
||||
|
||||
$prelude[$key] = $value;
|
||||
}
|
||||
|
||||
if (unpack('N', $calculatedCrc)[1] !== $prelude[self::CRC_PRELUDE]) {
|
||||
throw new ParserException('Prelude checksum mismatch.');
|
||||
}
|
||||
|
||||
return [$prelude, $bytesRead];
|
||||
}
|
||||
|
||||
/**
|
||||
* This method decodes an event from the stream.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseEvent()
|
||||
{
|
||||
$event = [];
|
||||
|
||||
if ($this->stream->tell() < $this->stream->getSize()) {
|
||||
$this->hashContext = hash_init('crc32b');
|
||||
|
||||
$bytesLeft = $this->stream->getSize() - $this->stream->tell();
|
||||
list($prelude, $numBytes) = $this->parsePrelude();
|
||||
if ($prelude[self::LENGTH_TOTAL] > $bytesLeft) {
|
||||
throw new ParserException('Message length too long.');
|
||||
}
|
||||
$bytesLeft -= $numBytes;
|
||||
|
||||
if ($prelude[self::LENGTH_HEADERS] > $bytesLeft) {
|
||||
throw new ParserException('Headers length too long.');
|
||||
}
|
||||
|
||||
list(
|
||||
$event[self::HEADERS],
|
||||
$numBytes
|
||||
) = $this->parseHeaders($prelude[self::LENGTH_HEADERS]);
|
||||
|
||||
$event[self::PAYLOAD] = Psr7\Utils::streamFor(
|
||||
$this->readAndHashBytes(
|
||||
$prelude[self::LENGTH_TOTAL] - self::BYTES_PRELUDE
|
||||
- $numBytes - self::BYTES_TRAILING
|
||||
)
|
||||
);
|
||||
|
||||
$calculatedCrc = hash_final($this->hashContext, true);
|
||||
$messageCrc = $this->stream->read(4);
|
||||
if ($calculatedCrc !== $messageCrc) {
|
||||
throw new ParserException('Message checksum mismatch.');
|
||||
}
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
// Iterator Functionality
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
return $this->currentEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
$this->currentPosition = $this->stream->tell();
|
||||
if ($this->valid()) {
|
||||
$this->key++;
|
||||
$this->currentEvent = $this->parseEvent();
|
||||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
$this->stream->rewind();
|
||||
$this->key = 0;
|
||||
$this->currentPosition = 0;
|
||||
$this->currentEvent = $this->parseEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
return $this->currentPosition < $this->stream->getSize();
|
||||
}
|
||||
|
||||
// Decoding Utilities
|
||||
|
||||
protected function readAndHashBytes($num)
|
||||
{
|
||||
$bytes = $this->stream->read($num);
|
||||
hash_update($this->hashContext, $bytes);
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
private function decodeBooleanTrue()
|
||||
{
|
||||
return [true, 0];
|
||||
}
|
||||
|
||||
private function decodeBooleanFalse()
|
||||
{
|
||||
return [false, 0];
|
||||
}
|
||||
|
||||
private function uintToInt($val, $size)
|
||||
{
|
||||
$signedCap = pow(2, $size - 1);
|
||||
if ($val > $signedCap) {
|
||||
$val -= (2 * $signedCap);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
private function decodeInt8()
|
||||
{
|
||||
$val = (int)unpack('C', $this->readAndHashBytes(1))[1];
|
||||
return [$this->uintToInt($val, 8), 1];
|
||||
}
|
||||
|
||||
private function decodeUint8()
|
||||
{
|
||||
return [unpack('C', $this->readAndHashBytes(1))[1], 1];
|
||||
}
|
||||
|
||||
private function decodeInt16()
|
||||
{
|
||||
$val = (int)unpack('n', $this->readAndHashBytes(2))[1];
|
||||
return [$this->uintToInt($val, 16), 2];
|
||||
}
|
||||
|
||||
private function decodeUint16()
|
||||
{
|
||||
return [unpack('n', $this->readAndHashBytes(2))[1], 2];
|
||||
}
|
||||
|
||||
private function decodeInt32()
|
||||
{
|
||||
$val = (int)unpack('N', $this->readAndHashBytes(4))[1];
|
||||
return [$this->uintToInt($val, 32), 4];
|
||||
}
|
||||
|
||||
private function decodeUint32()
|
||||
{
|
||||
return [unpack('N', $this->readAndHashBytes(4))[1], 4];
|
||||
}
|
||||
|
||||
private function decodeInt64()
|
||||
{
|
||||
$val = $this->unpackInt64($this->readAndHashBytes(8))[1];
|
||||
return [$this->uintToInt($val, 64), 8];
|
||||
}
|
||||
|
||||
private function decodeUint64()
|
||||
{
|
||||
return [$this->unpackInt64($this->readAndHashBytes(8))[1], 8];
|
||||
}
|
||||
|
||||
private function unpackInt64($bytes)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.6.3', '<')) {
|
||||
$d = unpack('N2', $bytes);
|
||||
return [1 => $d[1] << 32 | $d[2]];
|
||||
}
|
||||
return unpack('J', $bytes);
|
||||
}
|
||||
|
||||
private function decodeBytes($lengthBytes=2)
|
||||
{
|
||||
if (!isset(self::$lengthFormatMap[$lengthBytes])) {
|
||||
throw new ParserException('Undefined variable length format.');
|
||||
}
|
||||
$f = self::$lengthFormatMap[$lengthBytes];
|
||||
list($len, $bytes) = $this->{$f}();
|
||||
return [$this->readAndHashBytes($len), $len + $bytes];
|
||||
}
|
||||
|
||||
private function decodeString($lengthBytes=2)
|
||||
{
|
||||
if (!isset(self::$lengthFormatMap[$lengthBytes])) {
|
||||
throw new ParserException('Undefined variable length format.');
|
||||
}
|
||||
$f = self::$lengthFormatMap[$lengthBytes];
|
||||
list($len, $bytes) = $this->{$f}();
|
||||
return [$this->readAndHashBytes($len), $len + $bytes];
|
||||
}
|
||||
|
||||
private function decodeTimestamp()
|
||||
{
|
||||
list($val, $bytes) = $this->decodeInt64();
|
||||
return [
|
||||
DateTimeResult::createFromFormat('U.u', $val / 1000),
|
||||
$bytes
|
||||
];
|
||||
}
|
||||
|
||||
private function decodeUuid()
|
||||
{
|
||||
$val = unpack('H32', $this->readAndHashBytes(16))[1];
|
||||
return [
|
||||
substr($val, 0, 8) . '-'
|
||||
. substr($val, 8, 4) . '-'
|
||||
. substr($val, 12, 4) . '-'
|
||||
. substr($val, 16, 4) . '-'
|
||||
. substr($val, 20, 12),
|
||||
16
|
||||
];
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue