Skip to content

Commit

Permalink
support tars protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaojun committed Nov 15, 2018
1 parent ddc532e commit ed8fdf1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -53,7 +53,7 @@ Laravel集成微服务治理框架Tars
初始化Laravel Tars

```
php artisan vendor:publish
php artisan vendor:publish --tag=tars.http
```
3. 如果需要自动注册到网关(目前仅支持Kong),修改配置文件src/config/tars.php

Expand Down
5 changes: 5 additions & 0 deletions scripts/tars2php.sh
@@ -0,0 +1,5 @@
#!/bin/bash

cd ../tars/

php ../src/vendor/phptars/tars2php/src/tars2php.php ./tars.proto.php
33 changes: 31 additions & 2 deletions src/ServiceProvider.php
Expand Up @@ -39,10 +39,39 @@ public function boot()
{
app()->configure('tars');

$tarsServantDir = base_path('app/Tars/servant');
$tarsServantImplDir = base_path('app/Tars/impl');
$tarsCservantDir = base_path('app/Tars/cservant');

if (!is_dir($tarsServantDir)) {
mkdir($tarsServantDir, 0777, true);
}
if (!is_dir($tarsServantImplDir)) {
mkdir($tarsServantDir, 0777, true);
}
if (!is_dir($tarsCservantDir)) {
mkdir($tarsServantDir, 0777, true);
}

$this->publishes([
__DIR__ . '/index.php' => base_path('index.php'),
__DIR__ . '/services.php' => base_path('services.php'),
__DIR__ . '/services.http.php' => base_path('services.php'),
__DIR__ . '/config/tars.php' => base_path('config/tars.php'),
]);
__DIR__ . '/../tars/tars.proto.http.php' => base_path('../tars/tars.proto.php'),
__DIR__ . '/../scripts/.gitkeep' => $tarsServantDir . '/.gitkeep',
__DIR__ . '/../scripts/.gitkeep' => $tarsServantImplDir . '/.gitkeep',
__DIR__ . '/../scripts/.gitkeep' => $tarsCservantDir . '/.gitkeep',
], 'tars.http');

$this->publishes([
__DIR__ . '/index.php' => base_path('index.php'),
__DIR__ . '/services.tars.php' => base_path('services.php'),
__DIR__ . '/config/tars.php' => base_path('config/tars.php'),
__DIR__ . '/../scripts/tars2php.sh' => base_path('../scripts/tars2php.sh'),
__DIR__ . '/../tars/tars.proto.tars.php' => base_path('../tars/tars.proto.php'),
__DIR__ . '/../scripts/.gitkeep' => $tarsServantDir . '/.gitkeep',
__DIR__ . '/../scripts/.gitkeep' => $tarsServantImplDir . '/.gitkeep',
__DIR__ . '/../scripts/.gitkeep' => $tarsCservantDir . '/.gitkeep',
], 'tars.tars');
}
}
File renamed without changes.
6 changes: 6 additions & 0 deletions src/services.tars.php
@@ -0,0 +1,6 @@
<?php
// 以namespace的方式,在psr4的框架下对代码进行加载
return array(
'home-api' => '\App\Tars\servant\{appName}\{serverName}\{objName}\{servantName}', //根据实际情况替换,遵循PSR-4即可,与tars.proto.php配置一致
'home-class' => '\App\Tars\impl\{servantImplName}', //根据实际情况替换,遵循PSR-4即可
);
6 changes: 6 additions & 0 deletions tars/tars.proto.http.php
@@ -0,0 +1,6 @@
<?php
return array(
'appName' => '{appName}', //根据实际情况替换
'serverName' => '{serverName}', //根据实际情况替换
'objName' => '{objName}', //根据实际情况替换
);
6 changes: 0 additions & 6 deletions tars/tars.proto.php

This file was deleted.

12 changes: 12 additions & 0 deletions tars/tars.proto.tars.php
@@ -0,0 +1,12 @@
<?php
return array(
'appName' => '{appName}', //根据实际情况替换
'serverName' => '{serverName}', //根据实际情况替换
'objName' => '{objName}', //根据实际情况替换
'withServant' => true, //决定是服务端,还是客户端的自动生成,true为服务端
'tarsFiles' => array(
//根据实际情况填写
),
'dstPath' => '../src/app/Tars/servant', //可替换,遵循PSR-4规则
'namespacePrefix' => 'App\Tars\servant', //可替换,遵循PSR-4规则
);

0 comments on commit ed8fdf1

Please sign in to comment.