Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
c6eba508
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c6eba508
编写于
8月 30, 2019
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
extension generate service
上级
61968d79
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
419 addition
and
0 deletion
+419
-0
config/services/Extension.php
config/services/Extension.php
+3
-0
services/extension/Generate.php
services/extension/Generate.php
+143
-0
services/extension/generate/README.md
services/extension/generate/README.md
+0
-0
services/extension/generate/administer/Install.php
services/extension/generate/administer/Install.php
+82
-0
services/extension/generate/administer/Uninstall.php
services/extension/generate/administer/Uninstall.php
+35
-0
services/extension/generate/administer/Upgrade.php
services/extension/generate/administer/Upgrade.php
+61
-0
services/extension/generate/config.php
services/extension/generate/config.php
+95
-0
未找到文件。
config/services/Extension.php
浏览文件 @
c6eba508
...
@@ -15,6 +15,9 @@ return [
...
@@ -15,6 +15,9 @@ return [
'remoteService'
=>
[
'remoteService'
=>
[
'class'
=>
'fecshop\services\extension\RemoteService'
,
'class'
=>
'fecshop\services\extension\RemoteService'
,
],
],
'generate'
=>
[
'class'
=>
'fecshop\services\extension\Generate'
,
],
],
],
],
],
];
];
\ No newline at end of file
services/extension/Generate.php
0 → 100644
浏览文件 @
c6eba508
<?php
/*
* FecShop file.
*
* @link http://www.fecshop.com/
* @copyright Copyright (c) 2016 FecShop Software LLC
* @license http://www.fecshop.com/license/
*/
namespace
fecshop\services\extension
;
//use fecshop\models\mysqldb\cms\StaticBlock;
use
Yii
;
use
fecshop\services\Service
;
/**
* @author Terry Zhao <2358269014@qq.com>
* @since 1.0
*/
class
Generate
extends
Service
{
/**
* @param $param | array
* 数组子项:package, addon_folder, namespaces, addon_name, addon_author
* 创建应用初始化包到指定的文件路径。
*/
public
function
createAddonsFiles
(
$param
)
{
$package
=
isset
(
$param
[
'package'
])
?
$param
[
'package'
]
:
''
;
$addon_folder
=
isset
(
$param
[
'addon_folder'
])
?
$param
[
'addon_folder'
]
:
''
;
$namespaces
=
isset
(
$param
[
'namespaces'
])
?
$param
[
'namespaces'
]
:
''
;
$addon_name
=
isset
(
$param
[
'addon_name'
])
?
$param
[
'addon_name'
]
:
''
;
$addon_author
=
isset
(
$param
[
'addon_author'
])
?
$param
[
'addon_author'
]
:
''
;
if
(
!
$package
||
!
$addon_folder
||
!
$namespaces
||
!
$addon_name
||
!
$addon_author
)
{
return
false
;
}
// 创建文件夹
if
(
!
$this
->
createFolder
(
$param
))
{
return
false
;
}
// 开始渲染gii 模板
//得到应用文件夹
$addonPath
=
Yii
::
getAlias
(
'@addons/'
.
$package
.
'/'
.
$addon_folder
);
// config.php文件写入
$viewFile
=
'@fecshop/services/extension/generate/config.php'
;
$configContent
=
Yii
::
$app
->
view
->
renderFile
(
$viewFile
,
$param
);
// 写入的文件路径
$addonConfigFile
=
$addonPath
.
'/config.php'
;
if
(
@
file_put_contents
(
$addonConfigFile
,
$configContent
)
===
false
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'Unable to write the file '
.
$addonConfigFile
);
return
false
;
}
// 写入Install
$viewFile
=
'@fecshop/services/extension/generate/administer/Install.php'
;
$configContent
=
Yii
::
$app
->
view
->
renderFile
(
$viewFile
,
$param
);
// 写入的文件路径
$addonConfigFile
=
$addonPath
.
'/administer/Install.php'
;
if
(
@
file_put_contents
(
$addonConfigFile
,
$configContent
)
===
false
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'Unable to write the file '
.
$addonConfigFile
);
return
false
;
}
// 写入Upgrade
$viewFile
=
'@fecshop/services/extension/generate/administer/Upgrade.php'
;
$configContent
=
Yii
::
$app
->
view
->
renderFile
(
$viewFile
,
$param
);
// 写入的文件路径
$addonConfigFile
=
$addonPath
.
'/administer/Upgrade.php'
;
if
(
@
file_put_contents
(
$addonConfigFile
,
$configContent
)
===
false
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'Unable to write the file '
.
$addonConfigFile
);
return
false
;
}
// 写入 Uninstall
$viewFile
=
'@fecshop/services/extension/generate/administer/Uninstall.php'
;
$configContent
=
Yii
::
$app
->
view
->
renderFile
(
$viewFile
,
$param
);
// 写入的文件路径
$addonConfigFile
=
$addonPath
.
'/administer/Uninstall.php'
;
if
(
@
file_put_contents
(
$addonConfigFile
,
$configContent
)
===
false
)
{
Yii
::
$service
->
helper
->
errors
->
add
(
'Unable to write the file '
.
$addonConfigFile
);
return
false
;
}
return
true
;
}
public
function
createFolder
(
$param
)
{
$package
=
isset
(
$param
[
'package'
])
?
$param
[
'package'
]
:
''
;
$addon_folder
=
isset
(
$param
[
'addon_folder'
])
?
$param
[
'addon_folder'
]
:
''
;
$namespaces
=
isset
(
$param
[
'namespaces'
])
?
$param
[
'namespaces'
]
:
''
;
$addon_name
=
isset
(
$param
[
'addon_name'
])
?
$param
[
'addon_name'
]
:
''
;
$addon_author
=
isset
(
$param
[
'addon_author'
])
?
$param
[
'addon_author'
]
:
''
;
$addonPath
=
Yii
::
getAlias
(
'@addons/'
.
$package
.
'/'
.
$addon_folder
);
// 创建文件夹
if
(
!
$this
->
createDir
(
$addonPath
))
{
return
false
;
}
// administer
$administerPath
=
$addonPath
.
'/administer'
;
if
(
!
$this
->
createDir
(
$administerPath
))
{
return
false
;
}
// app/appfront
$appfrontPath
=
$addonPath
.
'/app/appfront'
;
if
(
!
$this
->
createDir
(
$appfrontPath
))
{
return
false
;
}
// models
$modelPath
=
$addonPath
.
'/models'
;
if
(
!
$this
->
createDir
(
$modelPath
))
{
return
false
;
}
// services
$servicesPath
=
$addonPath
.
'/services'
;
if
(
!
$this
->
createDir
(
$servicesPath
))
{
return
false
;
}
return
true
;
}
public
function
createDir
(
$dir
)
{
if
(
is_dir
(
$dir
))
{
Yii
::
$service
->
helper
->
errors
->
add
(
'dir['
.
$dir
.
'] is exist'
);
return
false
;
}
return
mkdir
(
$dir
,
0777
,
true
);
}
}
services/extension/generate/README.md
0 → 100644
浏览文件 @
c6eba508
services/extension/generate/administer/Install.php
0 → 100644
浏览文件 @
c6eba508
<?php
/**
* 应用卸载类生成模板
*/
echo
"<?php
\n
"
;
?>
/**
* Fecmall Addons
*/
namespace
<?=
$namespaces
?>
\administer;
use Yii;
/**
* 应用安装类
* 您可以在这里添加类变量,在配置中的值可以注入进来。
*/
class Install implements \fecshop\services\extension\InstallInterface
{
// 安装初始版本号,不需要改动,不能为空
public $version = '1.0.0';
// 类变量,在config.php中可以通过配置注入值
public $test;
/**
* @return mixed|void
*/
public function run()
{
/**
* 小知识:事务操作中,表数据的操作是可以回滚的,表结构改变的sql是无法回滚的。
$sql = "
DROP TABLE IF EXISTS `fecmall_addon_test1`;
CREATE TABLE `fecmall_addon_test1` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`merchant_id` int(10) unsigned DEFAULT '0' COMMENT '商户id',
`title` varchar(50) NOT NULL COMMENT '标题',
`cover` varchar(100) DEFAULT '' COMMENT '封面',
`seo_key` varchar(50) DEFAULT '' COMMENT 'seo关键字',
`seo_content` varchar(1000) DEFAULT '' COMMENT 'seo内容',
`cate_id` int(10) DEFAULT '0' COMMENT '分类id',
`description` char(140) DEFAULT '' COMMENT '描述".$this->test." ',
`position` smallint(5) NOT NULL DEFAULT '0' COMMENT '推荐位',
`content` longtext COMMENT '文章内容',
`link` varchar(100) DEFAULT '' COMMENT '外链',
`author` varchar(40) DEFAULT '' COMMENT '作者',
`view` int(10) NOT NULL DEFAULT '0' COMMENT '浏览量',
`sort` int(10) NOT NULL DEFAULT '0' COMMENT '优先级',
`status` tinyint(4) DEFAULT '1' COMMENT '状态',
`created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`),
KEY `article_id` (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='扩展_文章表';
-- ----------------------------
-- Table structure for rf_addon_article_adv
-- ----------------------------
DROP TABLE IF EXISTS `fecmall_addon_test2`;
CREATE TABLE `fecmall_addon_test2` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '序号',
`merchant_id` int(10) unsigned DEFAULT '0' COMMENT '商户id',
`title` varchar(30) NOT NULL DEFAULT '' COMMENT '标题',
`cover` varchar(100) DEFAULT '' COMMENT '图片',
`location_id` int(11) DEFAULT '0' COMMENT '广告位ID',
`silder_text` varchar(150) DEFAULT '' COMMENT '图片描述',
`start_time` int(10) DEFAULT '0' COMMENT '开始时间',
`end_time` int(10) DEFAULT '0' COMMENT '结束时间',
`jump_link` varchar(150) DEFAULT '' COMMENT '跳转链接',
`jump_type` tinyint(4) DEFAULT '1' COMMENT '跳转方式[1:新标签; 2:当前页]',
`sort` int(10) DEFAULT '0' COMMENT '优先级',
`status` tinyint(4) DEFAULT '1' COMMENT '状态',
`created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
`updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='扩展_文章_幻灯片表';
";
// 执行sql, 创建表结构的时候,这个函数会返回0,因此不能以返回值作为return
Yii::$app->getDb()->createCommand($sql)->execute();
*/
return true;
}
}
\ No newline at end of file
services/extension/generate/administer/Uninstall.php
0 → 100644
浏览文件 @
c6eba508
<?php
/**
* 应用卸载类生成模板
*/
echo
"<?php
\n
"
;
?>
/**
* Fecmall Addons
*/
namespace
<?=
$namespaces
?>
\administer;
use Yii;
/**
* 应用安装类
* 您可以在这里添加类变量,在配置中的值可以注入进来。
*/
class Uninstall implements \fecshop\services\extension\UninstallInterface
{
/**
* 应用执行卸载的步骤执行的函数。
*/
public function run()
{
/*
$sql = "
// DROP TABLE IF EXISTS `fecmall_addon_test1`;
// DROP TABLE IF EXISTS `fecmall_addon_test2`;
";
// 执行sql, 创建表结构的时候,这个函数会返回0,因此不能以返回值作为return
Yii::$app->getDb()->createCommand($sql)->execute();
*/
return true;
}
}
\ No newline at end of file
services/extension/generate/administer/Upgrade.php
0 → 100644
浏览文件 @
c6eba508
<?php
/**
* 应用卸载类生成模板
*/
echo
"<?php
\n
"
;
?>
/**
* Fecmall Addons
*/
namespace
<?=
$namespaces
?>
\administer;
use Yii;
/**
* 应用安装类
* 您可以在这里添加类变量,在配置中的值可以注入进来。
*/
class Upgrade implements \fecshop\services\extension\UpgradeInterface
{
/**
* @var array
* 必须按照版本号依次填写,否则升级会导致问题。
* 如果安装的初始版本号为1.0.0,那么下面的升级版本号必须比初始版本号大才行
*/
public $versions = [
// '1.0.1',
// '1.0.2',
// '1.0.3',
];
/**
* @param $version 最新版本号
* @return boolean
* 升级执行的函数,您可以在各个版本号需要执行的部分写入相应的操作。
*/
public function run($version)
{
/**
* 下面仅仅是一个sql例子,您可以将其换成您自己要升级的内容
switch ($version)
{
case '1.0.1' :
// 增加测试 - 冗余的字段
$sql = "ALTER TABLE fecmall_addon_test1 ADD COLUMN redundancy_field_5255 varchar(48);";
Yii::$app->getDb()->createCommand($sql)->execute();
break;
case '1.0.2' :
// 删除测试 - 冗余的字段
$sql = "ALTER TABLE fecmall_addon_test1 ADD COLUMN redundancy_field_566 varchar(48);";
Yii::$app->getDb()->createCommand($sql)->execute();
break;
case '1.0.3' :
// 删除测试 - 冗余的字段
$sql = "ALTER TABLE fecmall_addon_test1 ADD COLUMN redundancy_field_567 varchar(48);";
Yii::$app->getDb()->createCommand($sql)->execute();
break;
}
*/
return true;
}
}
\ No newline at end of file
services/extension/generate/config.php
0 → 100644
浏览文件 @
c6eba508
<?php
/**
* 应用卸载类生成模板
*/
echo
"<?php
\n
"
;
?>
/**
* Fecmall Addons Config File
*/
// set namespace alisa
Yii::setAlias('@
<?=
$namespaces
?>
', dirname(dirname(dirname(__DIR__))).'/addons/
<?=
$package
?>
/
<?=
$addon_folder
?>
/');
return [
// 插件信息
'info' => [
'name' => '
<?=
$addon_name
?>
',
'author' => '
<?=
$addon_author
?>
',
],
// 插件管理部分
'administer' => [
'install' => [
'class' => '
<?=
$namespaces
?>
\administer\Install',
// 其他引入的属性,类似yii2组件的方式写入即可
'test' => 'test_data',
],
'upgrade' => [
'class' => '
<?=
$namespaces
?>
\administer\Upgrade',
],
'uninstall' => [
'class' => '
<?=
$namespaces
?>
\administer\Uninstall',
],
],
// 各个入口的配置
'app' => [
// 公共层部分配置
'common' => [
'enable' => true,
// 公用层的具体配置下载下面
'config' => [
'services' => [
//'cart' => [
// 'class' => 'fecshop\rediscart\services\Cart',
// 'childService' => [
// 'quote' => [
// 'class' => 'fecshop\rediscart\services\cart\Quote',
// ],
// 'quoteItem' => [
// 'class' => 'fecshop\rediscart\services\cart\QuoteItem',
// ],
// ]
//]
],
]
],
// 1.appfront层
'appfront' => [
// appfront入口的开关,如果false,则会失效
'enable' => true,
'config' => [
// yii class rewrite map
'yiiClassMap' => [
// 'fecshop\app\appfront\helper\test\My' => '@appfront/helper/My.php',
],
// 重写model和block
'fecRewriteMap' => [
// '\fecshop\app\appfront\modules\Cms\block\home\Index' => '\fectfurnilife\app\appfront\modules\Cms\block\home\Index',
// '\fecshop\app\appfront\modules\Customer\block\address\Edit' => '\fectfurnilife\app\appfront\modules\Customer\block\address\Edit',
],
'modules' => [
//'checkout' => [
// 'controllerMap' => [
// 'cartinfo' => 'fectfurnilife\app\appfront\modules\Checkout\controllers\CartInfoController',
// ],
//],
],
],
],
// html5入口
'apphtml5' =>[],
// appserver入口(vue 微信小程序等api)
'appserver' =>[],
// appapi入口,和第三方交互的api
'appapi' =>[],
// 后台部分
'appadmin' =>[],
// console,命令行脚本端
'console' =>[],
],
];
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录