File tree Expand file tree Collapse file tree 8 files changed +39
-17
lines changed
Expand file tree Collapse file tree 8 files changed +39
-17
lines changed Original file line number Diff line number Diff line change 11<?php
2+ namespace Seefan ;
23
3- require __DIR__ .'/Http.php ' ;
4- require __DIR__ .'/service/service.php ' ;
54class ConsulClient
65{
76 private $ http ;
@@ -27,9 +26,17 @@ public function __get($name)
2726 public function get ($ name )
2827 {
2928 if (empty ($ this ->service [$ name ])) {
30- require __DIR__ . ' /service/ ' . $ name . ' .php ' ;
31- $ this ->service [$ name ] = new $ name ($ this ->base_url , $ this ->http );
29+ $ class_name = " Seefan \\ Service \\ $ name" ;
30+ $ this ->service [$ name ] = new $ class_name ($ this ->base_url , $ this ->http );
3231 }
3332 return $ this ->service [$ name ];
3433 }
35- }
34+
35+ }
36+ spl_autoload_register (function ($ class ) {
37+ $ file = $ class . '.php ' ;
38+ if (is_file ($ file )) {
39+ require ($ file );
40+ }
41+ }
42+ );
Original file line number Diff line number Diff line change 11<?php
2-
2+ namespace Seefan ;
33class Http
44{
55 /**
Original file line number Diff line number Diff line change 11<?php
2-
3- class agent extends service
2+ namespace Seefan \ Service ;
3+ class Agent extends Service
44{
55 public function __construct ($ base_url , $ http )
66 {
Original file line number Diff line number Diff line change 11<?php
2-
3- class catalog extends service
2+ namespace Seefan \ Service ;
3+ class Catalog extends Service
44{
55 public function __construct ($ base_url , $ http )
66 {
Original file line number Diff line number Diff line change 11<?php
2-
3- class kv extends service
2+ namespace Seefan \ Service ;
3+ class KV extends Service
44{
55 public function __construct ($ base_url , $ http )
66 {
Original file line number Diff line number Diff line change 11<?php
2+ namespace Seefan \Service ;
3+ use Seefan \Http ;
24
3- class service
5+ class Service
46{
57 /**
68 * @var Http
Original file line number Diff line number Diff line change 55 * Date: 2017/4/1
66 * Time: 10:22
77 */
8- require 'ConsulClient.php ' ;
9- $ cc = new ConsulClient (['host ' => '10.20.28.51:8500 ' ]);
8+ require 'Seefan\ ConsulClient.php ' ;
9+ $ cc = new Seefan \ ConsulClient (['host ' => '10.20.28.51:8500 ' ]);
1010//var_dump( $cc->catalog->services());
1111//var_dump($cc->kv->get('service/0000'));
1212//var_dump($cc->agent->self());
2525} ' ;
2626//$param = json_decode($str, true);
2727//var_dump($cc->agent->service('register', $param));
28- //$cc->agent->service('deregister','redis1');
28+ //$rsp=$ cc->agent->service('deregister','redis1');
2929//$rsp=$cc->catalog->service('XE');
3030
3131$ json_str = '{
5959 "ServiceID": "redis1"
6060 }
6161 } ' ;
62+ //$json = json_decode($json_str, true);
63+ //$rsp = $cc->catalog->register($json);
64+
65+ $ json_str ='{
66+ "Datacenter": "dc1",
67+ "Node": "foobar"
68+ } ' ;
6269$ json = json_decode ($ json_str , true );
63- $ rsp = $ cc ->catalog ->register ($ json );
70+ $ rsp = $ cc ->catalog ->deregister ($ json );
6471var_dump ($ rsp );
You can’t perform that action at this time.
0 commit comments