From f0351246fc9020fc19203f5c317d1323b8875894 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Tue, 21 Jul 2020 08:01:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ezip&composer=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/catcher/CatchAdminService.php | 4 +- extend/catcher/ModuleService.php | 4 +- extend/catcher/library/Composer.php | 5 ++ extend/catcher/library/Zip.php | 109 +++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 4 deletions(-) diff --git a/extend/catcher/CatchAdminService.php b/extend/catcher/CatchAdminService.php index 606859c..8664a81 100644 --- a/extend/catcher/CatchAdminService.php +++ b/extend/catcher/CatchAdminService.php @@ -43,10 +43,10 @@ class CatchAdminService extends Service */ protected function registerCommands(): void { - if ($this->app->runningInConsole() && class_exists('Symfony\Component\Finder\Finder')) { + if ($this->app->runningInConsole()) { $catchConsole = new CatchConsole($this->app); - $this->app->bind('catch_console', $catchConsole); + $this->app->bind('catch\console', $catchConsole); $this->commands($catchConsole->commands()); } diff --git a/extend/catcher/ModuleService.php b/extend/catcher/ModuleService.php index 7285308..286df81 100644 --- a/extend/catcher/ModuleService.php +++ b/extend/catcher/ModuleService.php @@ -55,8 +55,8 @@ abstract class ModuleService extends Service if (method_exists($this,'loadCommands') && $this->app->runningInConsole()) { list($namespace, $path) = $this->loadCommands(); - if ($this->app->has('catch_console')) { - $catchConsole = $this->app['catch_console']; + if ($this->app->has('catch\console')) { + $catchConsole = $this->app['catch\console']; $this->commands($catchConsole->setNamespace($namespace) ->path($path) diff --git a/extend/catcher/library/Composer.php b/extend/catcher/library/Composer.php index 388fa2b..eaa887d 100644 --- a/extend/catcher/library/Composer.php +++ b/extend/catcher/library/Composer.php @@ -19,6 +19,11 @@ class Composer return $this->composerContent()['autoload']['psr-4']; } + public function requires() + { + return $this->composerContent()['require']; + } + protected function composerContent() { return \json_decode(FileSystem::get($this->composerJsonPath()), true); diff --git a/extend/catcher/library/Zip.php b/extend/catcher/library/Zip.php index ef90e0a..3a6148e 100644 --- a/extend/catcher/library/Zip.php +++ b/extend/catcher/library/Zip.php @@ -8,3 +8,112 @@ // +---------------------------------------------------------------------- // | Author: JaguarJack [ njphper@gmail.com ] // +---------------------------------------------------------------------- +namespace catcher\library; + +use catcher\facade\FileSystem; + +class Zip +{ + protected $zipArchive; + + const EXTENSION = 'zip'; + + protected $folder; + + public function __construct() + { + $this->zipArchive = new \ZipArchive(); + } + + /** + * zip 文件 + * + * @time 2020年07月19日 + * @param $zip + * @throws \Exception + * @return $this + */ + public function make($zip) + { + if (FileSystem::extension($zip) != self::EXTENSION) { + throw new \Exception("make zip muse set [zip] extension"); + } + + $this->zipArchive->open($zip, \ZipArchive::CREATE); + + return $this; + } + + /** + * 添加文件 + * + * @time 2020年07月19日 + * @param $files + * @param bool $relative + * @return $this + */ + public function addFiles($files, $relative = true) + { + if ($relative) { + foreach ($files as $file) { + $this->zipArchive->addFile($file->getPathname(), $this->folder . $file->getRelativePathname()); + } + + } else { + foreach ($files as $file) { + $this->zipArchive->addFile($file->getPathname(), $this->folder . $file->getPathname()); + } + } + + return $this; + } + + /** + * 根目录 + * + * @time 2020年07月19日 + * @param string $folder + * @return $this + */ + public function folder(string $folder) + { + $this->zipArchive->addEmptyDir($folder); + + $this->folder = $folder . DIRECTORY_SEPARATOR; + + return $this; + } + + /** + * 解压到 + * + * @time 2020年07月19日 + * @param $path + * @return $this + * @throws \Exception + */ + public function extractTo($path) + { + if (!$this->zipArchive->extractTo($path)) { + throw new \Exception('extract failed'); + } + + return $this; + } + + public function getFiles() + { + $this->zipArchive; + } + /** + * 关闭 + * + * @time 2020年07月19日 + * @return void + */ + public function close() + { + $this->zipArchive->close(); + } + +} \ No newline at end of file