forked from wemecan/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
小滕
committed
Mar 6, 2020
0 parents
commit 0c1cedc
Showing
22 changed files
with
816 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
title: 'MeEdu开发文档', | ||
description: 'MeEdu插件和模板开发文档', | ||
themeConfig: { | ||
nav: [ | ||
{ text: '文档首页', link: '/' }, | ||
{ text: '官网', link: 'https://meedu.vip' }, | ||
{ text: 'Github', link: 'https://github.com/Qsnh/meedu' }, | ||
{ text: '插件开发', link: '/addons/' }, | ||
{ text: '模板开发', link: '/template/' }, | ||
], | ||
sidebar: { | ||
'/addons/': [ | ||
'', | ||
'快速开始', | ||
'约定', | ||
'服务注册', | ||
'路由注册', | ||
'视图注册', | ||
'命令注册', | ||
'事件监听', | ||
'中间件注册' | ||
], | ||
'/template/': [ | ||
'', | ||
'快速开始', | ||
'目录结构', | ||
'全局变量', | ||
'静态资源', | ||
'模板打包' | ||
] | ||
}, | ||
lastUpdated: 'Last Updated' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
home: true | ||
heroText: MeEdu | ||
tagline: 开源免费的在线点播收费系统 | ||
actionText: 快速上手 → | ||
actionLink: ./addons/ | ||
features: | ||
- title: 开源 | ||
details: MeEdu遵循MIT协议,所有用户可以自由免费的使用MeEdu。 | ||
- title: 生态丰富 | ||
details: MeEdu有完善的生态体系,丰富的插件足以满足您的任何需求。 | ||
- title: 安全 | ||
details: MeEdu是基于Laravel框架开发,数年来未出现任何重大安全漏洞。 | ||
footer: Copyright © 2020 MEEDU.VIP | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
## MeEdu插件开发 | ||
|
||
::: tip | ||
在插件开发开始之前,建议您仔细的阅读完这篇文章 [Laravel扩展包开发](https://learnku.com/docs/laravel/5.8/packages/3922) | ||
::: | ||
|
||
|
||
## 目录 | ||
|
||
+ [快速开始](快速开始.md) | ||
+ [约定](约定.md) | ||
+ [meedu.json](meedu.json.md) | ||
+ [服务注册](服务注册.md) | ||
+ [路由注册](路由注册.md) | ||
+ [视图注册](视图注册.md) | ||
+ [命令注册](命令注册.md) | ||
+ [事件监听](事件监听.md) | ||
+ [中间件注册](中间件注册.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
## `meedu.json` 文件 | ||
|
||
这个文件是插件必须的文件,它决定了 meedu 是否可以正确的加载到您的插件。 | ||
|
||
内容如下: | ||
|
||
```json | ||
{ | ||
"name": "测试", | ||
"version": "v1.0", | ||
"required": {} | ||
} | ||
``` | ||
|
||
| 字段 | 解释 | | ||
| --- | --- | | ||
| `name` | 插件名 | | ||
| `version` | 插件版本 | | ||
| `required` | 插件依赖,同 `composer.json` 的 `required` 字段 | | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
## 中间件注册 | ||
|
||
如果插件中的中间件只在插件的作用于内使用的话,那么就很简单了,直接在路由里面: | ||
|
||
```php | ||
Route::get('/', 'IndexController@index')->middleware(YourSelfMiddleware::class); | ||
``` | ||
|
||
这样就可以直接使用了。 | ||
|
||
如果您需要将自定义的中间件注册到全局中的话,你可以这样做: | ||
|
||
```php | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: xiaoteng | ||
* Date: 2019/1/13 | ||
* Time: 12:07 | ||
*/ | ||
|
||
namespace Addons\WeixinLogin; | ||
= | ||
use Addons\WeixinLogin\Http\Middlewares\WeixinLoginMiddleware; | ||
use Illuminate\Support\Facades\Route; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class MainServiceProvider extends ServiceProvider | ||
{ | ||
|
||
public function boot() | ||
{ | ||
Route::pushMiddlewareToGroup('web', WeixinLoginMiddleware::class); | ||
} | ||
|
||
public function register() | ||
{ | ||
} | ||
|
||
} | ||
``` | ||
|
||
`Route::pushMiddlewareToGroup` 方法就是将某个中间件注册到某个 `middlewareGroup` 中,当然这里仅仅给出了一个方法,laravel当中还有好多其他的方法,您可以去阅读 laravel 的api文档获取更多的用法。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
|
||
## 事件监听 | ||
|
||
事件监听可能是许多开发者比较关注的事情,丰富的事件监听可以让开发者更好的开发相关插件。有关 meedu 的事件注册,开发者可以到meedu的 `EventServiceProvider` 文件查看,这里给上一个 demo ,仅供参考: | ||
|
||
```php | ||
<?php | ||
|
||
/* | ||
* This file is part of the Qsnh/meedu. | ||
* | ||
* (c) XiaoTeng <616896861@qq.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace App\Providers; | ||
|
||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; | ||
|
||
class EventServiceProvider extends ServiceProvider | ||
{ | ||
protected $listen = [ | ||
'App\Events\PaymentSuccessEvent' => [ | ||
'\App\Listeners\PaymentSuccessEvent\OrderPaidDeliverListener', | ||
'\App\Listeners\PaymentSuccessEvent\OrderPaidNotificationListener', | ||
'\App\Listeners\PaymentSuccessEvent\OrderPaidStatusChangeListener', | ||
'\App\Listeners\PaymentSuccessEvent\PromoCodeListener', | ||
'\App\Listeners\PaymentSuccessEvent\InviteUserRewardListener', | ||
], | ||
'App\Events\OrderCancelEvent' => [ | ||
'\App\Listeners\OrderCancelEvent\PromoCodeResumeListener', | ||
'\App\Listeners\OrderCancelEvent\InviteBalanceResumeListener', | ||
], | ||
'App\Events\AdFromEvent' => [ | ||
'App\Listeners\AdFromEvent\AdFromListener', | ||
], | ||
\SocialiteProviders\Manager\SocialiteWasCalled::class => [ | ||
'SocialiteProviders\\WeixinWeb\\WeixinWebExtendSocialite@handle', | ||
'SocialiteProviders\\QQ\\QqExtendSocialite@handle', | ||
], | ||
'App\Events\CourseCommentEvent' => [ | ||
'App\Listeners\CourseCommentEvent\NotifyOwnerListener', | ||
'App\Listeners\CourseCommentEvent\AtEventListener', | ||
], | ||
'App\Events\VideoCommentEvent' => [ | ||
'App\Listeners\VideoCommentEvent\NotifyOwnerListener', | ||
'App\Listeners\VideoCommentEvent\AtEventListener', | ||
], | ||
'App\Events\UserRegisterEvent' => [ | ||
'App\Listeners\UserRegisterEvent\WelcomeMessageListener', | ||
], | ||
'App\Events\UserLoginEvent' => [ | ||
'App\Listeners\UserLoginEvent\SafeAlertListener', | ||
'App\Listeners\UserLoginEvent\BindMobileListener', | ||
], | ||
'App\Events\UserInviteBalanceWithdrawCreatedEvent' => [ | ||
'App\Listeners\UserInviteBalanceWithdrawCreatedEvent\NotifyListener', | ||
], | ||
'App\Events\UserInviteBalanceWithdrawHandledEvent' => [ | ||
'App\Listeners\UserInviteBalanceWithdrawHandledEvent\NotifyListener', | ||
'App\Listeners\UserInviteBalanceWithdrawHandledEvent\RefundBalanceListener', | ||
], | ||
]; | ||
} | ||
``` | ||
|
||
插件中,我们可以这样监听某个事件: | ||
|
||
```php | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: xiaoteng | ||
* Date: 2019/1/13 | ||
* Time: 12:07 | ||
*/ | ||
|
||
namespace Addons\Zhibo; | ||
|
||
use Addons\Zhibo\Listeners\OrderPaidDeliverListener; | ||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class MainServiceProvider extends ServiceProvider | ||
{ | ||
|
||
protected $listen = [ | ||
'App\Events\PaymentSuccessEvent' => [ | ||
OrderPaidDeliverListener::class, | ||
], | ||
]; | ||
|
||
public function boot() | ||
{ | ||
// 事件注册 | ||
foreach ($this->listen as $event => $listeners) { | ||
foreach ($listeners as $listener) { | ||
Event::listen($event, $listener); | ||
} | ||
} | ||
} | ||
|
||
public function register() | ||
{ | ||
} | ||
|
||
} | ||
``` | ||
|
||
> 注意,事件监听的代码是写在 `boot()` 方法里面。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
## 命令注册 | ||
|
||
meedu插件的安装和卸载都是通过命令完成的,所以一款插件的必须要有相应的安装和卸载命令。 | ||
|
||
我们约定,在插件目录下创建 `Commands` 目录,并在该目录创建 `AppCommand.php` 文件,结构如下: | ||
|
||
```sh | ||
./Commands | ||
└── AppCommand.php | ||
``` | ||
|
||
其中,`AppCommand.php` 文件内容如下: | ||
|
||
```php | ||
<?php | ||
|
||
namespace Addons\Demo1\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\Artisan; | ||
|
||
class AppCommand extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'Demo1 {action}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = ''; | ||
|
||
/** | ||
* AppCommand constructor. | ||
*/ | ||
public function __construct(F) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
public function handle() | ||
{ | ||
$action = $this->argument('action'); | ||
$method = 'action' . ucfirst($action); | ||
$this->{$method}(); | ||
} | ||
|
||
protected function actionInstall() | ||
{ | ||
} | ||
|
||
protected function actionUninstall() | ||
{ | ||
} | ||
|
||
protected function actionUpgrade() | ||
{ | ||
} | ||
} | ||
``` | ||
|
||
这样,插件的命令就注册成功了,接下来,我们就可通过: | ||
|
||
```sh | ||
# 插件安装 | ||
php artisan Demo1 install | ||
# 插件升级 | ||
php artisan Demo1 upgrade | ||
# 插件写在 | ||
php artisan Demo1 uninstall | ||
``` | ||
|
||
至于插件的安装,升级,卸载的逻辑,我们可以在上面的命令文件中的 `actionInstall` , `actionUpgrade` , `actionUninstall` 三个方法完成。 |
Oops, something went wrong.