Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
Easy Http SDK
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Back End
Easy Http SDK
Commits
f54e5466
Commit
f54e5466
authored
Feb 20, 2023
by
谢宇轩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: 新增配置option生成工具
parent
d6f878ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
6 deletions
+119
-6
easysdk-option
bin/easysdk-option
+48
-0
composer.json
composer.json
+2
-1
SdkOptionBuilder.php
src/Generation/SdkOptionBuilder.php
+58
-0
Option.temp
template/Option.temp
+11
-5
No files found.
bin/easysdk-option
0 → 100755
View file @
f54e5466
#!/usr/bin/env php
<?php
include
$_composer_autoload_path
??
__DIR__
.
'/../vendor/autoload.php'
;
use
Jiwei\EasyHttpSdk\Generation\SdkOptionBuilder
;
$params
=
getopt
(
"p:d:h"
,
[
"dist:"
,
"package:"
,
"help"
]);
if
(
isset
(
$params
[
'h'
])
||
isset
(
$params
[
'help'
]))
{
echo
"SDK Option 生成工具🧸ver:0.1
\n
-d --dist
输出SDK Option 类的目录 默认为 ./src/
-p--package
SDK Option 类所使用的包名 "
.
PHP_EOL
;
exit
;
}
$packageName
=
$params
[
'p'
]
??
$params
[
'package'
]
??
""
;
$distPath
=
$params
[
'd'
]
??
$params
[
'dist'
]
??
__DIR__
.
"./src/"
;
if
(
""
===
$packageName
)
{
echo
"请输入的包名"
.
PHP_EOL
;
exit
;
}
if
(
substr
(
$distPath
,
-
1
)
!=
"/"
)
{
$distPath
.=
"/"
;
}
echo
"正在创建Jiwei
\\
{
$packageName
}
\\
Sdk
\\
Option配置文件"
.
PHP_EOL
;
echo
"目标目录
{
$distPath
}
"
.
PHP_EOL
;
$builder
=
new
SdkOptionBuilder
(
$distPath
,
__DIR__
.
'/../template/'
,
$packageName
);
$builder
->
build
();
echo
"成功生成Jiwei
\\
{
$packageName
}
\\
Sdk
\\
Option类"
.
PHP_EOL
;
composer.json
View file @
f54e5466
...
...
@@ -35,7 +35,8 @@
}
},
"bin"
:
[
"bin/easysdk"
"bin/easysdk"
,
"bin/easysdk-option"
],
"scripts"
:
{
"phpstan"
:
"vendor/bin/phpstan analyse -c phpstan.neon"
,
...
...
src/Generation/SdkOptionBuilder.php
0 → 100644
View file @
f54e5466
<?php
declare
(
strict_types
=
1
);
namespace
Jiwei\EasyHttpSdk\Generation
;
use
Twig\Environment
;
use
Twig\Error\LoaderError
;
use
Twig\Error\RuntimeError
;
use
Twig\Error\SyntaxError
;
use
Twig\Loader\FilesystemLoader
;
class
SdkOptionBuilder
{
/** @var string 目标Endpoint目录 */
private
$endpointDstPath
;
/** @var string twig模板目录 */
private
$twigPath
;
/** @var Environment twig生成器 */
protected
$twig
;
/** @var string 包命名空间 */
protected
$package
;
/**
* @param string $endpointDstPath
* @param string $twigPath
* @param string $package
*/
public
function
__construct
(
string
$endpointDstPath
,
string
$twigPath
,
string
$package
)
{
$this
->
endpointDstPath
=
$endpointDstPath
;
$this
->
twigPath
=
$twigPath
;
$this
->
package
=
$package
;
$loader
=
new
FilesystemLoader
(
$this
->
twigPath
);
$this
->
twig
=
new
Environment
(
$loader
);
}
/**
* 根据配置创建Endpoint类
*
* @return void
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public
function
build
()
:
void
{
$phpCode
=
$this
->
twig
->
render
(
'Option.temp'
,
[
"Name"
=>
$this
->
package
]);
file_put_contents
(
$this
->
endpointDstPath
.
$this
->
package
.
"Option.php"
,
$phpCode
);
}
}
src/XXXSDKOption.ph
p
→
template/Option.tem
p
View file @
f54e5466
{% autoescape false %}
<?php
declare
(
strict_types
=
1
);
namespace
Jiwei\
EasyHttpSdk
;
namespace
Jiwei
\
{{
Name
}}
\SDK
;
use
GuzzleHttp\Psr7\Request
;
use
Jiwei\EasyHttpSdk\Option
;
use
Jiwei\EasyHttpSdk\Policy\DefaultErrorHandlingPolicy
;
use
Jiwei\EasyHttpSdk\Policy\HandlingPolicyInterface
;
class
XXXSDK
Option
extends
Option
class
{{
Name
}}
Option
extends
Option
{
/** @var string API鉴权地址 */
private
const
AUTH_API_ROUTE
=
"/api/access/token"
;
/** @var int API鉴权过期时间 */
const
AUTH_CACHE_EXPIRES_AT
=
30000
;
/** @var array<string, string> API HOST */
const
ENDPONIT_HOSTS
=
[
'local'
=>
'
localhost:8080
'
,
'development'
=>
'
localhost:8080
'
,
'production'
=>
'
localhost:8080
'
'local'
=>
''
,
'development'
=>
''
,
'production'
=>
''
];
/**
...
...
@@ -38,6 +43,7 @@ class XXXSDKOption extends Option
/**
* 错误处理策略
*
* @return HandlingPolicyInterface
*/
public
function
errorHandlingPolicy
()
:
HandlingPolicyInterface
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment