Skip to content

Commit 5ed6ac0

Browse files
author
jay
committed
fixed:修复
1 parent 57a0a61 commit 5ed6ac0

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "phpzlc/document-bundle",
33
"description": "文档组件,用于编写接口文档,通过命令生成,在线的,可测试,可交付的技术文档。",
4-
"homepage": "https://phpzlc.com/",
4+
"homepage": "https://phpzlc.com/doc/document-bundle",
55
"license": "MIT",
66
"type": "library",
77
"keywords": [
@@ -22,7 +22,8 @@
2222
}
2323
},
2424
"require": {
25-
"symfony/framework-bundle": ">=4.4"
25+
"symfony/framework-bundle": ">=4.4",
26+
"zanysoft/laravel-zip": "^1.0"
2627
}
2728
}
2829

src/DocumentBundle/Command/GenerateDocumentCommand.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
* User: Jay
55
* Date: 2018/5/2
66
*/
7-
87
namespace PHPZlc\Document\DocumentBundle\Command;
98

10-
119
use App\Document\Config;
1210
use Doctrine\Common\Annotations\AnnotationReader;
1311
use Doctrine\DBAL\Connection;
14-
use MongoDB\Driver\Command;
1512
use PHPZlc\Document\Document;
1613
use Symfony\Component\Console\Input\InputInterface;
1714
use Symfony\Component\Console\Output\OutputInterface;
15+
use Symfony\Component\Filesystem\Filesystem;
1816
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcher;
17+
use ZanySoft\Zip\Zip;
1918

2019
class GenerateDocumentCommand extends Base
2120
{
@@ -24,10 +23,16 @@ class GenerateDocumentCommand extends Base
2423
*/
2524
private $connection;
2625

26+
/**
27+
* @var Filesystem;
28+
*/
29+
private $fileSystem;
30+
2731
public function __construct(Connection $connection = null)
2832
{
2933
parent::__construct();
3034
$this->connection = $connection;
35+
$this->fileSystem = new Filesystem();
3136
}
3237

3338
private $vars = array(
@@ -58,18 +63,18 @@ public function execute(InputInterface $input, OutputInterface $output)
5863
$this->globalConfig();
5964

6065
//TODO 接口数据
61-
foreach ($this->getDocumentClassArray($this->getRootPath() . '/src/Document') as $document) {
66+
foreach ($this->getDocumentClassArray($this->getRootPath() . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR .'Document') as $document) {
6267
$this->reader($document);
6368
}
64-
69+
6570
$this->actionsArrange();
6671

6772
//TODO 代码生成
6873

6974
//>1 目录资源重置
70-
exec('rm -rf ' . $this->rootApiDir());
71-
mkdir($this->rootApiDir());
72-
exec('cp -rf ' . __DIR__ . '/../Resources/Default/ApiDoc/* ' . $this->rootApiDir() . '/');
75+
$this->fileSystem->remove($this->rootApiDir());
76+
$this->fileSystem->mkdir($this->rootApiDir());
77+
$this->fileSystem->mirror(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'Default' . DIRECTORY_SEPARATOR . 'ApiDoc', $this->rootApiDir() . DIRECTORY_SEPARATOR);
7378

7479
//>2 生成静态页面
7580
$this->generateIndexFile();
@@ -80,7 +85,8 @@ public function execute(InputInterface $input, OutputInterface $output)
8085
$this->generateDebugFile();
8186

8287
//>3 生成打包件
83-
exec('cd ' . $this->rootApiDir() .'; zip -r ' . $this->rootApiDir() . '/' . $this->jsonToArray($this->global)['title'] . 'API文档.zip .');
88+
$zip = Zip::create($this->rootApiDir() . DIRECTORY_SEPARATOR . $this->jsonToArray($this->global)['title'] . 'API文档.zip');
89+
$zip->add($this->rootApiDir());
8490

8591
$this->io->success('生成成功');
8692

@@ -123,7 +129,7 @@ private function globalConfig()
123129

124130
private function rootApiDir()
125131
{
126-
return $this->getRootPath() . '/public/apidoc';
132+
return $this->getRootPath() . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'apidoc';
127133
}
128134

129135
/**
@@ -138,11 +144,11 @@ private function getDocumentClassArray($dir_name)
138144
$return_array = [];
139145
if(!empty($arr)) {
140146
foreach ($arr as $value) {
141-
if(is_file($dir_name . '/' . $value) && strpos($value, 'Document') !== false){
142-
$return_array[] = str_replace('/' ,'\\' , str_replace($this->getRootPath() . '/src/', '', 'App/'. $dir_name .'/'. rtrim($value, '.php')));
143-
}elseif(is_dir($dir_name . '/' . $value)){
147+
if(is_file($dir_name . DIRECTORY_SEPARATOR . $value) && strpos($value, 'Document') !== false){
148+
$return_array[] = str_replace(DIRECTORY_SEPARATOR ,'\\' , str_replace($this->getRootPath() . DIRECTORY_SEPARATOR . 'src' .DIRECTORY_SEPARATOR, '', 'App' . DIRECTORY_SEPARATOR . $dir_name . DIRECTORY_SEPARATOR . rtrim($value, '.php')));
149+
}elseif(is_dir($dir_name . DIRECTORY_SEPARATOR . $value)){
144150
if(!in_array($value, ['.', '..'])) {
145-
$return_array = array_merge($return_array, $this->getDocumentClassArray($dir_name . '/' . $value));
151+
$return_array = array_merge($return_array, $this->getDocumentClassArray($dir_name . DIRECTORY_SEPARATOR . $value));
146152
}
147153
}
148154
}
@@ -164,8 +170,8 @@ function reader($document)
164170
$class = new $document();
165171

166172
if($class instanceof Document){
167-
foreach ($reflClass->getMethods() as $action){
168-
if(strpos($action->getName(), 'Action') !== false && strpos($action->__toString(), str_replace('App/', '', str_replace('\\', '/', $document))) !== false){
173+
foreach ($reflClass->getMethods() as $action) {
174+
if(strpos($action->getName(), 'Action') !== false && strpos($action->__toString(), str_replace('App' . DIRECTORY_SEPARATOR, '', str_replace('\\', DIRECTORY_SEPARATOR, $document))) !== false){
169175
$method = $action->getName();
170176
$class->$method();
171177
}

0 commit comments

Comments
 (0)