[Lumen5.2 documentation] more features-events

Source: Internet
Author: User
[Lumen5.2 documentation] more features-events 1. Introduction

Lumen events provide simple observer mode implementation, allowing you to subscribe to and listen to events in the application. The event class is usually stored in the app/Events directory, and the listener is stored in app/Listeners.

2. differences with Laravel

Generally, the event functions in Lumen are almost the same as those in Laravel. for details about how to use the functions, see the Laravel event documentation. Lumen also supports event broadcast, allowing you to listen to server-side events in client JavaScript. It should be noted that there is a difference between Lumen and Laravel events.

Generator

In Lumen, the Artisan command for generating events and listener classes is not provided, so you need to copy ExampleEvent or ExampleListener to customize the event class and listener class.

Register event/listener

Like the Laravel framework, the Lumen built-in EventServiceProvider is used to register all event listeners. The listen attribute is an array containing all events (keys) and their corresponding listener (values). you can add all events of the application to this array:

/*** The event listener mappings for the application. ** @ var array */protected $ listen = ['app \ Events \ exampleevent' => ['app \ Listeners \ ExampleListener ',],];

Trigger Event

You can use the helper function event or Event facade in the application to trigger events. these methods are called like Laravel:

Event (new ExampleEvent); Event: fire (new ExampleEvent );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.