<?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. VUE学习-:class & :style

    :class & :style :class 键值对 <div id="app" v-bind:class="{ 'active': isActive }& ...

  2. error:0308010C:digital envelope routines::unsupported

    Node.js v18.14.1 运行项目 node:internal/crypto/hash:71 this[kHandle] = new _Hash(algorithm, xofLen); ^ E ...

  3. 性能测试工具locust压测介绍

    官方文档:https://docs.locust.io/en/stable/index.html 1.初识locust Locust 完全基本 Python 编程语言,采用python 编写压测脚本, ...

  4. div 拖动 js实现

    function dragFun(id) { var Drag = document.getElementById(id); Drag.onmousedown = function(event) { ...

  5. web.py 中的分页设计

    1.定义分页类 class Pagination(object): ''' 分页类 参数: per_page:每页数量 total_data:总数目 cur_page:当前页. 用法:(flask,h ...

  6. Delphi获取程序版本号

    参考: http://www.delphitop.com/html/hanshu/4627.html procedure GetVersionInfo(const FileName:string; v ...

  7. starlette.routing.NoMatchFound

    目前正在学习FastAPI, 目前是学习到了引入静态文件.这是我引入的本地文件的方式 url_for('/static', path='/imgs/favicon.ico') 只要启动服务,就会报错5 ...

  8. swift中的进制转换,以及玩转二进制

    swift中的进制转换,以及玩转二进制 在日常开发中我们很少用到进制转换,或操作二进制的情况.但是如果你处理一些底层的代码,你会经常与二进制打交道,所以接下来我们先来了解一下二进制. 二进制(bina ...

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

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

  10. Android学习——控件ImageView

    1.主要属性 2.缩放类型