├── .gitignore
├── LICENSE
├── NAMING.md
├── README.md
├── composer.json
├── docs
└── img
│ ├── nacos-mug-1.jpg
│ └── nacos-mug-2.jpg
├── src
└── alibaba
│ └── nacos
│ ├── DummyNacosClient.php
│ ├── Nacos.php
│ ├── NacosClient.php
│ ├── NacosClientInterface.php
│ ├── NacosConfig.php
│ ├── Naming.php
│ ├── NamingClient.php
│ ├── NamingConfig.php
│ ├── enum
│ └── ErrorCodeEnum.php
│ ├── exception
│ ├── RequestUriRequiredException.php
│ ├── RequestVerbRequiredException.php
│ └── ResponseCodeErrorException.php
│ ├── failover
│ ├── LocalConfigInfoProcessor.php
│ ├── LocalDiscoveryInfoProcessor.php
│ ├── LocalDiscoveryListInfoProcessor.php
│ └── Processor.php
│ ├── listener
│ ├── Listener.php
│ └── config
│ │ ├── Config.php
│ │ ├── GetConfigRequestErrorListener.php
│ │ └── ListenerConfigRequestErrorListener.php
│ ├── model
│ ├── Beat.php
│ ├── Host.php
│ ├── Instance.php
│ ├── InstanceList.php
│ └── Model.php
│ ├── request
│ ├── Request.php
│ ├── config
│ │ ├── ConfigRequest.php
│ │ ├── DeleteConfigRequest.php
│ │ ├── GetConfigRequest.php
│ │ ├── ListenerConfigRequest.php
│ │ └── PublishConfigRequest.php
│ └── naming
│ │ ├── BeatInstanceNaming.php
│ │ ├── DeleteInstanceNaming.php
│ │ ├── GetInstanceNaming.php
│ │ ├── ListInstanceNaming.php
│ │ ├── NamingRequest.php
│ │ ├── RegisterInstanceNaming.php
│ │ └── UpdateInstanceNaming.php
│ └── util
│ ├── DiscoveryUtil.php
│ ├── EncodeUtil.php
│ ├── FileUtil.php
│ ├── HttpUtil.php
│ ├── LogUtil.php
│ ├── MapperUtil.php
│ └── ReflectionUtil.php
└── tests
├── DummyNacosTest.php
├── Ipv6NamingTest.php
├── NacosTest.php
├── NamingTest.php
├── TestCase.php
├── listener
└── config
│ └── GetConfigRequestErrorListenerTest.php
├── request
├── config
│ ├── DeleteConfigRequestTest.php
│ ├── GetConfigRequestTest.php
│ ├── ListenerConfigRequestTest.php
│ ├── PublishConfigRequestTest.php
│ └── env-example
└── naming
│ ├── BeatInstanceNamingTest.php
│ ├── DeleteInstanceNamingTest.php
│ ├── GetInstanceNamingTest.php
│ ├── ListInstanceNamingTest.php
│ ├── RegisterInstanceNamingTest.php
│ └── UpdateInstanceNamingTest.php
└── util
├── EncodeTest.php
├── HttpUtilTest.php
├── LogUtilTest.php
└── env-example
/.gitignore:
--------------------------------------------------------------------------------
1 | tests/nacos/*
2 |
3 | composer.phar
4 | /vendor/
5 |
6 | .idea/
7 | composer.lock
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2010-2019 suxiaolin. https://neatlife.github.io
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/NAMING.md:
--------------------------------------------------------------------------------
1 | # 服务发现
2 |
3 | ## 配置成客户端发送实例心跳
4 | ```php
5 | NacosConfig::setHost("http://127.0.0.1:8848/"); // 配置中心地址
6 | $naming = Naming::init(
7 | "nacos.test.1",
8 | "11.11.11.11",
9 | "8848"
10 | );
11 | ```
12 |
13 | ## 配置成服务端检测实例是否存活
14 | ```php
15 | NacosConfig::setHost("http://127.0.0.1:8848/"); // 配置中心地址
16 | $naming = Naming::init(
17 | "nacos.test.1",
18 | "11.11.11.11",
19 | "8848",
20 | "",
21 | "",
22 | false
23 | );
24 | ```
25 | 主要是最后一个参数需要置为false,设置后nacos服务器会自动检测ip和端口匹配的实例是否存活
26 | 设置后就无需客户端发送实例心跳了
27 |
28 | ## 注册实例
29 |
30 | ```php
31 | $naming->register();
32 | ```
33 |
34 | ## 删除实例
35 | ```php
36 | $naming->delete();
37 | ```
38 |
39 | ## 修改实例
40 | ```php
41 | $naming->update(0.8);
42 | ```
43 |
44 | ## 查询实例列表
45 |
46 | ```php
47 | $instanceList = $naming->listInstances();
48 | ```
49 |
50 | ## 查询实例详情
51 | ```php
52 | $instance = $naming->get();
53 | ```
54 |
55 | ## 发送实例心跳
56 |
57 | ```php
58 | $beat = $naming->beat();
59 | ```
60 |
61 | 定时5秒发送一次心跳
62 |
63 | ```bash
64 | #!/bin/bash
65 |
66 | while true; do
67 | php path/to/beat.php
68 | sleep 5;
69 | done
70 | ```
71 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 阿里巴巴nacos配置中心-PHP客户端
2 |
3 | [Nacos配置中心](https://github.com/alibaba/nacos)的PHP客户端,更多关于Nacos配置中心的介绍,可以查看[Nacos配置中心Wiki](https://github.com/alibaba/nacos/wiki)。
4 |
5 | ### 特性
6 |
7 | 1. 容错兜底
8 | 2. 容易上手
9 | 3. 技术支持,有问题可加作者微信: suxiaolinKing
10 |
11 | ### 开发计划
12 |
13 | - [x] 增强容错机制
14 | - [x] [实现服务发现](NAMING.md)
15 | - [x] [Laravel框架集成](https://juejin.im/post/5ccf645b6fb9a032435dba16)
16 | - [x] Dummy模式(本地开发不走配置中心)
17 | - [ ] Yii框架集成
18 | - [ ] ThinkPHP框架集成
19 | - [ ] Symfony框架集成
20 |
21 | ## composer安装
22 |
23 | ``` bash
24 | composer require alibaba/nacos
25 | ```
26 |
27 | ## 使用crontab拉取配置文件
28 |
29 | 定时1分钟拉取一次
30 |
31 | ```bash
32 | */1 */1 * * * php path/to/cron.php
33 | ```
34 |
35 | ```php
36 | # cron.php
37 | Nacos::init(
38 | "http://127.0.0.1:8848/",
39 | "dev",
40 | "LARAVEL",
41 | "DEFAULT_GROUP",
42 | ""
43 | )->runOnce();
44 | ```
45 |
46 | 拉取到的配置文件路径:当前工作目录/nacos/config/dev_nacos/snapshot/LARAVEL
47 |
48 | 配置文件保存的工作目录可以通过下面命令修改
49 |
50 | ```php
51 | NacosConfig::setSnapshotPath("指定存放配置文件的目录路径");
52 | ```
53 |
54 | ## 长轮询拉取配置文件
55 |
56 | ```php
57 | Nacos::init(
58 | "http://127.0.0.1:8848/",
59 | "dev",
60 | "LARAVEL",
61 | "DEFAULT_GROUP",
62 | ""
63 | )->listener();
64 | ```
65 |
66 | ## 事件监听器
67 |
68 | ```php
69 | GetConfigRequestErrorListener::add(function($config) {
70 | if (!$config->getConfig()) {
71 | echo "获取配置异常, 配置为空,下面进行自定义逻辑处理" . PHP_EOL;
72 | // 设置是否修改配置文件内容,如果修改成true,这里设置的配置文件内容将是最终获取到的配置文件
73 | $config->setChanged(true);
74 | $config->setConfig("hello");
75 | }
76 | });
77 | ```
78 |
79 | ## 配置兜底方案
80 |
81 | 将兜底的配置文件放入下面的路径里
82 |
83 | 如果有给$tenant设置值,文件路径这样计算
84 |
85 | 工作目录/nacos/config/{$env}_nacos/config-data-{$tenant}/{$dataId}
86 |
87 | 否则
88 |
89 | 工作目录/nacos/config/{$env}_nacos/config-data/{$dataId}
90 |
91 | nacos会在无法从配置中心查询配置文件时将读取上面的配置文件
92 |
93 | ## Dummy模式(本地开发不走配置中心)
94 |
95 | 配置环境变量NACOS_ENV=local再启动项目
96 |
97 | ```shell
98 | export NACOS_ENV=local
99 | ```
100 |
101 | ## 贡献者 ✨
102 |
103 |
104 | Thanks goes to these wonderful people:
105 |
106 |
135 |
136 | Contributions of any kind are welcome!
137 |
138 | ## 感谢nacos团队赠送的纪念杯
139 |
140 | 
141 | 
142 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "alibaba/nacos",
3 | "description": "阿里巴巴nacos配置中心php客户端",
4 | "type": "library",
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "suxiaolin",
9 | "email": "dear.lin@live.com"
10 | }
11 | ],
12 | "require": {
13 | "guzzlehttp/guzzle": "^6.3|^7.0.0",
14 | "monolog/monolog": "^1.24|^2.0",
15 | "ext-json": "*"
16 | },
17 | "require-dev": {
18 | "phpunit/phpunit": "^7.5|^8.0"
19 | },
20 | "autoload": {
21 | "psr-4": {
22 | "alibaba\\": "src/alibaba/"
23 | }
24 | },
25 | "autoload-dev": {
26 | "psr-4": {
27 | "tests\\": "tests/"
28 | }
29 | },
30 | "minimum-stability": "dev",
31 | "prefer-stable": true
32 | }
33 |
--------------------------------------------------------------------------------
/docs/img/nacos-mug-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neatlife/php-nacos/024c0bd67d84a82c7c2ebe5f390e8d8b16284ef9/docs/img/nacos-mug-1.jpg
--------------------------------------------------------------------------------
/docs/img/nacos-mug-2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/neatlife/php-nacos/024c0bd67d84a82c7c2ebe5f390e8d8b16284ef9/docs/img/nacos-mug-2.jpg
--------------------------------------------------------------------------------
/src/alibaba/nacos/DummyNacosClient.php:
--------------------------------------------------------------------------------
1 | setDataId($dataId);
33 | $listenerConfigRequest->setGroup($group);
34 | $listenerConfigRequest->setTenant($tenant);
35 | $listenerConfigRequest->setContentMD5(md5($config));
36 |
37 | try {
38 | $response = $listenerConfigRequest->doRequest();
39 | if ($response->getBody()->getContents()) {
40 | // 配置发生了变化
41 | $config = self::get($env, $dataId, $group, $tenant);
42 |
43 | LogUtil::info("found changed config: " . $config);
44 |
45 | // 保存最新的配置
46 | LocalConfigInfoProcessor::saveSnapshot($env, $dataId, $group, $tenant, $config);
47 | }
48 | } catch (Exception $e) {
49 | LogUtil::error("listener请求异常, e: " . $e->getMessage());
50 | ListenerConfigRequestErrorListener::notify($env, $dataId, $group, $tenant);
51 | // 短暂休息会儿
52 | usleep(500);
53 | }
54 | LogUtil::info("listener loop count: " . $loop);
55 | } while (true);
56 | }
57 |
58 | public static function get($env, $dataId, $group, $tenant)
59 | {
60 | $getConfigRequest = new GetConfigRequest();
61 | $getConfigRequest->setDataId($dataId);
62 | $getConfigRequest->setGroup($group);
63 | $getConfigRequest->setTenant($tenant);
64 |
65 | try {
66 | $response = $getConfigRequest->doRequest();
67 | $config = $response->getBody()->getContents();
68 | LocalConfigInfoProcessor::saveSnapshot($env, $dataId, $group, $tenant, $config);
69 | } catch (Exception $e) {
70 | LogUtil::error("获取配置异常,开始从本地获取配置, message: " . $e->getMessage());
71 | $config = LocalConfigInfoProcessor::getFailover($env, $dataId, $group, $tenant);
72 | $config = $config ? $config
73 | : LocalConfigInfoProcessor::getSnapshot($env, $dataId, $group, $tenant);
74 | $configListenerParameter = Config::of($env, $dataId, $group, $tenant, $config);
75 | GetConfigRequestErrorListener::notify($configListenerParameter);
76 | if ($configListenerParameter->isChanged()) {
77 | $config = $configListenerParameter->getConfig();
78 | }
79 | }
80 |
81 | return $config;
82 | }
83 |
84 | public static function publish($dataId, $group, $content, $tenant = "")
85 | {
86 | $publishConfigRequest = new PublishConfigRequest();
87 | $publishConfigRequest->setDataId($dataId);
88 | $publishConfigRequest->setGroup($group);
89 | $publishConfigRequest->setTenant($tenant);
90 | $publishConfigRequest->setContent($content);
91 |
92 | try {
93 | $response = $publishConfigRequest->doRequest();
94 | } catch (Exception $e) {
95 | return false;
96 | }
97 | return $response->getBody()->getContents() == "true";
98 | }
99 |
100 | public static function delete($dataId, $group, $tenant)
101 | {
102 | $deleteConfigRequest = new DeleteConfigRequest();
103 | $deleteConfigRequest->setDataId($dataId);
104 | $deleteConfigRequest->setGroup($group);
105 | $deleteConfigRequest->setTenant($tenant);
106 |
107 | $response = $deleteConfigRequest->doRequest();
108 | return $response->getBody()->getContents() == "true";
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/NacosClientInterface.php:
--------------------------------------------------------------------------------
1 | get();
145 | }
146 | return NamingClient::beat(
147 | NamingConfig::getServiceName(),
148 | $instance->encode()
149 | );
150 | }
151 |
152 | /**
153 | * @param bool $healthyOnly
154 | * @param string $weight
155 | * @param string $namespaceId
156 | * @param string $clusters
157 | * @return model\Instance
158 | * @throws ReflectionException
159 | * @throws exception\RequestUriRequiredException
160 | * @throws exception\RequestVerbRequiredException
161 | * @throws exception\ResponseCodeErrorException
162 | */
163 | public function get($healthyOnly = false, $weight = "", $namespaceId = "", $clusters = "")
164 | {
165 | return NamingClient::get(
166 | NamingConfig::getServiceName(),
167 | NamingConfig::getIp(),
168 | NamingConfig::getPort(),
169 | $healthyOnly,
170 | $weight,
171 | $namespaceId,
172 | $clusters
173 | );
174 | }
175 |
176 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/NamingClient.php:
--------------------------------------------------------------------------------
1 | setServiceName($serviceName);
52 | $registerInstanceDiscovery->setIp($ip);
53 | $registerInstanceDiscovery->setPort($port);
54 | $registerInstanceDiscovery->setNamespaceId($namespaceId);
55 | $registerInstanceDiscovery->setWeight($weight);
56 | $registerInstanceDiscovery->setEnable($enable);
57 | $registerInstanceDiscovery->setHealthy($healthy);
58 | $registerInstanceDiscovery->setMetadata($metadata);
59 | $registerInstanceDiscovery->setClusterName($clusterName);
60 |
61 | $response = $registerInstanceDiscovery->doRequest();
62 | return $response->getBody()->getContents() == "ok";
63 | }
64 |
65 | /**
66 | * @param $serviceName
67 | * @param $ip
68 | * @param $port
69 | * @param string $namespaceId
70 | * @param string $clusterName
71 | * @return bool
72 | * @throws ReflectionException
73 | * @throws RequestUriRequiredException
74 | * @throws RequestVerbRequiredException
75 | * @throws ResponseCodeErrorException
76 | */
77 | public static function delete($serviceName, $ip, $port, $namespaceId = "", $clusterName = "")
78 | {
79 | $deleteInstanceDiscovery = new DeleteInstanceNaming();
80 | $deleteInstanceDiscovery->setServiceName($serviceName);
81 | $deleteInstanceDiscovery->setIp($ip);
82 | $deleteInstanceDiscovery->setPort($port);
83 | $deleteInstanceDiscovery->setNamespaceId($namespaceId);
84 | $deleteInstanceDiscovery->setClusterName($clusterName);
85 |
86 | $response = $deleteInstanceDiscovery->doRequest();
87 | return $response->getBody()->getContents() == "ok";
88 | }
89 |
90 | /**
91 | * @param $serviceName
92 | * @param $ip
93 | * @param $port
94 | * @param string $weight
95 | * @param string $namespaceId
96 | * @param string $clusterName
97 | * @param string $metadata
98 | * @return bool
99 | * @throws ReflectionException
100 | * @throws RequestUriRequiredException
101 | * @throws RequestVerbRequiredException
102 | * @throws ResponseCodeErrorException
103 | */
104 | public static function update($serviceName, $ip, $port, $weight = "", $namespaceId = "", $clusterName = "", $metadata = "{}")
105 | {
106 | $updateInstanceDiscovery = new UpdateInstanceNaming();
107 | $updateInstanceDiscovery->setServiceName($serviceName);
108 | $updateInstanceDiscovery->setIp($ip);
109 | $updateInstanceDiscovery->setPort($port);
110 | $updateInstanceDiscovery->setNamespaceId($namespaceId);
111 | $updateInstanceDiscovery->setWeight($weight);
112 | $updateInstanceDiscovery->setMetadata($metadata);
113 | $updateInstanceDiscovery->setClusterName($clusterName);
114 |
115 | $response = $updateInstanceDiscovery->doRequest();
116 | $content = $response->getBody()->getContents();
117 | return $content == "ok";
118 | }
119 |
120 | /**
121 | * @param $serviceName
122 | * @param bool $healthyOnly
123 | * @param string $namespaceId
124 | * @param string $clusters
125 | * @return model\InstanceList
126 | * @throws ReflectionException
127 | * @throws RequestUriRequiredException
128 | * @throws RequestVerbRequiredException
129 | * @throws ResponseCodeErrorException
130 | */
131 | public static function listInstances($serviceName, $healthyOnly = false, $namespaceId = "", $clusters = "")
132 | {
133 | try {
134 | $listInstanceDiscovery = new ListInstanceNaming();
135 | $listInstanceDiscovery->setServiceName($serviceName);
136 | $listInstanceDiscovery->setNamespaceId($namespaceId);
137 | $listInstanceDiscovery->setClusters($clusters);
138 | $listInstanceDiscovery->setHealthyOnly($healthyOnly);
139 |
140 | $response = $listInstanceDiscovery->doRequest();
141 | $content = $response->getBody()->getContents();
142 |
143 | $instanceList = InstanceList::decode($content);
144 | LocalDiscoveryListInfoProcessor::saveSnapshot($serviceName, $namespaceId, $clusters, $instanceList);
145 | } catch (Exception $e) {
146 | LogUtil::error("查询实例列表异常,开始从本地获取配置, message: " . $e->getMessage());
147 | $instanceList = LocalDiscoveryListInfoProcessor::getFailover($serviceName, $namespaceId, $clusters);
148 | $instanceList = $instanceList ? $instanceList
149 | : LocalDiscoveryListInfoProcessor::getSnapshot($serviceName, $namespaceId, $clusters);
150 | }
151 | return $instanceList;
152 | }
153 |
154 | /**
155 | * @param $serviceName
156 | * @param $ip
157 | * @param $port
158 | * @param bool $healthyOnly
159 | * @param string $weight
160 | * @param string $namespaceId
161 | * @param string $cluster
162 | * @return model\Instance
163 | * @throws ReflectionException
164 | * @throws RequestUriRequiredException
165 | * @throws RequestVerbRequiredException
166 | * @throws ResponseCodeErrorException
167 | */
168 | public static function get($serviceName, $ip, $port, $healthyOnly = false, $weight = "", $namespaceId = "", $cluster = "")
169 | {
170 | try {
171 | $getInstanceDiscovery = new GetInstanceNaming();
172 | $getInstanceDiscovery->setServiceName($serviceName);
173 | $getInstanceDiscovery->setIp($ip);
174 | $getInstanceDiscovery->setPort($port);
175 | $getInstanceDiscovery->setNamespaceId($namespaceId);
176 | $getInstanceDiscovery->setCluster($cluster);
177 | $getInstanceDiscovery->setHealthyOnly($healthyOnly);
178 |
179 | $response = $getInstanceDiscovery->doRequest();
180 | $content = $response->getBody()->getContents();
181 | $instance = Instance::decode($content);
182 | LocalDiscoveryInfoProcessor::saveSnapshot($serviceName, $ip, $port, $cluster, $instance);
183 | } catch (Exception $e) {
184 | LogUtil::error("查询实例详情异常,开始从本地获取配置, message: " . $e->getMessage());
185 | $instance = LocalDiscoveryInfoProcessor::getFailover($serviceName, $ip, $port, $cluster);
186 | $instance = $instance ? $instance
187 | : LocalDiscoveryInfoProcessor::getSnapshot($serviceName, $ip, $port, $cluster);
188 | }
189 |
190 | return $instance;
191 | }
192 |
193 | /**
194 | * @param $serviceName
195 | * @param $beat
196 | * @return model\Beat
197 | * @throws ReflectionException
198 | * @throws RequestUriRequiredException
199 | * @throws RequestVerbRequiredException
200 | * @throws ResponseCodeErrorException
201 | */
202 | public static function beat($serviceName, $beat)
203 | {
204 | $beatInstanceDiscovery = new BeatInstanceNaming();
205 | $beatInstanceDiscovery->setServiceName($serviceName);
206 | $beatInstanceDiscovery->setBeat($beat);
207 |
208 | $response = $beatInstanceDiscovery->doRequest();
209 | $content = $response->getBody()->getContents();
210 | return Beat::decode($content);
211 | }
212 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/NamingConfig.php:
--------------------------------------------------------------------------------
1 | "客户端请求中的语法错误",
23 | 403 => "没有权限",
24 | 404 => "无法找到资源",
25 | 500 => "服务器内部错误",
26 | ];
27 | }
28 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/exception/RequestUriRequiredException.php:
--------------------------------------------------------------------------------
1 | getPath())) {
70 | mkdir($file->getPath(), 0777, true);
71 | }
72 | file_put_contents($snapshotFile, $config);
73 | }
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/failover/LocalDiscoveryInfoProcessor.php:
--------------------------------------------------------------------------------
1 | getPath())) {
70 | mkdir($file->getPath(), 0777, true);
71 | }
72 | file_put_contents($snapshotFile, $instance->encode());
73 | }
74 | }
75 |
76 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/failover/LocalDiscoveryListInfoProcessor.php:
--------------------------------------------------------------------------------
1 | getPath())) {
69 | mkdir($file->getPath(), 0777, true);
70 | }
71 | file_put_contents($snapshotFile, $instanceList->encode());
72 | }
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/failover/Processor.php:
--------------------------------------------------------------------------------
1 | $obs) {
22 | if ($obs == $observer) {
23 | unset(static::$observers[$key]);
24 | return true;
25 | }
26 | }
27 | return false;
28 | }
29 |
30 | // 通知观察者
31 | public static function notify()
32 | {
33 | foreach (static::$observers as $observer) {
34 | call_user_func_array($observer, func_get_args());
35 | }
36 | }
37 |
38 | /**
39 | * @return array
40 | */
41 | public static function getObservers()
42 | {
43 | return static::$observers;
44 | }
45 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/listener/config/Config.php:
--------------------------------------------------------------------------------
1 | setEnv($env);
40 | $config->setTenant($tenant);
41 | $config->setDataId($dataId);
42 | $config->setGroup($group);
43 | $config->setConfig($configString);
44 | return $config;
45 | }
46 |
47 | /**
48 | * @return mixed
49 | */
50 | public function getConfig()
51 | {
52 | return $this->config;
53 | }
54 |
55 | /**
56 | * @param mixed $config
57 | */
58 | public function setConfig($config)
59 | {
60 | $this->config = $config;
61 | }
62 |
63 | /**
64 | * @return mixed
65 | */
66 | public function getTenant()
67 | {
68 | return $this->tenant;
69 | }
70 |
71 | /**
72 | * @param mixed $tenant
73 | */
74 | public function setTenant($tenant)
75 | {
76 | $this->tenant = $tenant;
77 | }
78 |
79 | /**
80 | * @return mixed
81 | */
82 | public function getDataId()
83 | {
84 | return $this->dataId;
85 | }
86 |
87 | /**
88 | * @param mixed $dataId
89 | */
90 | public function setDataId($dataId)
91 | {
92 | $this->dataId = $dataId;
93 | }
94 |
95 | /**
96 | * @return mixed
97 | */
98 | public function getGroup()
99 | {
100 | return $this->group;
101 | }
102 |
103 | /**
104 | * @param mixed $group
105 | */
106 | public function setGroup($group)
107 | {
108 | $this->group = $group;
109 | }
110 |
111 | /**
112 | * @return mixed
113 | */
114 | public function getEnv()
115 | {
116 | return $this->env;
117 | }
118 |
119 | /**
120 | * @param mixed $env
121 | */
122 | public function setEnv($env)
123 | {
124 | $this->env = $env;
125 | }
126 |
127 | /**
128 | * @return bool
129 | */
130 | public function isChanged()
131 | {
132 | return $this->changed;
133 | }
134 |
135 | /**
136 | * @param bool $changed
137 | */
138 | public function setChanged($changed)
139 | {
140 | $this->changed = $changed;
141 | }
142 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/listener/config/GetConfigRequestErrorListener.php:
--------------------------------------------------------------------------------
1 | clientBeatInterval;
17 | }
18 |
19 | /**
20 | * @param mixed $clientBeatInterval
21 | */
22 | public function setClientBeatInterval($clientBeatInterval)
23 | {
24 | $this->clientBeatInterval = $clientBeatInterval;
25 | } //int
26 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/model/Host.php:
--------------------------------------------------------------------------------
1 | valid;
26 | }
27 |
28 | /**
29 | * @param mixed $valid
30 | */
31 | public function setValid($valid)
32 | {
33 | $this->valid = $valid;
34 | }
35 |
36 | /**
37 | * @return mixed
38 | */
39 | public function getMarked()
40 | {
41 | return $this->marked;
42 | }
43 |
44 | /**
45 | * @param mixed $marked
46 | */
47 | public function setMarked($marked)
48 | {
49 | $this->marked = $marked;
50 | }
51 |
52 | /**
53 | * @return mixed
54 | */
55 | public function getMetadata()
56 | {
57 | return $this->metadata;
58 | }
59 |
60 | /**
61 | * @param mixed $metadata
62 | */
63 | public function setMetadata($metadata)
64 | {
65 | $this->metadata = $metadata;
66 | }
67 |
68 | /**
69 | * @return mixed
70 | */
71 | public function getInstanceId()
72 | {
73 | return $this->instanceId;
74 | }
75 |
76 | /**
77 | * @param mixed $instanceId
78 | */
79 | public function setInstanceId($instanceId)
80 | {
81 | $this->instanceId = $instanceId;
82 | }
83 |
84 | /**
85 | * @return mixed
86 | */
87 | public function getPort()
88 | {
89 | return $this->port;
90 | }
91 |
92 | /**
93 | * @param mixed $port
94 | */
95 | public function setPort($port)
96 | {
97 | $this->port = $port;
98 | }
99 |
100 | /**
101 | * @return mixed
102 | */
103 | public function getIp()
104 | {
105 | return $this->ip;
106 | }
107 |
108 | /**
109 | * @param mixed $ip
110 | */
111 | public function setIp($ip)
112 | {
113 | $this->ip = $ip;
114 | }
115 |
116 | /**
117 | * @return mixed
118 | */
119 | public function getClusterName()
120 | {
121 | return $this->clusterName;
122 | }
123 |
124 | /**
125 | * @param mixed $clusterName
126 | */
127 | public function setClusterName($clusterName)
128 | {
129 | $this->clusterName = $clusterName;
130 | }
131 |
132 | /**
133 | * @return mixed
134 | */
135 | public function getWeight()
136 | {
137 | return $this->weight;
138 | }
139 |
140 | /**
141 | * @param mixed $weight
142 | */
143 | public function setWeight($weight)
144 | {
145 | $this->weight = $weight;
146 | }
147 |
148 | /**
149 | * @return mixed
150 | */
151 | public function getServiceName()
152 | {
153 | return $this->serviceName;
154 | }
155 |
156 | /**
157 | * @param mixed $serviceName
158 | */
159 | public function setServiceName($serviceName)
160 | {
161 | $this->serviceName = $serviceName;
162 | }
163 |
164 | /**
165 | * @return mixed
166 | */
167 | public function getEnabled()
168 | {
169 | return $this->enabled;
170 | }
171 |
172 | /**
173 | * @param mixed $enabled
174 | */
175 | public function setEnabled($enabled)
176 | {
177 | $this->enabled = $enabled;
178 | } //boolean
179 |
180 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/model/Instance.php:
--------------------------------------------------------------------------------
1 | metadata;
30 | }
31 |
32 | /**
33 | * @param mixed $metadata
34 | */
35 | public function setMetadata($metadata)
36 | {
37 | $this->metadata = $metadata;
38 | }
39 |
40 | /**
41 | * @return mixed
42 | */
43 | public function getInstanceId()
44 | {
45 | return $this->instanceId;
46 | }
47 |
48 | /**
49 | * @param mixed $instanceId
50 | */
51 | public function setInstanceId($instanceId)
52 | {
53 | $this->instanceId = $instanceId;
54 | }
55 |
56 | /**
57 | * @return mixed
58 | */
59 | public function getPort()
60 | {
61 | return $this->port;
62 | }
63 |
64 | /**
65 | * @param mixed $port
66 | */
67 | public function setPort($port)
68 | {
69 | $this->port = $port;
70 | }
71 |
72 | /**
73 | * @return mixed
74 | */
75 | public function getService()
76 | {
77 | return $this->service;
78 | }
79 |
80 | /**
81 | * @param mixed $service
82 | */
83 | public function setService($service)
84 | {
85 | $this->service = $service;
86 | }
87 |
88 | /**
89 | * @return mixed
90 | */
91 | public function getHealthy()
92 | {
93 | return $this->healthy;
94 | }
95 |
96 | /**
97 | * @param mixed $healthy
98 | */
99 | public function setHealthy($healthy)
100 | {
101 | $this->healthy = $healthy;
102 | }
103 |
104 | /**
105 | * @return mixed
106 | */
107 | public function getIp()
108 | {
109 | return $this->ip;
110 | }
111 |
112 | /**
113 | * @param mixed $ip
114 | */
115 | public function setIp($ip)
116 | {
117 | $this->ip = $ip;
118 | }
119 |
120 | /**
121 | * @return mixed
122 | */
123 | public function getClusterName()
124 | {
125 | return $this->clusterName;
126 | }
127 |
128 | /**
129 | * @param mixed $clusterName
130 | */
131 | public function setClusterName($clusterName)
132 | {
133 | $this->clusterName = $clusterName;
134 | }
135 |
136 | /**
137 | * @return mixed
138 | */
139 | public function getWeight()
140 | {
141 | return $this->weight;
142 | }
143 |
144 | /**
145 | * @param mixed $weight
146 | */
147 | public function setWeight($weight)
148 | {
149 | $this->weight = $weight;
150 | } //double
151 |
152 |
153 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/model/InstanceList.php:
--------------------------------------------------------------------------------
1 | metadata;
28 | }
29 |
30 | /**
31 | * @param mixed $metadata
32 | */
33 | public function setMetadata($metadata)
34 | {
35 | $this->metadata = $metadata;
36 | }
37 |
38 | /**
39 | * @return mixed
40 | */
41 | public function getDom()
42 | {
43 | return $this->dom;
44 | }
45 |
46 | /**
47 | * @param mixed $dom
48 | */
49 | public function setDom($dom)
50 | {
51 | $this->dom = $dom;
52 | }
53 |
54 | /**
55 | * @return mixed
56 | */
57 | public function getCacheMillis()
58 | {
59 | return $this->cacheMillis;
60 | }
61 |
62 | /**
63 | * @param mixed $cacheMillis
64 | */
65 | public function setCacheMillis($cacheMillis)
66 | {
67 | $this->cacheMillis = $cacheMillis;
68 | }
69 |
70 | /**
71 | * @return mixed
72 | */
73 | public function getUseSpecifiedURL()
74 | {
75 | return $this->useSpecifiedURL;
76 | }
77 |
78 | /**
79 | * @param mixed $useSpecifiedURL
80 | */
81 | public function setUseSpecifiedURL($useSpecifiedURL)
82 | {
83 | $this->useSpecifiedURL = $useSpecifiedURL;
84 | }
85 |
86 | /**
87 | * @return mixed
88 | */
89 | public function getHosts()
90 | {
91 | $hostsList = [];
92 | foreach ($this->hosts as $host) {
93 | $hostsList[] = MapperUtil::objectToObject($host, "alibaba\\nacos\\model\\Host");
94 | }
95 | return $hostsList;
96 | }
97 |
98 | /**
99 | * @param mixed $hosts
100 | */
101 | public function setHosts($hosts)
102 | {
103 | $this->hosts = $hosts;
104 | }
105 |
106 | /**
107 | * @return mixed
108 | */
109 | public function getChecksum()
110 | {
111 | return $this->checksum;
112 | }
113 |
114 | /**
115 | * @param mixed $checksum
116 | */
117 | public function setChecksum($checksum)
118 | {
119 | $this->checksum = $checksum;
120 | }
121 |
122 | /**
123 | * @return mixed
124 | */
125 | public function getLastRefTime()
126 | {
127 | return $this->lastRefTime;
128 | }
129 |
130 | /**
131 | * @param mixed $lastRefTime
132 | */
133 | public function setLastRefTime($lastRefTime)
134 | {
135 | $this->lastRefTime = $lastRefTime;
136 | }
137 |
138 | /**
139 | * @return mixed
140 | */
141 | public function getEnv()
142 | {
143 | return $this->env;
144 | }
145 |
146 | /**
147 | * @param mixed $env
148 | */
149 | public function setEnv($env)
150 | {
151 | $this->env = $env;
152 | }
153 |
154 | /**
155 | * @return mixed
156 | */
157 | public function getClusters()
158 | {
159 | return $this->clusters;
160 | }
161 |
162 | /**
163 | * @param mixed $clusters
164 | */
165 | public function setClusters($clusters)
166 | {
167 | $this->clusters = $clusters;
168 | } //String
169 |
170 | /**
171 | * @return mixed
172 | */
173 | public function getName()
174 | {
175 | return $this->name;
176 | }
177 |
178 | /**
179 | * @param mixed $name
180 | */
181 | public function setName($name)
182 | {
183 | $this->name = $name;
184 | }
185 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/model/Model.php:
--------------------------------------------------------------------------------
1 | $propertyValue) {
22 | if (property_exists($instance, $propertyName)) {
23 | $instance->{"set" . ucfirst($propertyName)}($propertyValue);
24 | }
25 | }
26 | return $instance;
27 | }
28 |
29 | /**
30 | * @return false|string
31 | */
32 | public function encode()
33 | {
34 | return json_encode(get_object_vars($this));
35 | }
36 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/Request.php:
--------------------------------------------------------------------------------
1 | getParameterAndHeader();
52 | $response = HttpUtil::request(
53 | $this->getVerb(),
54 | $this->getUri(),
55 | $parameterList,
56 | $headers,
57 | ['debug' => NacosConfig::getIsDebug()]
58 | );
59 |
60 | if (isset(ErrorCodeEnum::getErrorCodeMap()[$response->getStatusCode()])) {
61 | throw new ResponseCodeErrorException($response->getStatusCode(), ErrorCodeEnum::getErrorCodeMap()[$response->getStatusCode()]);
62 | }
63 | return $response;
64 | }
65 |
66 | /**
67 | * 获取请求参数和请求头
68 | * @return array
69 | * @throws ReflectionException
70 | */
71 | abstract protected function getParameterAndHeader();
72 |
73 | /**
74 | * @return mixed
75 | * @throws
76 | */
77 | public function getVerb()
78 | {
79 | if ($this->verb == null) {
80 | throw new RequestVerbRequiredException();
81 | }
82 | return $this->verb;
83 | }
84 |
85 | /**
86 | * @param mixed $verb
87 | */
88 | public function setVerb($verb)
89 | {
90 | $this->verb = $verb;
91 | }
92 |
93 | /**
94 | * @return mixed
95 | * @throws
96 | */
97 | public function getUri()
98 | {
99 | if ($this->uri == null) {
100 | throw new RequestUriRequiredException();
101 | }
102 | return $this->uri;
103 | }
104 |
105 | /**
106 | * @param mixed $uri
107 | */
108 | public function setUri($uri)
109 | {
110 | $this->uri = $uri;
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/config/ConfigRequest.php:
--------------------------------------------------------------------------------
1 | tenant;
41 | }
42 |
43 | /**
44 | * @param mixed $tenant
45 | */
46 | public function setTenant($tenant)
47 | {
48 | $this->tenant = $tenant;
49 | }
50 |
51 | /**
52 | * @return mixed
53 | */
54 | public function getDataId()
55 | {
56 | return $this->dataId;
57 | }
58 |
59 | /**
60 | * @param mixed $dataId
61 | */
62 | public function setDataId($dataId)
63 | {
64 | $this->dataId = $dataId;
65 | }
66 |
67 | /**
68 | * @return mixed
69 | */
70 | public function getGroup()
71 | {
72 | return $this->group;
73 | }
74 |
75 | /**
76 | * @param mixed $group
77 | */
78 | public function setGroup($group)
79 | {
80 | $this->group = $group;
81 | }
82 |
83 | protected function getParameterAndHeader()
84 | {
85 | $headers = [];
86 | $parameterList = [];
87 |
88 | $properties = ReflectionUtil::getProperties($this);
89 | foreach ($properties as $propertyName => $propertyValue) {
90 | if (in_array($propertyName, $this->standaloneParameterList)) {
91 | // 忽略这些参数
92 | } else if ($propertyName == "longPullingTimeout") {
93 | $headers["Long-Pulling-Timeout"] = $this->getLongPullingTimeout();
94 | } else if ($propertyName == "listeningConfigs") {
95 | $parameterList["Listening-Configs"] = $this->getListeningConfigs();
96 | } else {
97 | $parameterList[$propertyName] = $propertyValue;
98 | }
99 | }
100 |
101 | if (NacosConfig::getIsDebug()) {
102 | LogUtil::info(strtr("parameterList: {parameterList}, headers: {headers}", [
103 | "parameterList" => json_encode($parameterList),
104 | "headers" => json_encode($headers)
105 | ]));
106 | }
107 | return [$parameterList, $headers];
108 | }
109 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/config/DeleteConfigRequest.php:
--------------------------------------------------------------------------------
1 | longPullingTimeout) {
47 | return $this->longPullingTimeout;
48 | } else {
49 | return NacosConfig::getLongPullingTimeout();
50 | }
51 | }
52 |
53 | /**
54 | * @return mixed
55 | */
56 | public function getListeningConfigs()
57 | {
58 | $this->listeningConfigs = sprintf(
59 | self::LISTENING_CONFIGS_FORMAT,
60 | $this->getDataId(),
61 | EncodeUtil::twoEncode(),
62 | $this->getGroup(),
63 | EncodeUtil::twoEncode(),
64 | $this->getContentMD5(),
65 | EncodeUtil::twoEncode(),
66 | $this->getTenant(),
67 | EncodeUtil::oneEncode()
68 | );
69 | return $this->listeningConfigs;
70 | }
71 |
72 | /**
73 | * @return mixed
74 | */
75 | public function getContentMD5()
76 | {
77 | return $this->contentMD5;
78 | }
79 |
80 | /**
81 | * @param mixed $contentMD5
82 | */
83 | public function setContentMD5($contentMD5)
84 | {
85 | $this->contentMD5 = $contentMD5;
86 | }
87 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/config/PublishConfigRequest.php:
--------------------------------------------------------------------------------
1 | content;
28 | }
29 |
30 | /**
31 | * @param mixed $content
32 | */
33 | public function setContent($content)
34 | {
35 | $this->content = $content;
36 | }
37 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/BeatInstanceNaming.php:
--------------------------------------------------------------------------------
1 | serviceName;
30 | }
31 |
32 | /**
33 | * @param mixed $serviceName
34 | */
35 | public function setServiceName($serviceName)
36 | {
37 | $this->serviceName = $serviceName;
38 | }
39 |
40 | /**
41 | * @return mixed
42 | */
43 | public function getBeat()
44 | {
45 | return $this->beat;
46 | }
47 |
48 | /**
49 | * @param mixed $beat
50 | */
51 | public function setBeat($beat)
52 | {
53 | $this->beat = $beat;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/DeleteInstanceNaming.php:
--------------------------------------------------------------------------------
1 | serviceName;
51 | }
52 |
53 | /**
54 | * @param mixed $serviceName
55 | */
56 | public function setServiceName($serviceName)
57 | {
58 | $this->serviceName = $serviceName;
59 | }
60 |
61 | /**
62 | * @return mixed
63 | */
64 | public function getIp()
65 | {
66 | return $this->ip;
67 | }
68 |
69 | /**
70 | * @param mixed $ip
71 | */
72 | public function setIp($ip)
73 | {
74 | $this->ip = $ip;
75 | }
76 |
77 | /**
78 | * @return mixed
79 | */
80 | public function getPort()
81 | {
82 | return $this->port;
83 | }
84 |
85 | /**
86 | * @param mixed $port
87 | */
88 | public function setPort($port)
89 | {
90 | $this->port = $port;
91 | }
92 |
93 | /**
94 | * @return mixed
95 | */
96 | public function getClusterName()
97 | {
98 | return $this->clusterName;
99 | }
100 |
101 | /**
102 | * @param mixed $clusterName
103 | */
104 | public function setClusterName($clusterName)
105 | {
106 | $this->clusterName = $clusterName;
107 | }
108 |
109 | /**
110 | * @return mixed
111 | */
112 | public function getNamespaceId()
113 | {
114 | return $this->namespaceId;
115 | }
116 |
117 | /**
118 | * @param mixed $namespaceId
119 | */
120 | public function setNamespaceId($namespaceId)
121 | {
122 | $this->namespaceId = $namespaceId;
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/GetInstanceNaming.php:
--------------------------------------------------------------------------------
1 | serviceName;
57 | }
58 |
59 | /**
60 | * @param mixed $serviceName
61 | */
62 | public function setServiceName($serviceName)
63 | {
64 | $this->serviceName = $serviceName;
65 | }
66 |
67 | /**
68 | * @return mixed
69 | */
70 | public function getIp()
71 | {
72 | return $this->ip;
73 | }
74 |
75 | /**
76 | * @param mixed $ip
77 | */
78 | public function setIp($ip)
79 | {
80 | $this->ip = $ip;
81 | }
82 |
83 | /**
84 | * @return mixed
85 | */
86 | public function getPort()
87 | {
88 | return $this->port;
89 | }
90 |
91 | /**
92 | * @param mixed $port
93 | */
94 | public function setPort($port)
95 | {
96 | $this->port = $port;
97 | }
98 |
99 | /**
100 | * @return mixed
101 | */
102 | public function getNamespaceId()
103 | {
104 | return $this->namespaceId;
105 | }
106 |
107 | /**
108 | * @param mixed $namespaceId
109 | */
110 | public function setNamespaceId($namespaceId)
111 | {
112 | $this->namespaceId = $namespaceId;
113 | }
114 |
115 | /**
116 | * @return mixed
117 | */
118 | public function getCluster()
119 | {
120 | return $this->cluster;
121 | }
122 |
123 | /**
124 | * @param mixed $cluster
125 | */
126 | public function setCluster($cluster)
127 | {
128 | $this->cluster = $cluster;
129 | }
130 |
131 | /**
132 | * @return mixed
133 | */
134 | public function getHealthyOnly()
135 | {
136 | return $this->healthyOnly;
137 | }
138 |
139 | /**
140 | * @param mixed $healthyOnly
141 | */
142 | public function setHealthyOnly($healthyOnly)
143 | {
144 | $this->healthyOnly = $healthyOnly;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/ListInstanceNaming.php:
--------------------------------------------------------------------------------
1 | serviceName;
43 | }
44 |
45 | /**
46 | * @param mixed $serviceName
47 | */
48 | public function setServiceName($serviceName)
49 | {
50 | $this->serviceName = $serviceName;
51 | }
52 |
53 | /**
54 | * @return mixed
55 | */
56 | public function getNamespaceId()
57 | {
58 | return $this->namespaceId;
59 | }
60 |
61 | /**
62 | * @param mixed $namespaceId
63 | */
64 | public function setNamespaceId($namespaceId)
65 | {
66 | $this->namespaceId = $namespaceId;
67 | }
68 |
69 | /**
70 | * @return mixed
71 | */
72 | public function getClusters()
73 | {
74 | return $this->clusters;
75 | }
76 |
77 | /**
78 | * @param mixed $clusters
79 | */
80 | public function setClusters($clusters)
81 | {
82 | $this->clusters = $clusters;
83 | }
84 |
85 | /**
86 | * @return mixed
87 | */
88 | public function getHealthyOnly()
89 | {
90 | return $this->healthyOnly;
91 | }
92 |
93 | /**
94 | * @param mixed $healthyOnly
95 | */
96 | public function setHealthyOnly($healthyOnly)
97 | {
98 | $this->healthyOnly = $healthyOnly;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/NamingRequest.php:
--------------------------------------------------------------------------------
1 | $propertyValue) {
23 | if (in_array($propertyName, $this->standaloneParameterList)) {
24 | // 忽略这些参数
25 | } else {
26 | $parameterList[$propertyName] = $propertyValue;
27 | }
28 | }
29 |
30 | if ($this instanceof RegisterInstanceNaming || $this instanceof DeleteInstanceNaming ||
31 | $this instanceof UpdateInstanceNaming || $this instanceof ListInstanceNaming ||
32 | $this instanceof BeatInstanceNaming) {
33 | $parameterList["ephemeral"] = NamingConfig::getEphemeral();
34 | }
35 |
36 | if (NacosConfig::getIsDebug()) {
37 | LogUtil::info(strtr("parameterList: {parameterList}, headers: {headers}", [
38 | "parameterList" => json_encode($parameterList),
39 | "headers" => json_encode($headers)
40 | ]));
41 | }
42 | return [$parameterList, $headers];
43 | }
44 |
45 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/RegisterInstanceNaming.php:
--------------------------------------------------------------------------------
1 | ip;
79 | }
80 |
81 | /**
82 | * @param mixed $ip
83 | */
84 | public function setIp($ip)
85 | {
86 | $this->ip = $ip;
87 | }
88 |
89 | /**
90 | * @return mixed
91 | */
92 | public function getPort()
93 | {
94 | return $this->port;
95 | }
96 |
97 | /**
98 | * @param mixed $port
99 | */
100 | public function setPort($port)
101 | {
102 | $this->port = $port;
103 | }
104 |
105 | /**
106 | * @return mixed
107 | */
108 | public function getNamespaceId()
109 | {
110 | return $this->namespaceId;
111 | }
112 |
113 | /**
114 | * @param mixed $namespaceId
115 | */
116 | public function setNamespaceId($namespaceId)
117 | {
118 | $this->namespaceId = $namespaceId;
119 | }
120 |
121 | /**
122 | * @return mixed
123 | */
124 | public function getWeight()
125 | {
126 | return $this->weight;
127 | }
128 |
129 | /**
130 | * @param mixed $weight
131 | */
132 | public function setWeight($weight)
133 | {
134 | $this->weight = $weight;
135 | }
136 |
137 | /**
138 | * @return mixed
139 | */
140 | public function getEnable()
141 | {
142 | return $this->enable;
143 | }
144 |
145 | /**
146 | * @param mixed $enable
147 | */
148 | public function setEnable($enable)
149 | {
150 | $this->enable = $enable;
151 | }
152 |
153 | /**
154 | * @return mixed
155 | */
156 | public function getHealthy()
157 | {
158 | return $this->healthy;
159 | }
160 |
161 | /**
162 | * @param mixed $healthy
163 | */
164 | public function setHealthy($healthy)
165 | {
166 | $this->healthy = $healthy;
167 | }
168 |
169 | /**
170 | * @return mixed
171 | */
172 | public function getMetadata()
173 | {
174 | return $this->metadata;
175 | }
176 |
177 | /**
178 | * @param mixed $metadata
179 | */
180 | public function setMetadata($metadata)
181 | {
182 | $this->metadata = $metadata;
183 | }
184 |
185 | /**
186 | * @return mixed
187 | */
188 | public function getClusterName()
189 | {
190 | return $this->clusterName;
191 | }
192 |
193 | /**
194 | * @param mixed $clusterName
195 | */
196 | public function setClusterName($clusterName)
197 | {
198 | $this->clusterName = $clusterName;
199 | }
200 |
201 | /**
202 | * @return mixed
203 | */
204 | public function getServiceName()
205 | {
206 | return $this->serviceName;
207 | }
208 |
209 | /**
210 | * @param mixed $serviceName
211 | */
212 | public function setServiceName($serviceName)
213 | {
214 | $this->serviceName = $serviceName;
215 | }
216 | }
217 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/request/naming/UpdateInstanceNaming.php:
--------------------------------------------------------------------------------
1 | serviceName;
65 | }
66 |
67 | /**
68 | * @param mixed $serviceName
69 | */
70 | public function setServiceName($serviceName)
71 | {
72 | $this->serviceName = $serviceName;
73 | }
74 |
75 | /**
76 | * @return mixed
77 | */
78 | public function getIp()
79 | {
80 | return $this->ip;
81 | }
82 |
83 | /**
84 | * @param mixed $ip
85 | */
86 | public function setIp($ip)
87 | {
88 | $this->ip = $ip;
89 | }
90 |
91 | /**
92 | * @return mixed
93 | */
94 | public function getPort()
95 | {
96 | return $this->port;
97 | }
98 |
99 | /**
100 | * @param mixed $port
101 | */
102 | public function setPort($port)
103 | {
104 | $this->port = $port;
105 | }
106 |
107 | /**
108 | * @return mixed
109 | */
110 | public function getClusterName()
111 | {
112 | return $this->clusterName;
113 | }
114 |
115 | /**
116 | * @param mixed $clusterName
117 | */
118 | public function setClusterName($clusterName)
119 | {
120 | $this->clusterName = $clusterName;
121 | }
122 |
123 | /**
124 | * @return mixed
125 | */
126 | public function getNamespaceId()
127 | {
128 | return $this->namespaceId;
129 | }
130 |
131 | /**
132 | * @param mixed $namespaceId
133 | */
134 | public function setNamespaceId($namespaceId)
135 | {
136 | $this->namespaceId = $namespaceId;
137 | }
138 |
139 | /**
140 | * @return mixed
141 | */
142 | public function getWeight()
143 | {
144 | return $this->weight;
145 | }
146 |
147 | /**
148 | * @param mixed $weight
149 | */
150 | public function setWeight($weight)
151 | {
152 | $this->weight = $weight;
153 | }
154 |
155 | /**
156 | * @return mixed
157 | */
158 | public function getMetadata()
159 | {
160 | return $this->metadata;
161 | }
162 |
163 | /**
164 | * @param mixed $metadata
165 | */
166 | public function setMetadata($metadata)
167 | {
168 | $this->metadata = $metadata;
169 | }
170 |
171 | }
172 |
--------------------------------------------------------------------------------
/src/alibaba/nacos/util/DiscoveryUtil.php:
--------------------------------------------------------------------------------
1 | $headers,
22 | ];
23 | if ($verb == "GET") {
24 | $parameterList['query'] = $body;
25 | } else {
26 | $parameterList['form_params'] = $body;
27 | }
28 | $response = $httpClient->request($verb, $uri, array_merge($parameterList, $options));
29 | return $response;
30 | }
31 |
32 | /**
33 | * @param $host
34 | * @param $timeout
35 | * @return Client
36 | */
37 | public static function getGuzzle()
38 | {
39 | static $guzzle;
40 | if ($guzzle == null) {
41 | $guzzle = new Client([
42 | 'base_uri' => NacosConfig::getHost(),
43 | ]);
44 | }
45 | return $guzzle;
46 | }
47 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/util/LogUtil.php:
--------------------------------------------------------------------------------
1 | info($message, $parameters);
25 | }
26 |
27 | public static function getLog()
28 | {
29 | static $log;
30 | if ($log == null) {
31 | // create a log channel
32 | try {
33 | $log = new Logger(NacosConfig::getName());
34 | $log->pushHandler(new StreamHandler(NacosConfig::getLogPath(), NacosConfig::getLogLevel()));
35 | } catch (Exception $e) {
36 | echo "初始化日志系统失败";
37 | exit(255);
38 | }
39 | }
40 | return $log;
41 | }
42 |
43 | /**
44 | * @param $message
45 | * @param $parameters
46 | */
47 | public static function error($message, $parameters = [])
48 | {
49 | self::getLog()->error($message, $parameters);
50 | }
51 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/util/MapperUtil.php:
--------------------------------------------------------------------------------
1 | getProperties();
26 | foreach ($sourceProperties as $sourceProperty) {
27 | $sourceProperty->setAccessible(true);
28 | $name = $sourceProperty->getName();
29 | $value = $sourceProperty->getValue($instance);
30 | if ($destinationReflection->hasProperty($name)) {
31 | $propDest = $destinationReflection->getProperty($name);
32 | $propDest->setAccessible(true);
33 | $propDest->setValue($className, $value);
34 | } else {
35 | $className->$name = $value;
36 | }
37 | }
38 | return $className;
39 | }
40 | }
--------------------------------------------------------------------------------
/src/alibaba/nacos/util/ReflectionUtil.php:
--------------------------------------------------------------------------------
1 | getProperties() as $property) {
28 | $property->setAccessible(true);
29 | $properties[$property->getName()] = $property->getValue($object);
30 | }
31 | } while ($reflect = $reflect->getParentClass());
32 | return $properties;
33 | }
34 | }
--------------------------------------------------------------------------------
/tests/DummyNacosTest.php:
--------------------------------------------------------------------------------
1 | runOnce();
26 | $this->assertEmpty($config);
27 | }
28 |
29 | public function testListener()
30 | {
31 | Nacos::init(
32 | "http://127.0.0.1:8848/",
33 | "dummy_dev",
34 | "DUMMY",
35 | "DUMMY_GROUP",
36 | ""
37 | )->listener();
38 | }
39 |
40 | /**
41 | * This method is called before each test.
42 | */
43 | protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */
44 | {
45 | putenv("NACOS_ENV=local");
46 |
47 | NacosConfig::setIsDebug(true);
48 | // 长轮询10秒一次
49 | NacosConfig::setLongPullingTimeout(10000);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/tests/Ipv6NamingTest.php:
--------------------------------------------------------------------------------
1 | assertTrue($this->discovery->register());
38 | }
39 |
40 | /**
41 | * @throws ReflectionException
42 | * @throws RequestUriRequiredException
43 | * @throws RequestVerbRequiredException
44 | * @throws ResponseCodeErrorException
45 | */
46 | public function testDelete()
47 | {
48 | $this->assertTrue($this->discovery->delete());
49 | }
50 |
51 | /**
52 | * @throws ReflectionException
53 | * @throws RequestUriRequiredException
54 | * @throws RequestVerbRequiredException
55 | * @throws ResponseCodeErrorException
56 | */
57 | public function testUpdate()
58 | {
59 | while (true) {
60 | $this->assertTrue($this->discovery->update(0.8));
61 | echo "tiemstamp " . time();
62 | sleep(5);
63 | }
64 | }
65 |
66 | /**
67 | * @throws ReflectionException
68 | * @throws RequestUriRequiredException
69 | * @throws RequestVerbRequiredException
70 | * @throws ResponseCodeErrorException
71 | */
72 | public function testListInstances()
73 | {
74 | $instanceList = $this->discovery->listInstances();
75 | $this->assertInstanceOf(InstanceList::class, $instanceList);
76 | }
77 |
78 | /**
79 | * @throws ReflectionException
80 | * @throws RequestUriRequiredException
81 | * @throws RequestVerbRequiredException
82 | * @throws ResponseCodeErrorException
83 | */
84 | public function testGet()
85 | {
86 | $this->assertInstanceOf(Instance::class, $this->discovery->get());
87 | }
88 |
89 | /**
90 | * @throws ReflectionException
91 | * @throws RequestUriRequiredException
92 | * @throws RequestVerbRequiredException
93 | * @throws ResponseCodeErrorException
94 | */
95 | public function testBeat()
96 | {
97 | while (true) {
98 | $beat = $this->discovery->beat($this->discovery->get());
99 | $this->assertInstanceOf(Beat::class, $beat);
100 | echo "tiemstamp " . time();
101 | sleep(5);
102 | }
103 | }
104 |
105 | /**
106 | * This method is called before each test.
107 | */
108 | protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */
109 | {
110 | NacosConfig::setHost("http://127.0.0.1:8848/");
111 | NacosConfig::setIsDebug(true);
112 | // 长轮询10秒一次
113 | NacosConfig::setLongPullingTimeout(10000);
114 | $this->discovery = Naming::init(
115 | "nacos.test.1",
116 | // "2404:6800:8005::2e",
117 | "::1",
118 | "8848",
119 | "",
120 | "",
121 | false
122 | );
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/tests/NacosTest.php:
--------------------------------------------------------------------------------
1 | runOnce();
27 | $this->assertFileExists(
28 | LocalConfigInfoProcessor::getSnapshotFile(
29 | "dev",
30 | "LARAVEL",
31 | "DEFAULT_GROUP",
32 | ""
33 | )
34 | );
35 | }
36 |
37 | public function testListener()
38 | {
39 | Nacos::init(
40 | "http://127.0.0.1:8848/",
41 | "dev",
42 | "LARAVEL",
43 | "DEFAULT_GROUP",
44 | ""
45 | )->listener();
46 | }
47 |
48 | /**
49 | * This method is called before each test.
50 | */
51 | protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */
52 | {
53 | NacosConfig::setIsDebug(true);
54 | // 长轮询10秒一次
55 | NacosConfig::setLongPullingTimeout(10000);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/NamingTest.php:
--------------------------------------------------------------------------------
1 | assertTrue($this->discovery->register());
38 | }
39 |
40 | /**
41 | * @throws ReflectionException
42 | * @throws RequestUriRequiredException
43 | * @throws RequestVerbRequiredException
44 | * @throws ResponseCodeErrorException
45 | */
46 | public function testDelete()
47 | {
48 | $this->assertTrue($this->discovery->delete());
49 | }
50 |
51 | /**
52 | * @throws ReflectionException
53 | * @throws RequestUriRequiredException
54 | * @throws RequestVerbRequiredException
55 | * @throws ResponseCodeErrorException
56 | */
57 | public function testUpdate()
58 | {
59 | $this->assertTrue($this->discovery->update(0.8));
60 | }
61 |
62 | /**
63 | * @throws ReflectionException
64 | * @throws RequestUriRequiredException
65 | * @throws RequestVerbRequiredException
66 | * @throws ResponseCodeErrorException
67 | */
68 | public function testListInstances()
69 | {
70 | $instanceList = $this->discovery->listInstances();
71 | $this->assertInstanceOf(InstanceList::class, $instanceList);
72 | }
73 |
74 | /**
75 | * @throws ReflectionException
76 | * @throws RequestUriRequiredException
77 | * @throws RequestVerbRequiredException
78 | * @throws ResponseCodeErrorException
79 | */
80 | public function testGet()
81 | {
82 | $this->assertInstanceOf(Instance::class, $this->discovery->get());
83 | }
84 |
85 | /**
86 | * @throws ReflectionException
87 | * @throws RequestUriRequiredException
88 | * @throws RequestVerbRequiredException
89 | * @throws ResponseCodeErrorException
90 | */
91 | public function testBeat()
92 | {
93 | $beat = $this->discovery->beat($this->discovery->get());
94 | $this->assertInstanceOf(Beat::class, $beat);
95 | }
96 |
97 | /**
98 | * This method is called before each test.
99 | */
100 | protected function setUp()/* The :void return type declaration that should be here would cause a BC issue */
101 | {
102 | NacosConfig::setHost("http://127.0.0.1:8848/");
103 | NacosConfig::setIsDebug(true);
104 | // 长轮询10秒一次
105 | NacosConfig::setLongPullingTimeout(10000);
106 | $this->discovery = Naming::init(
107 | "nacos.test.1",
108 | "11.11.11.11",
109 | "8848"
110 | );
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | getConfig()) {
26 | echo "获取配置异常, 配置为空,下面进行自定义逻辑处理" . PHP_EOL;
27 | // 设置是否修改配置文件内容,如果修改成true,这里设置的配置文件内容将是最终获取到的配置文件
28 | $config->setChanged(true);
29 | $config->setConfig("hello");
30 | }
31 | });
32 | $config = Nacos::init(
33 | "http://127.0.0.1:8848/",
34 | "dev",
35 | "LARAVEL",
36 | "DEFAULT_GROUP",
37 | ""
38 | )->runOnce();
39 |
40 | $this->assertNotEmpty($config);
41 | $this->assertEquals($config, "hello");
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/request/config/DeleteConfigRequestTest.php:
--------------------------------------------------------------------------------
1 | setDataId("LARAVEL1");
29 | $deleteConfigRequest->setGroup("DEFAULT_GROUP");
30 |
31 | $response = $deleteConfigRequest->doRequest();
32 | $this->assertNotEmpty($response);
33 | $this->assertNotEmpty($response->getBody());
34 | $content = $response->getBody()->getContents();
35 | echo "content: " . $content;
36 | $this->assertNotEmpty($content);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/request/config/GetConfigRequestTest.php:
--------------------------------------------------------------------------------
1 | setDataId("LARAVEL");
29 | $getConfigRequest->setGroup("DEFAULT_GROUP");
30 |
31 | $response = $getConfigRequest->doRequest();
32 | $this->assertNotEmpty($response);
33 | $this->assertNotEmpty($response->getBody());
34 | $content = $response->getBody()->getContents();
35 | echo "md5: " . md5($content);
36 | $this->assertEquals(md5($content), "d10d54edbdf4c99f6bbab4ef69292046");
37 | file_put_contents("env-example", $content);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/request/config/ListenerConfigRequestTest.php:
--------------------------------------------------------------------------------
1 | setDataId("LARAVEL");
29 | $listenerConfigRequest->setGroup("DEFAULT_GROUP");
30 | $listenerConfigRequest->setContentMD5("ddf41f9b16c588e0f6a185f4c82bf61d");
31 |
32 | $response = $listenerConfigRequest->doRequest();
33 | $this->assertNotEmpty($response);
34 | $this->assertNotEmpty($response->getBody());
35 | $content = $response->getBody()->getContents();
36 | echo "content: " . $content;
37 | $this->assertNotEmpty($content);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/request/config/PublishConfigRequestTest.php:
--------------------------------------------------------------------------------
1 | setDataId("LARAVEL");
29 | $publishConfigRequest->setGroup("DEFAULT_GROUP");
30 | $publishConfigRequest->setContent(file_get_contents("env-example"));
31 |
32 | $response = $publishConfigRequest->doRequest();
33 | $this->assertNotEmpty($response);
34 | $this->assertNotEmpty($response->getBody());
35 | $content = $response->getBody()->getContents();
36 | echo "content: " . $content;
37 | $this->assertNotEmpty($content);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/request/config/env-example:
--------------------------------------------------------------------------------
1 | APP_NAME=Laravel
2 | APP_ENV=dev
3 | APP_KEY=
4 | APP_DEBUG=true
5 | APP_URL=http://localhost
6 |
7 | LOG_CHANNEL=stack
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=127.0.0.1
11 | DB_PORT=3306
12 | DB_DATABASE=homestead
13 | DB_USERNAME=homestead
14 | DB_PASSWORD=secret
15 |
16 | BROADCAST_DRIVER=log
17 | CACHE_DRIVER=file
18 | QUEUE_CONNECTION=sync
19 | SESSION_DRIVER=file
20 | SESSION_LIFETIME=120
21 |
22 | REDIS_HOST=127.0.0.1
23 | REDIS_PASSWORD=null
24 | REDIS_PORT=6379
25 |
26 | MAIL_DRIVER=smtp
27 | MAIL_HOST=smtp.mailtrap.io
28 | MAIL_PORT=2525
29 | MAIL_USERNAME=null
30 | MAIL_PASSWORD=null
31 | MAIL_ENCRYPTION=null
32 |
33 | AWS_ACCESS_KEY_ID=
34 | AWS_SECRET_ACCESS_KEY=
35 | AWS_DEFAULT_REGION=us-east-1
36 | AWS_BUCKET=
37 |
38 | PUSHER_APP_ID=
39 | PUSHER_APP_KEY=
40 | PUSHER_APP_SECRET=
41 | PUSHER_APP_CLUSTER=mt1
42 |
43 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
44 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--------------------------------------------------------------------------------
/tests/request/naming/BeatInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setServiceName("nacos.test.1");
27 | $beatInstanceDiscovery->setBeat($this->beat);
28 |
29 | $response = $beatInstanceDiscovery->doRequest();
30 | $this->assertNotEmpty($response);
31 | $this->assertNotEmpty($response->getBody());
32 | $content = $response->getBody()->getContents();
33 | echo "content: " . $content;
34 | $this->assertNotEmpty($content);
35 | $this->assertTrue($content == '{"clientBeatInterval":5000}');
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/request/naming/DeleteInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setIp("11.11.11.12");
25 | $deleteInstanceDiscovery->setPort("8848");
26 | $deleteInstanceDiscovery->setNamespaceId("");
27 | $deleteInstanceDiscovery->setClusterName("");
28 | $deleteInstanceDiscovery->setServiceName("nacos.test.1");
29 |
30 | $response = $deleteInstanceDiscovery->doRequest();
31 | $this->assertNotEmpty($response);
32 | $this->assertNotEmpty($response->getBody());
33 | $content = $response->getBody()->getContents();
34 | echo "content: " . $content;
35 | $this->assertNotEmpty($content);
36 | $this->assertTrue($content == "ok");
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/request/naming/GetInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setServiceName("nacos.test.1");
26 | $getInstanceDiscovery->setIp("11.11.11.11");
27 | $getInstanceDiscovery->setPort("8848");
28 | $getInstanceDiscovery->setNamespaceId("");
29 | $getInstanceDiscovery->setCluster("");
30 | $getInstanceDiscovery->setHealthyOnly(false);
31 |
32 | $response = $getInstanceDiscovery->doRequest();
33 | $this->assertNotEmpty($response);
34 | $this->assertNotEmpty($response->getBody());
35 | $content = $response->getBody()->getContents();
36 | echo "content: " . $content;
37 | $this->assertNotEmpty($content);
38 |
39 | var_dump(Instance::decode($content));
40 | var_dump(Instance::decode($content)->encode());
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/request/naming/ListInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setServiceName("nacos.test.1");
26 | $listInstanceDiscovery->setNamespaceId("");
27 | $listInstanceDiscovery->setClusters("");
28 | $listInstanceDiscovery->setHealthyOnly(false);
29 |
30 | $response = $listInstanceDiscovery->doRequest();
31 | $this->assertNotEmpty($response);
32 | $this->assertNotEmpty($response->getBody());
33 | $content = $response->getBody()->getContents();
34 | echo "content: " . $content;
35 | $this->assertNotEmpty($content);
36 |
37 | var_dump(InstanceList::decode($content));
38 | var_dump(InstanceList::decode($content)->getHosts());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/request/naming/RegisterInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setIp("11.11.11.11");
25 | $registerInstanceDiscovery->setPort("8848");
26 | $registerInstanceDiscovery->setNamespaceId("");
27 | $registerInstanceDiscovery->setWeight(1.0);
28 | $registerInstanceDiscovery->setEnable(true);
29 | $registerInstanceDiscovery->setHealthy(true);
30 | $registerInstanceDiscovery->setMetadata('{"sn": 12345}');
31 | $registerInstanceDiscovery->setClusterName("");
32 | $registerInstanceDiscovery->setServiceName("nacos.test.1");
33 |
34 | $response = $registerInstanceDiscovery->doRequest();
35 | $this->assertNotEmpty($response);
36 | $this->assertNotEmpty($response->getBody());
37 | $content = $response->getBody()->getContents();
38 | echo "content: " . $content;
39 | $this->assertNotEmpty($content);
40 | $this->assertTrue($content == "ok");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/request/naming/UpdateInstanceNamingTest.php:
--------------------------------------------------------------------------------
1 | setIp("11.11.11.12");
25 | $updateInstanceDiscovery->setPort("8848");
26 | $updateInstanceDiscovery->setNamespaceId("");
27 | $updateInstanceDiscovery->setWeight(0.5);
28 | $updateInstanceDiscovery->setMetadata('{"sn": 123456}');
29 | $updateInstanceDiscovery->setClusterName("");
30 | $updateInstanceDiscovery->setServiceName("nacos.test.1");
31 |
32 | $response = $updateInstanceDiscovery->doRequest();
33 | $this->assertNotEmpty($response);
34 | $this->assertNotEmpty($response->getBody());
35 | $content = $response->getBody()->getContents();
36 | echo "content: " . $content;
37 | $this->assertNotEmpty($content);
38 | $this->assertTrue($content == "ok");
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/util/EncodeTest.php:
--------------------------------------------------------------------------------
1 | assertNotEmpty(EncodeUtil::oneEncode());
19 | }
20 |
21 | public function testTwoEncode()
22 | {
23 | $this->assertNotEmpty(EncodeUtil::twoEncode());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/util/HttpUtilTest.php:
--------------------------------------------------------------------------------
1 | "LARAVEL",
19 | "group" => "DEFAULT_GROUP"
20 | ];
21 | $response = HttpUtil::request("GET", "/nacos/v1/cs/configs", $parameterList);
22 | $this->assertNotEmpty($response);
23 | $this->assertNotEmpty($response->getBody());
24 | file_put_contents("env-example", $response->getBody()->getContents());
25 | }
26 |
27 | public function testPost()
28 | {
29 | $parameterList = [
30 | "Listening-Configs" => "LARAVEL^2DEFAULT_GROUP^2ddf41f9b16c588e0f6a185f4c82bf61d^1"
31 | ];
32 | $headers = [
33 | "Long-Pulling-Timeout" => "3000",
34 | "Content-Type" => "application/x-www-form-urlencoded"
35 | ];
36 | $response = HttpUtil::request("POST", "/nacos/v1/cs/configs/listener", $parameterList, $headers, ['debug' => true]);
37 | $this->assertNotEmpty($response);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/util/LogUtilTest.php:
--------------------------------------------------------------------------------
1 | assertEmpty(LogUtil::info("info message"));
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/util/env-example:
--------------------------------------------------------------------------------
1 | APP_NAME=Laravel
2 | APP_ENV=dev
3 | APP_KEY=
4 | APP_DEBUG=true
5 | APP_URL=http://localhost
6 |
7 | LOG_CHANNEL=stack
8 |
9 | DB_CONNECTION=mysql
10 | DB_HOST=127.0.0.1
11 | DB_PORT=3306
12 | DB_DATABASE=homestead
13 | DB_USERNAME=homestead
14 | DB_PASSWORD=secret
15 |
16 | BROADCAST_DRIVER=log
17 | CACHE_DRIVER=file
18 | QUEUE_CONNECTION=sync
19 | SESSION_DRIVER=file
20 | SESSION_LIFETIME=120
21 |
22 | REDIS_HOST=127.0.0.1
23 | REDIS_PASSWORD=null
24 | REDIS_PORT=6379
25 |
26 | MAIL_DRIVER=smtp
27 | MAIL_HOST=smtp.mailtrap.io
28 | MAIL_PORT=2525
29 | MAIL_USERNAME=null
30 | MAIL_PASSWORD=null
31 | MAIL_ENCRYPTION=null
32 |
33 | AWS_ACCESS_KEY_ID=
34 | AWS_SECRET_ACCESS_KEY=
35 | AWS_DEFAULT_REGION=us-east-1
36 | AWS_BUCKET=
37 |
38 | PUSHER_APP_ID=
39 | PUSHER_APP_KEY=
40 | PUSHER_APP_SECRET=
41 | PUSHER_APP_CLUSTER=mt1
42 |
43 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
44 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
--------------------------------------------------------------------------------