<?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. golang流程控制if,switch分支

    if 分支 if 单分支 if 条件表达式 { 逻辑代码 } package main import "fmt" func main() { //var a int = 9 //i ...

  2. 【Frida】Java反射调用

    通过反射调用,获取类名 参数Object obj 类名 String str 方法名 static Object a(Object obj, String str) { try { return ob ...

  3. SpringBoot Circular view path错误

    在运行SpringBoot时报了这样一个错误 百度翻译是视图循环 搜索一下 原来是类上restcontroller写成了controller  对比一下两者 @Controller和@RestCont ...

  4. 宝塔部署 vue + thinkphp

    部署https://blog.csdn.net/xinxinsky/article/details/105441164?spm=1001.2101.3001.6650.2&utm_medium ...

  5. Python-numpy基本用法

    import numpy as np import numpy as np #导入numpy库 _version_显示版本号 show_config() 显示配置文件 print(np.__versi ...

  6. mybatis-plus 时间查询

    QueryWrapper userquery= new QueryWrapper<>(); user.and(true,wrapper -> wrapper.ge("CRE ...

  7. sql语句查询优化

    SQL 性能优化 explain 中的 type:至少要达到 range 级别,要求是 ref 级别,如果可以是 consts 最好. consts:单表中最多只有一个匹配行(主键或者唯一索引),在优 ...

  8. 基于Mybatis Plus的一种查询条件构建方案

    ! 重要: 遐(瞎)想的思路, 希望各位多多建议 record为jdk17写法, 使用class也不会有问题 背景 身为资深程序员, 上班最重要的事当然是增删改查(bushi). 比如今天, 组长甩给 ...

  9. unity 利用相机截图,可以截取UI,保存png格式,可用于签名抠图

    public Camera cam; void Start() { StartCoroutine(CaptureAlphaCamera(cam,new Rect(0,0,1920,1080))); } ...

  10. noi 1.5 42画矩形

    noi 1.5 42画矩形 1.描述 根据参数,画出矩形. 2.输入 输入一行,包括四个参数:前两个参数为整数,依次代表矩形的高和宽(高不少于3行不多于10行,宽不少于5列不多于10列):第三个参数是 ...