<?php
/**
 * Link         :   http://www.phpcorner.net
 * User         :   qingbing<780042175@qq.com>
 * Date         :   2018-12-07
 * Version      :   1.0
 */

namespace TestClass;

use Abstracts\Base;
use Helper\Event;

class DemoBase extends Base
{
    public $age;
    private $_name;
    private $_sex;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->_name;
    }

    /**
     * @param string $name
     */
    public function setName($name)
    {
        $this->_name = $name;
    }

    /**
     * @return mixed
     */
    public function getSex()
    {
        return $this->_sex;
    }

    /**
     * @param mixed $sex
     */
    public function setSex($sex)
    {
        $this->_sex = $sex;
    }

    /**
     * @throws \Helper\Exception
     */
    public function login()
    {
        if ($this->hasEventHandler('beforeLogin')) {
            $this->onBeforeLogin(new Event($this));
        }
        var_dump('login');
        if ($this->hasEventHandler('afterLogin')) {
            $this->onAfterLogin(new Event($this, ['name' => 'qingbing']));
        }
    }

    /**
     * 调用及触发 beforeLogin 事件
     * @param Event $event
     * @throws \Helper\Exception
     */
    public function onBeforeLogin($event)
    {
        $this->raiseEvent('beforeLogin', $event);
    }

    /**
     * 调用及触发 afterLogin 事件
     * @param Event $event
     * @throws \Helper\Exception
     */
    public function onAfterLogin($event)
    {
        $this->raiseEvent('afterLogin', $event);
    }
}