初始化仓库

This commit is contained in:
wangxiaowei
2025-04-22 14:09:52 +08:00
commit 8b100110bb
5155 changed files with 664201 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
namespace AlibabaCloud\Client\Support;
/**
* Class Arrays
*
* @package AlibabaCloud\Client\Support
*/
class Arrays
{
/**
* @param array $arrays
*
* @return array
*/
public static function merge(array $arrays)
{
$result = [];
foreach ($arrays as $array) {
foreach ($array as $key => $value) {
if (is_int($key)) {
$result[] = $value;
continue;
}
if (isset($result[$key]) && is_array($result[$key])) {
$result[$key] = self::merge(
[$result[$key], $value]
);
continue;
}
$result[$key] = $value;
}
}
return $result;
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace AlibabaCloud\Client\Support;
/**
* Class Path
*
* @package AlibabaCloud\Client\Support
*/
class Path
{
/**
* Assign path parameters to the url.
*
* @param string $pattern
* @param array $parameters
*
* @return string
*/
public static function assign($pattern, array $parameters)
{
foreach ($parameters as $key => $value) {
$pattern = str_replace("[$key]", $value, $pattern);
}
return $pattern;
}
}

View File

@ -0,0 +1,143 @@
<?php
namespace AlibabaCloud\Client\Support;
use GuzzleHttp\Psr7\Request;
use Psr\Http\Message\UriInterface;
/**
* Class Sign
*
* @package AlibabaCloud\Client\Support
*/
class Sign
{
/**
* @var string
*/
private static $headerSeparator = "\n";
/**
* Construct standard Header for Alibaba Cloud.
*
* @param array $headers
*
* @return string
*/
private static function acsHeaderString(array $headers)
{
$array = [];
foreach ($headers as $headerKey => $headerValue) {
$key = strtolower($headerKey);
if (strncmp($key, 'x-acs-', 6) === 0) {
$array[$key] = $headerValue;
}
}
ksort($array);
$string = '';
foreach ($array as $sortMapKey => $sortMapValue) {
$string .= $sortMapKey . ':' . $sortMapValue[0] . self::$headerSeparator;
}
return $string;
}
/**
* @param UriInterface $uri
*
* @return string
*/
private static function resourceString(UriInterface $uri)
{
return $uri->getPath() . '?' . rawurldecode($uri->getQuery());
}
/**
* @param string $method
* @param array $headers
*
* @return string
*/
private static function headerString($method, array $headers)
{
$string = $method . self::$headerSeparator;
if (isset($headers['Accept'][0])) {
$string .= $headers['Accept'][0];
}
$string .= self::$headerSeparator;
if (isset($headers['Content-MD5'][0])) {
$string .= $headers['Content-MD5'][0];
}
$string .= self::$headerSeparator;
if (isset($headers['Content-Type'][0])) {
$string .= $headers['Content-Type'][0];
}
$string .= self::$headerSeparator;
if (isset($headers['Date'][0])) {
$string .= $headers['Date'][0];
}
$string .= self::$headerSeparator;
$string .= self::acsHeaderString($headers);
return $string;
}
/**
* @param string $string
*
* @return null|string|string[]
*/
private static function percentEncode($string)
{
$result = urlencode($string);
$result = str_replace(['+', '*'], ['%20', '%2A'], $result);
$result = preg_replace('/%7E/', '~', $result);
return $result;
}
/**
* @param string $method
* @param array $parameters
*
* @return string
*/
public static function rpcString($method, array $parameters)
{
ksort($parameters);
$canonicalized = '';
foreach ($parameters as $key => $value) {
if ($value === null || $value === '') {
continue;
}
$canonicalized .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value);
}
return $method . '&%2F&' . self::percentEncode(substr($canonicalized, 1));
}
/**
* @param Request $request
*
* @return string
*/
public static function roaString(Request $request)
{
return self::headerString($request->getMethod(), $request->getHeaders()) .
self::resourceString($request->getUri());
}
/**
* @param string $salt
*
* @return string
*/
public static function uuid($salt)
{
return md5($salt . uniqid(md5(microtime(true)), true)) . microtime();
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace AlibabaCloud\Client\Support;
/**
* Class Stringy
*
* @package AlibabaCloud\Client\Support
*/
class Stringy
{
private static function _value($value, $default = '')
{
return null === $value ? $default : $value;
}
/**
* @param string $str
* @param string $substr
*
* @return bool
*/
public static function contains($str, $substr)
{
return false !== strpos(self::_value($str), self::_value($substr));
}
/**
* @param string $str
* @param string $substr
*
* @return bool
*/
public static function endsWith($str, $substr)
{
$str = self::_value($str);
$substr = self::_value($substr);
$length = \strlen($substr);
if (!$length) {
return true;
}
return substr($str, -$length) === $substr;
}
}