catchAdmin/extend/catcher/ModuleService.php

85 lines
2.2 KiB
PHP
Raw Normal View History

2020-06-24 08:47:46 +08:00
<?php
2020-11-29 09:29:14 +08:00
declare(strict_types=1);
2020-06-24 08:47:46 +08:00
// +----------------------------------------------------------------------
// | CatchAdmin [Just Like ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://catchadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://github.com/yanwenwu/catch-admin/blob/master/LICENSE.txt )
// +----------------------------------------------------------------------
// | Author: JaguarJack [ njphper@gmail.com ]
// +----------------------------------------------------------------------
2020-06-24 09:11:30 +08:00
namespace catcher;
use think\Service;
abstract class ModuleService extends Service
{
abstract public function loadRouteFrom();
2020-07-02 14:01:05 +08:00
/**
* 注册
*
* @time 2020年07月02日
* @return void
*/
2020-06-24 09:11:30 +08:00
public function register()
{
$this->app->make('routePath')->loadRouterFrom($this->loadRouteFrom());
$this->registerEvents();
2020-07-02 14:01:05 +08:00
2020-09-26 15:11:50 +08:00
$this->registerCommands();
$this->registerConfig();
2020-06-24 09:11:30 +08:00
}
/**
2020-07-02 14:01:05 +08:00
* 事件注册
2020-06-24 09:11:30 +08:00
*
* @time 2020年06月24日
* @return void
*/
protected function registerEvents()
{
if (method_exists($this, 'loadEvents')) {
$this->app->event->listenEvents($this->loadEvents());
}
}
2020-09-26 15:11:50 +08:00
/**
* register config
*
* @time 2020年09月25日
* @return void
*/
protected function registerConfig()
{
if (method_exists($this, 'loadConfig')) {
$this->app->config->set(array_merge($this->app->config->get('catch'), $this->loadConfig()), 'catch');
}
}
2020-07-02 14:01:05 +08:00
/**
* 注册commands
*
* @time 2020年07月02日
* @return void
*/
protected function registerCommands()
{
if (method_exists($this,'loadCommands') && $this->app->runningInConsole()) {
2020-07-02 14:01:05 +08:00
list($namespace, $path) = $this->loadCommands();
2020-06-24 09:11:30 +08:00
2020-07-21 08:01:20 +08:00
if ($this->app->has('catch\console')) {
$catchConsole = $this->app['catch\console'];
2020-07-20 17:03:49 +08:00
$this->commands($catchConsole->setNamespace($namespace)
->path($path)
->commands());
}
2020-07-02 14:01:05 +08:00
}
}
2020-06-24 09:11:30 +08:00
}