.gitignore 0000644 00000000472 14641221656 0006546 0 ustar 00 composer.phar
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
composer.lock
.idea
.DS_Store
cache/
*.cache
runtime/
.php_cs.dist 0000644 00000005666 14641221656 0007007 0 ustar 00 setRiskyAllowed(true)
->setIndent(' ')
->setRules([
'@PSR2' => true,
'@PhpCsFixer' => true,
'@Symfony:risky' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'array_indentation' => true,
'combine_consecutive_unsets' => true,
'method_separation' => true,
'single_quote' => true,
'declare_equal_normalize' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'include' => true,
'lowercase_cast' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_leading_import_slash' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_spaces_around_offset' => true,
'no_unneeded_control_parentheses' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'object_operator_without_whitespace' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,
'no_extra_consecutive_blank_lines' => [
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'square_brace_block',
'throw',
'use',
],
'binary_operator_spaces' => [
'align_double_arrow' => true,
'align_equals' => true,
],
'braces' => [
'allow_single_line_closure' => true,
],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('tests')
->in(__DIR__)
);
LICENSE 0000644 00000001115 14641221656 0005556 0 ustar 00 Copyright (c) 2009-present, Alibaba Cloud 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.
README-CN.md 0000644 00000001274 14641221656 0006334 0 ustar 00 English | [简体中文](README-CN.md)

## Alibaba Cloud Endpoint Library for PHP
## Installation
### Composer
```bash
composer require alibabacloud/endpoint-util
```
## Issues
[Opening an Issue](https://github.com/aliyun/endpoint-util/issues/new), Issues not conforming to the guidelines may be closed immediately.
## Changelog
Detailed changes for each release are documented in the [release notes](./ChangeLog.txt).
## References
* [Latest Release](https://github.com/aliyun/endpoint-util)
## License
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
README.md 0000644 00000001215 14641221656 0006031 0 ustar 00 [English](README.md) | 简体中文

## Alibaba Cloud Endpoint Library for PHP
## 安装
### Composer
```bash
composer require alibabacloud/endpoint-util
```
## 问题
[提交 Issue](https://github.com/aliyun/endpoint-util/issues/new),不符合指南的问题可能会立即关闭。
## 发行说明
每个版本的详细更改记录在[发行说明](./ChangeLog.txt)中。
## 相关
* [最新源码](https://github.com/aliyun/endpoint-util)
## 许可证
[Apache-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Copyright (c) 2009-present, Alibaba Cloud All rights reserved.
composer.json 0000644 00000001524 14641221656 0007277 0 ustar 00 {
"name": "alibabacloud/endpoint-util",
"description": "Alibaba Cloud Endpoint Library for PHP",
"type": "library",
"license": "Apache-2.0",
"authors": [
{
"name": "Alibaba Cloud SDK",
"email": "sdk-team@alibabacloud.com"
}
],
"require": {
"php": ">5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35|^5.4.3"
},
"autoload": {
"psr-4": {
"AlibabaCloud\\Endpoint\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"AlibabaCloud\\Endpoint\\Tests\\": "tests"
}
},
"scripts": {
"fixer": "php-cs-fixer fix ./",
"test": [
"@clearCache",
"./vendor/bin/phpunit --colors=always"
],
"clearCache": "rm -rf cache/*"
},
"config": {
"sort-packages": true,
"preferred-install": "dist",
"optimize-autoloader": true
},
"prefer-stable": true
} phpunit.xml 0000644 00000002045 14641221656 0006765 0 ustar 00
tests
./tests/Unit
integration
./src
src/Endpoint.php 0000644 00000004137 14641221656 0007640 0 ustar 00 ..aliyuncs.com';
const CENTRAL_RULES = '.aliyuncs.com';
/**
* @param string $product required
* @param string $regionId optional It will be required when endpoint type is 'regional'
* @param string $endpointType optional regional|central
* @param string $network optional
* @param string $suffix optional
*
* @throws \InvalidArgumentException
*
* @return string
*/
public static function getEndpointRules($product, $regionId, $endpointType = '', $network = '', $suffix = '')
{
if (empty($product)) {
throw new \InvalidArgumentException('Product name cannot be empty.');
}
$endpoint = self::REGIONAL_RULES;
if (self::ENDPOINT_TYPE_REGIONAL === $endpointType) {
if (empty($regionId)) {
throw new \InvalidArgumentException('RegionId is empty, please set a valid RegionId');
}
$endpoint = self::render($endpoint, 'region_id', strtolower($regionId));
} elseif (self::ENDPOINT_TYPE_CENTRAL === $endpointType) {
$endpoint = self::CENTRAL_RULES;
} else {
throw new \InvalidArgumentException('Invalid EndpointType');
}
if (!empty($network) && 'public' !== $network) {
$endpoint = self::render($endpoint, 'network', '-' . $network);
} else {
$endpoint = self::render($endpoint, 'network', '');
}
if (!empty($suffix)) {
$endpoint = self::render($endpoint, 'suffix', '-' . $suffix);
} else {
$endpoint = self::render($endpoint, 'suffix', '');
}
return self::render($endpoint, 'product', strtolower($product));
}
private static function render($str, $tag, $replace)
{
return str_replace('<' . $tag . '>', $replace, $str);
}
}
tests/EndpointTest.php 0000644 00000003756 14641221656 0011061 0 ustar 00 expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Product name cannot be empty.');
Endpoint::getEndpointRules('', '', '', '');
}
public function testGetEndpointWhenInvalidEndpointType()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid EndpointType');
Endpoint::getEndpointRules('ecs', '', 'fake endpoint type', '');
}
public function testGetEndpointWhenInvalidRegionId()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('RegionId is empty, please set a valid RegionId');
Endpoint::getEndpointRules('ecs', '', Endpoint::ENDPOINT_TYPE_REGIONAL, '');
}
public function testGetEndpointCentral()
{
$endpoint = Endpoint::getEndpointRules('ecs', '', Endpoint::ENDPOINT_TYPE_CENTRAL);
$this->assertEquals('ecs.aliyuncs.com', $endpoint);
}
public function testGetEndpointRegional()
{
$endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL);
$this->assertEquals('ecs.cn-hangzhou.aliyuncs.com', $endpoint);
}
public function testGetEndpointRegionalWithNetwork()
{
$endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL, 'internal');
$this->assertEquals('ecs-internal.cn-hangzhou.aliyuncs.com', $endpoint);
}
public function testGetEndpointRegionalWithSuffix()
{
$endpoint = Endpoint::getEndpointRules('ecs', 'cn-hangzhou', Endpoint::ENDPOINT_TYPE_REGIONAL, 'internal', 'test');
$this->assertEquals('ecs-test-internal.cn-hangzhou.aliyuncs.com', $endpoint);
}
}
tests/bootstrap.php 0000644 00000000151 14641221656 0010440 0 ustar 00