Skip to content

Commit c3ddbd0

Browse files
author
宋神宗
authored
recover deprecated (#138)
1 parent e76b652 commit c3ddbd0

13 files changed

+221
-87
lines changed

src/Credentials/Providers/Provider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ class Provider
1515
* For TSC Duration Seconds
1616
*/
1717
const DURATION_SECONDS = 3600;
18+
1819
/**
1920
* @var array
2021
*/
2122
protected static $credentialsCache = [];
23+
2224
/**
2325
* Expiration time slot for temporary security credentials.
2426
*
2527
* @var int
2628
*/
2729
protected $expirationSlot = 180;
30+
2831
/**
2932
* @var Client
3033
*/

src/DefaultAcsClient.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,54 @@
22

33
namespace AlibabaCloud\Client;
44

5-
use RuntimeException;
5+
use AlibabaCloud\Client\Result\Result;
6+
use AlibabaCloud\Client\Clients\Client;
7+
use AlibabaCloud\Client\Request\Request;
8+
use AlibabaCloud\Client\Exception\ClientException;
9+
use AlibabaCloud\Client\Exception\ServerException;
610

711
/**
812
* Class DefaultAcsClient
913
*
1014
* @package AlibabaCloud
1115
*
12-
* @deprecated
16+
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
1317
* @codeCoverageIgnore
1418
*/
1519
class DefaultAcsClient
1620
{
1721

22+
/**
23+
* @var string
24+
*/
25+
public $randClientName;
26+
1827
/**
1928
* DefaultAcsClient constructor.
29+
*
30+
* @param Client $client
31+
*
32+
* @throws ClientException
2033
*/
21-
public function __construct()
34+
public function __construct(Client $client)
2235
{
23-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud instead.');
36+
$this->randClientName = \uniqid('', true);
37+
$client->name($this->randClientName);
38+
}
39+
40+
/**
41+
* @param Request|Result $request
42+
*
43+
* @return Result|string
44+
* @throws ClientException
45+
* @throws ServerException
46+
*/
47+
public function getAcsResponse($request)
48+
{
49+
if ($request instanceof Result) {
50+
return $request;
51+
}
52+
53+
return $request->client($this->randClientName)->request();
2454
}
2555
}

src/Exception/AlibabaCloudException.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace AlibabaCloud\Client\Exception;
44

5+
use Exception;
56
use RuntimeException;
67

78
/**
89
* Class AlibabaCloudException
910
*
1011
* @package AlibabaCloud\Client\Exception
1112
*/
12-
abstract class AlibabaCloudException extends \Exception
13+
abstract class AlibabaCloudException extends Exception
1314
{
1415

1516
/**
@@ -49,11 +50,14 @@ public function getErrorMessage()
4950

5051
/**
5152
* @codeCoverageIgnore
53+
*
54+
* @param $errorMessage
55+
*
5256
* @deprecated
5357
*/
54-
public function setErrorMessage()
58+
public function setErrorMessage($errorMessage)
5559
{
56-
throw new RuntimeException('deprecated since 2.0.');
60+
$this->errorMessage = $errorMessage;
5761
}
5862

5963
/**
@@ -62,6 +66,5 @@ public function setErrorMessage()
6266
*/
6367
public function setErrorType()
6468
{
65-
throw new RuntimeException('deprecated since 2.0.');
6669
}
6770
}

src/Exception/ClientException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public function __construct($errorMessage, $errorCode, $previous = null)
3333
*/
3434
public function getErrorType()
3535
{
36-
throw new RuntimeException('deprecated since 2.0.');
36+
return 'Client';
3737
}
3838
}

src/Exception/ServerException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function getRequestId()
144144
*/
145145
public function getErrorType()
146146
{
147-
throw new RuntimeException('deprecated since 2.0.');
147+
return 'Server';
148148
}
149149

150150
/**
@@ -153,6 +153,6 @@ public function getErrorType()
153153
*/
154154
public function getHttpStatus()
155155
{
156-
throw new RuntimeException('deprecated since 2.0, Use getResult()->getResponse()->getStatusCode() instead.');
156+
return $this->getResult()->getResponse()->getStatusCode();
157157
}
158158
}

src/Profile/DefaultProfile.php

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,73 @@
22

33
namespace AlibabaCloud\Client\Profile;
44

5-
use RuntimeException;
5+
use AlibabaCloud\Client\AlibabaCloud;
6+
use AlibabaCloud\Client\Clients\Client;
7+
use AlibabaCloud\Client\Exception\ClientException;
68

