事件监听

  1. <?php
  2. use Hyperf\Contract\StdoutLoggerInterface;
  3. use Hyperf\Framework\Event\BootApplication;
  4. use Hyperf\Nano\Factory\AppFactory;
  5. require_once __DIR__ . '/vendor/autoload.php';
  6. $app = AppFactory::create();
  7. $app->addListener(BootApplication::class, function($event){
  8. $this->get(StdoutLoggerInterface::class)->info('App started');
  9. });
  10. $app->run();