.gitignore000064400000000472146412126470006546 0ustar00composer.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.dist000064400000005666146412126470007007 0ustar00setRiskyAllowed(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__) ); LICENSE000064400000001115146412126470005556 0ustar00Copyright (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.md000064400000001274146412126470006334 0ustar00English | [简体中文](README-CN.md) ![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) ## 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.md000064400000001215146412126470006031 0ustar00[English](README.md) | 简体中文 ![](https://aliyunsdk-pages.alicdn.com/icons/AlibabaCloud.svg) ## 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.json000064400000001537146412126470007303 0ustar00{ "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": "^5.0", "symfony/var-dumper": "^5.0" }, "autoload": { "psr-4": { "AlibabaCloud\\Endpoint\\": "src" } }, "autoload-dev": { "psr-4": { "AlibabaCloud\\Endpoint\\Tests\\": "tests" } }, "scripts": { "fixer": "php-cs-fixer fix ./", "test": [ "@clearCache", "phpunit --colors=always" ], "clearCache": "rm -rf cache/*" }, "config": { "sort-packages": true, "preferred-install": "dist", "optimize-autoloader": true }, "prefer-stable": true }phpunit.xml000064400000002045146412126470006765 0ustar00 tests ./tests/Unit integration ./src src/Endpoint.php000064400000004136146412126470007637 0ustar00..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 ('' !== $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.php000064400000003756146412126470011061 0ustar00expectException(\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.php000064400000000151146412126470010440 0ustar00