79
/**
810
* Class DefaultProfile
911
*
1012
* @package AlibabaCloud\Client\Profile
11-
*
12-
* @deprecated
1313
* @codeCoverageIgnore
14+
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
1415
*/
1516
class DefaultProfile
1617
{
17-
public static function getProfile()
18+
19+
/**
20+
* @param string $regionId
21+
* @param string $accessKeyId
22+
* @param string $accessKeySecret
23+
*
24+
* @return Client
25+
* @throws ClientException
26+
*/
27+
public static function getProfile($regionId, $accessKeyId, $accessKeySecret)
1828
{
19-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::accessKeyClient() instead.');
29+
return AlibabaCloud::accessKeyClient($accessKeyId, $accessKeySecret)
30+
->regionId($regionId);
2031
}
2132

22-
public static function getRamRoleArnProfile()
33+
/**
34+
* @param string $regionId
35+
* @param string $accessKeyId
36+
* @param string $accessKeySecret
37+
* @param string $roleArn
38+
* @param string $roleSessionName
39+
*
40+
* @return Client
41+
* @throws ClientException
42+
*/
43+
public static function getRamRoleArnProfile($regionId, $accessKeyId, $accessKeySecret, $roleArn, $roleSessionName)
2344
{
24-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::ramRoleArnClient() instead.');
45+
return AlibabaCloud::ramRoleArnClient($accessKeyId, $accessKeySecret, $roleArn, $roleSessionName)
46+
->regionId($regionId);
2547
}
2648

27-
public static function getEcsRamRoleProfile()
49+
/**
50+
* @param string $regionId
51+
* @param string $roleName
52+
*
53+
* @return Client
54+
* @throws ClientException
55+
*/
56+
public static function getEcsRamRoleProfile($regionId, $roleName)
2857
{
29-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::ecsRamRoleClient() instead.');
58+
return AlibabaCloud::ecsRamRoleClient($roleName)
59+
->regionId($regionId);
3060
}
3161

32-
public static function getBearerTokenProfile()
62+
/**
63+
* @param string $regionId
64+
* @param string $bearerToken
65+
*
66+
* @return Client
67+
* @throws ClientException
68+
*/
69+
public static function getBearerTokenProfile($regionId, $bearerToken)
3370
{
34-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::bearerTokenClient() instead.');
71+
return AlibabaCloud::bearerTokenClient($bearerToken)
72+
->regionId($regionId);
3573
}
3674
}

src/Regions/EndpointProvider.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22

33
namespace AlibabaCloud\Client\Regions;
44

5-
use RuntimeException;
5+
use AlibabaCloud\Client\Traits\EndpointTrait;
66

77
/**
88
* Class EndpointProvider
99
*
1010
* @package AlibabaCloud\Client\Regions
1111
*
12-
* @deprecated
12+
* @deprecated deprecated since version 2.0, Use AlibabaCloud instead.
1313
* @codeCoverageIgnore
1414
*/
1515
class EndpointProvider
1616
{
17-
/**
18-
* @deprecated
19-
*/
20-
public static function findProductDomain()
21-
{
22-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::resolveHost() instead.');
23-
}
24-
25-
/**
26-
* @deprecated
27-
*/
28-
public static function addEndpoint()
29-
{
30-
throw new RuntimeException('deprecated since 2.0, Use AlibabaCloud::addHost() instead.');
31-
}
17+
use EndpointTrait;
3218
}

src/Regions/LocationService.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,35 @@ private function __construct(Request $request)
4646
}
4747

4848
/**
49+
* @param Request $request
50+
* @param string $domain
51+
*
52+
* @return string
53+
* @throws ClientException
54+
* @throws ServerException
4955
* @deprecated
5056
* @codeCoverageIgnore
5157
*/
52-
public static function findProductDomain()
58+
public static function findProductDomain(Request $request, $domain = 'location.aliyuncs.com')
5359
{
54-
throw new RuntimeException('deprecated since 2.0, Use resolveHost() instead.');
60+
return self::resolveHost($request, $domain);
5561
}
5662

5763
/**
64+
* @param $regionId
65+
* @param $product
66+
* @param $domain
67+
*
68+
* @throws ClientException
5869
* @deprecated
5970
* @codeCoverageIgnore
6071
*/
61-
public static function addEndPoint()
72+
public static function addEndPoint($regionId, $product, $domain)
6273
{
63-
throw new RuntimeException('deprecated since 2.0, Use addHost() instead.');
74+
self::addHost($product, $domain, $regionId);
6475
}
6576

77+
6678
/**
6779
* @param Request $request
6880
* @param string $domain

src/Request/Traits/DeprecatedRoaTrait.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,54 @@
22

33
namespace AlibabaCloud\Client\Request\Traits;
44

5-
use RuntimeException;
6-
75
/**
86
* @package AlibabaCloud\Client\Request\Traits
97
* @codeCoverageIgnore
108
*/
119
trait DeprecatedRoaTrait
1210
{
1311
/**
12+
* @param $name
13+
* @param $value
14+
*
15+
* @return $this
1416
* @deprecated
1517
* @codeCoverageIgnore
1618
*/
17-
public function putPathParameter()
19+
public function putPathParameter($name, $value)
1820
{
19-
throw new RuntimeException('deprecated since 2.0, Use pathParameter() instead.');
21+
return $this->pathParameter($name, $value);
2022
}
2123

2224
/**
25+
* @param $pathPattern
26+
*
27+
* @return $this
2328
* @deprecated
2429
* @codeCoverageIgnore
2530
*/
26-
public function setUriPattern()
31+
public function setUriPattern($pathPattern)
2732
{
28-
throw new RuntimeException('deprecated since 2.0, Use pathPattern() instead.');
33+
return $this->pathPattern($pathPattern);
2934
}
3035

3136
/**
37+
* @return string
3238
* @deprecated
3339
* @codeCoverageIgnore
3440
*/
3541
public function getUriPattern()
3642
{
37-
throw new RuntimeException('deprecated since 2.0, Use pathPattern instead.');
43+
return $this->pathPattern;
3844
}
3945

4046
/**
47+
* @return array
4148
* @deprecated
4249
* @codeCoverageIgnore
4350
*/
4451
public function getPathParameters()
4552
{
46-
throw new RuntimeException('deprecated since 2.0, Use pathParameters instead.');
53+
return $this->pathParameters;
4754
}
4855
}

0 commit comments

Comments
 (0)