<?php

namespace App\Providers;

use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
use Illuminate\Database\Events\StatementPrepared;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        'Illuminate\Database\Events\QueryExecuted' => [
            'App\Listeners\QueryListener',
        ],

        'App\Events\ExternalAndFollowOperateEvent' => [
            'App\Listeners\ExternalAndFollowOperateListener',
        ],

        'App\Events\ExternalAndGroupOperateEvent' => [
            'App\Listeners\ExternalAndGroupOperateListener',
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
        // 使数据库查询返回的数据就是单纯的数组形式。
        Event::listen(StatementPrepared::class, function ($event) {
            // 仅支持数据库方式，不支持模型方式
            $event->statement->setFetchMode(\PDO::FETCH_ASSOC);
        });
    }
}
