DemoBase.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Link : http://www.phpcorner.net
  4. * User : qingbing<780042175@qq.com>
  5. * Date : 2018-12-07
  6. * Version : 1.0
  7. */
  8. namespace TestClass;
  9. use Abstracts\Base;
  10. use Helper\Event;
  11. class DemoBase extends Base
  12. {
  13. public $age;
  14. private $_name;
  15. private $_sex;
  16. /**
  17. * @return string
  18. */
  19. public function getName()
  20. {
  21. return $this->_name;
  22. }
  23. /**
  24. * @param string $name
  25. */
  26. public function setName($name)
  27. {
  28. $this->_name = $name;
  29. }
  30. /**
  31. * @return mixed
  32. */
  33. public function getSex()
  34. {
  35. return $this->_sex;
  36. }
  37. /**
  38. * @param mixed $sex
  39. */
  40. public function setSex($sex)
  41. {
  42. $this->_sex = $sex;
  43. }
  44. /**
  45. * @throws \Helper\Exception
  46. */
  47. public function login()
  48. {
  49. if ($this->hasEventHandler('beforeLogin')) {
  50. $this->onBeforeLogin(new Event($this));
  51. }
  52. var_dump('login');
  53. if ($this->hasEventHandler('afterLogin')) {
  54. $this->onAfterLogin(new Event($this, ['name' => 'qingbing']));
  55. }
  56. }
  57. /**
  58. * 调用及触发 beforeLogin 事件
  59. * @param Event $event
  60. * @throws \Helper\Exception
  61. */
  62. public function onBeforeLogin($event)
  63. {
  64. $this->raiseEvent('beforeLogin', $event);
  65. }
  66. /**
  67. * 调用及触发 afterLogin 事件
  68. * @param Event $event
  69. * @throws \Helper\Exception
  70. */
  71. public function onAfterLogin($event)
  72. {
  73. $this->raiseEvent('afterLogin', $event);
  74. }
  75. }