<?php

namespace App\Providers;

use App\Ad\Providers\AdServiceProvider;
use App\Common\Providers\CommonProvider;
use App\ExcelData\Providers\ExcelDataProvider;
use App\Form\Providers\FormServiceProvider;
use App\User\Providers\UserProvider;
use App\Web\Components\Ad\AdInfo;
use App\Web\Components\Blog\BlogPlateTypeTag;
use App\Web\Components\Blog\KnowledgeCentre;
use App\Web\Components\Blog\NewsInfo;
use App\Web\Components\Blog\NewsList;
use App\Web\Components\Blog\Partners;
use App\Web\Components\Blog\QuestionsAndAnswers;
use App\Web\Components\Blog\RecentNewsList;
use App\Web\Components\Blog\SolutionList;
use App\Web\Components\Blog\SuccessCaseList;
use App\Web\Components\Blog\TypeList;
use App\Web\Components\Blog\VideoList;
use App\Web\Components\Form\FormInfo;
use App\Web\Components\Help\HelpList;
use App\Web\Components\Meeting\MeetingGlobalList;
use App\Web\Components\Meeting\MeetingInfo;
use App\Web\Components\Meeting\MeetingList;
use App\Web\Components\Page\PageContent;
use App\Web\Components\Product\ProductList;
use App\Web\Components\Product\ProductListByIds;
use App\Web\Providers\WebServiceProvider;
use Illuminate\Redis\RedisServiceProvider;
use Illuminate\Support\Facades\Blade;
use Laravel\Lumen\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        \App\Events\ExampleEvent::class => [
            \App\Listeners\ExampleListener::class,
        ],
    ];
    //路由文件名
    protected $routes = 'routes.php';

    public function boot()
    {
        //自动载入路由
        $func = new \ReflectionClass(get_class($this));
        $path = str_replace($func->getShortName() . '.php', '', $func->getFileName());
        $routesFile = $path . '../' . $this->routes;
        if (file_exists($routesFile)) {
            require $routesFile;
        }
        if (!isset($this->app['blade.compiler'])) {
            $this->app['view'];
        }
        $this->registerComponent();
        parent::boot();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //注册redis服务
        $this->app->register(RedisServiceProvider::class);
        //注册userProvider
        $this->app->register(UserProvider::class);
        //注册CommonProvider
        $this->app->register(CommonProvider::class);
        //注册WebServiceProvider
        $this->app->register(WebServiceProvider::class);
        //注册导出excel
        $this->app->register(ExcelDataProvider::class);
        //注册FormProvider
        $this->app->register(FormServiceProvider::class);
        //注册广告Provider
        $this->app->register(AdServiceProvider::class);
    }

    /**
     * 注册组件
     */
    protected function registerComponent(){
        //广告
        Blade::component('ad-list', AdInfo::class);

        //表单
        Blade::component('form-info', FormInfo::class);

        //帮助列表
        Blade::component('help-list', HelpList::class);
        Blade::component('product-list', ProductList::class);
        Blade::component('product-list-by-ids', ProductListByIds::class);
        //会议列表
        Blade::component('meeting-list', MeetingList::class);
        Blade::component('meeting-info', MeetingInfo::class);
        Blade::component('meeting-global-list', MeetingGlobalList::class);

        //文本内容列表
        Blade::component('website-page-content', PageContent::class);

        // 文章板块组件
        Blade::component('blog-knowledge-centre', KnowledgeCentre::class);//知识中心
        Blade::component('blog-news-info', NewsInfo::class);//资讯详情
        Blade::component('blog-news-list', NewsList::class);//资讯列表
        Blade::component('blog-type-list', TypeList::class);//文章分类列表
        Blade::component('blog-partners', Partners::class);//合作伙伴
        Blade::component('blog-questions-and-answers', QuestionsAndAnswers::class);//问答
        Blade::component('blog-success-case-list', SuccessCaseList::class);//成功案例列表
        Blade::component('blog-solution-list', SolutionList::class);//解决方案列表
        Blade::component('blog-video-list', VideoList::class);//视频列表
        Blade::component('blog-recent-news-list', RecentNewsList::class);//最近资讯列表
        Blade::component('blog-plate-type-tag', BlogPlateTypeTag::class);//获取文章分类和标签

    }
}
