<?php
namespace app\command; use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output; class Scan extends Command
{
protected $root = 'runtime/';
protected $output = '';
protected $file_count = 0; protected function configure()
{
$this->setName('fa')
->addArgument('name', Argument::OPTIONAL, "插件名称")
->addOption('source', null, Option::VALUE_REQUIRED, '压缩文件')
->setDescription('打包fa开发的插件');
} protected function execute(Input $input, Output $output)
{
$this->output = $output;
$name = trim($input->getArgument('name'));
if (!$name) {
$output->writeln('请输入插件名称:');
exit();
} else {
$this->root .= $name . '/';
}
$this->selectFIles('@plugin ' . $name); if ($input->hasOption('source')) {
$source = $input->getOption('source');
} else {
$source = 'zip';
} $addons = './runtime/addons';
if (!file_exists($addons)) {
$this->mkdirs($addons, 0777);
}
// 拷贝到插件
$addons_path = './addons/' . $name;
$this->recurse_copy($this->root, $addons_path); $this->zip($addons_path, $addons . '/' . $name, $name); $zipcreated = $addons . '/' . $name . ".zip";
if (file_exists($zipcreated)) {
$this->recursiveDelete($this->root);
} $output->writeln('打包成功,共' . $this->file_count . '个文件!');
} //执行,递归查询文件
private function selectFIles($name)
{
//开始运行
$arr_file = array();
$scans = [
'./public',
'./app',
];
foreach ($scans as $key => $value) {
$this->trees($arr_file, $value, str_replace('./', '', $value));
$this->handelFiles($arr_file, $name);
}
} // 递归拿到所有的文件包含目录
private function trees(&$arr_file, $directory, $dir_name = '')
{ $mydir = dir($directory);
while ($file = $mydir->read()) {
if ((is_dir("$directory/$file")) and ($file != ".") and ($file != "..")) {
$this->trees($arr_file, "$directory/$file", "$dir_name/$file");
} else if (($file != ".") and ($file != "..")) {
$arr_file[] = "$dir_name/$file";
}
}
$mydir->close();
} //判断文件是否包含插件标识
private function handelFiles(&$arr_file, $name = '')
{
foreach ($arr_file as $key => $value) {
if (!is_dir($value)) {
// 文件
if (is_file($value)) {
$file = file_get_contents($value);
if (strstr($file, $name)) {
$this->file_count += 1;
$this->makeDirByPath($value);
}
}
}
}
} /**
* 根绝文件路径创建对应的目录
* @param string $path a/b/c/d/
*
*/
private function makeDirByPath($path)
{
$opath = $path;
$path = $this->root . $path;
$dir = dirname($path);
if (!file_exists($dir)) {
$this->mkdirs($dir, 0777);
$this->echo('创建文件夹' . $dir . '成功');
} if (is_file($opath)) {
copy($opath, $path);
$this->echo('拷贝文件' . $opath . '成功');
}
} //创建文件夹
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)) {
return true;
} if (!$this->mkdirs(dirname($dir), $mode)) {
return false;
} return @mkdir($dir, $mode);
} //输出模式
function echo ($msg) {
$this->output->writeln($msg);
} private function zip($pathdir, $names, $addons_name)
{
// 创建压缩目录的名称
$zipcreated = $names . ".zip";
// Get real path for our folder
$rootPath = $pathdir; // Initialize archive object
$zip = new \ZipArchive();
$zip->open($zipcreated, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); // Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootPath),
\RecursiveIteratorIterator::LEAVES_ONLY
); foreach ($files as $name => $file) {
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
// var_dump($addons_name);die;
$relativePath = substr($filePath, strlen($rootPath) + 15 + strlen($addons_name));
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
// Zip archive will be created only after closing object
$zip->close();
} // $dir:要删除的文件的目录
private function recursiveDelete($dir)
{
// 打开指定目录
if ($handle = @opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (($file == ".") || ($file == "..")) {
continue;
}
if (is_dir($dir . '/' . $file)) {
// 递归
$this->recursiveDelete($dir . '/' . $file);
} else {
unlink($dir . '/' . $file); // 删除文件
}
}
@closedir($handle);
rmdir($dir);
}
} // cp文件$src 源, $dst目标
private function recurse_copy($src, $dst)
{
$dir = opendir($src);
@mkdir($dst);
while (false !== ($file = readdir($dir))) {
if (($file != '.') && ($file != '..')) {
if (is_dir($src . '/' . $file)) {
$this->recurse_copy($src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
}
}

  1.php think scan 插件名称

  思考:

    1.需要插件标识 @plugin 插件名称

    2.需要配置文件console.php配置命名行模式

    3.打包的文件在./runtime/addons目录

fastadmin打包插件的更多相关文章

  1. FastAdmin CMS 插件下载

    FastAdmin CMS 插件下载 CMS内容管理系统插件(含小程序) 自定义内容模型.自定义单页.自定义表单.自定义会员发布.付费阅读.小程序等 提供全部前后端源代码和小程序源代码 功能特性 基于 ...

  2. 随笔:关于 FastAdmin ueditor 插件 中的 rand mt_rand mt_getrandmax 问题

    随笔:关于 FastAdmin ueditor 插件 中的 rand mt_rand mt_getrandmax 问题 问题来源 一位小伙伴在使用 Ueditor 插件时出错,因为用的是 php7.1 ...

  3. FastAdmin CMS 插件相关文章收集(2018-08-16)

    FastAdmin CMS 插件相关文章收集(2018-08-16) CMS内容管理系统(含小程序) 介绍 https://www.fastadmin.net/store/cms.html CMS内容 ...

  4. 为什么 FastAdmin 的插件不全部免费?

    为什么 FastAdmin 的插件不全部免费? 主要还是有以下几个原因. 支持开发者. 为了支付网站空间费和 CDN 费. 有收入后可以更好的开发 FastAdmin.

  5. assembly打包插件引发的自定义spring标签找不到声明的错误

    异常信息:通配符的匹配很全面, 但无法找到元素 的声明. 报的异常信息是关于我们使用的一个自定义的spring标签,这个异常通常的原因可能是读取不到自定义标签的映射. 到META-INF目录下找一下是 ...

  6. maven打包插件maven-assembly-plugin

    1.POM文件添加jar包生成插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifac ...

  7. springboot 打包插件去除jar包瘦身

    1.pom文件配置 <plugin> <groupId>org.springframework.boot</groupId> <artifactId>s ...

  8. Maven打包插件Assembly(七)

    1. 在 dubbo 的 provider 项目(实现类项目dubbo-service-impl)中 pom.xml 配置 assembly插件信息 <!-- 指定项目的打包插件信息 --> ...

  9. eclipse打包插件net.sf.fjep.fatjar

    eclipse打包插件安装 1)将net.sf.fjep.fatjar_0.0.32.jar拷贝到eclipse安装目录中的plugins目录下,然后重启eclipse即可. 软件获取方式: 链接:h ...

  10. java 打包插件

    是时候闭环Java应用了 原创 2016-08-16 张开涛  你曾经因为部署/上线而痛苦吗?你曾经因为要去运维那改配置而烦恼吗?在我接触过的一些部署/上线方式中,曾碰到过以下一些问题: 1.程序代码 ...

随机推荐

  1. MSF内网信息收集

    1. msf通过shell关闭防火墙 Netsh advfirewall set allprofiles state off(关闭防火墙) Netsh advfirewall show allprof ...

  2. gobuster安装

    Github地址:https://github.com/OJ/gobuste 第一种方式 sudo apt install golang-gogo install github.com/OJ/gobu ...

  3. Homebrew macOS飞速安装教程

    ​ 快速安装 打开终端 /bin/bash -c "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/insta ...

  4. 升级sqlite3

    原文连接: https://blog.zhheo.com/p/22f4cbb2.html 创建一个工作目录(可选) Code 12 mkdir sqlite3_upgradecd sqlite3_up ...

  5. pycharm 连接服务器进行操作比 Xshell 更简单!

    一.SSH 连接 pycharm 中通过 SSH 连接服务器非常的简单,只需要简单的几步操作就能完成,如下图 1.第一步:点击开启 SSH 会话 2.第二步:填入对应的连接信息,点击 OK 3.这个时 ...

  6. [267] High Five

    [267] High Five Client 00 SendLogOut 01 RequestAttack 03 RequestStartPledgeWar 04 RequestReplyStartP ...

  7. SpringBoot打成war包,部署到Tomcat服务器

    SpringBoot默认达成jar包,使用SpringBoot构想web应用,默认使用内置的Tomcat.但考虑到项目需要集群部署或者进行优化时,就需要打成war包部署到外部的Tomcat服务器中.  ...

  8. [SSH-1]publickey,gssapi-keyex,gssapi-with-mic

    实际上,是有两个不同的原因的,它们都会造成这个报错. 原因1)client端私钥文件权限太大 解决方法:chmod 400 ~/.ssh/id_rsa  #如果是RSA算法的话,私钥生成时默认叫id_ ...

  9. ORA-28001 口令已经失效(密码过期)相关问题处理

    Oracle 提示错误消息 ORA-28001: the password has expired, 经调查是由于 Oracle 11G 的新特性所致, Oracle 11G 创建用户时缺省密码过期限 ...

  10. Linux命令-df

    场景: df -h查看磁盘信息 /dev/mapper/rl-root 96% du -h --max-depth=1 命令代表寻找当前目录,哪个文件夹占用空间最大,进入根目录: [root@loca ...