Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

TutsPlus.com:
How to Use the Symfony Event Dispatcher for PHP
Oct 29, 2018 @ 18:40:03

The TutsPlus.com site has posted another tutorial where they go in-depth with one of the components of the Symfony framework. In this new tutorial they cover the Symfony Event Dispatcher component including its basic use via events and subscribers.

Today, we're going to learn how to use the Symfony event dispatcher component, which allows you to create events and listeners in your PHP applications. Thus, different components of your application can talk to each other with loosely coupled code.

[...] The event dispatcher component provides three elements that you could build your app architecture around: event, listener, and dispatcher. The whole system is orchestrated by the dispatcher class, which raises events at appropriate points in an application and calls listeners associated with those events.

The tutorial starts with the command you'll need to get the dispatcher installed and examples of:

  • creating events
  • dispatching the events to subscribers
  • listening for the events

The tutorial then covers subscribers, reusable listeners that can be added to the list for handling when an event fires. Code examples are included for all topics.

tagged: symfony event dispatcher component tutorial introduction

Link: https://code.tutsplus.com/tutorials/handling-events-in-your-php-applications-using-the-symfony-eventdispatcher-component--cms-31328

TutsPlus.com:
How Laravel Broadcasting Works
May 07, 2018 @ 16:41:41

The TutsPlus.com site has a new tutorial posted for the Laravel users out there ]introducing you to the framework's broadcast functionality](https://code.tutsplus.com/tutorials/how-laravel-broadcasting-works--cms-30500). Broadcasting in Laravel provides a simple interface to sending notification (such as emails or even real-time push messages) via a standardized interface.

Today, we are going to explore the concept of broadcasting in the Laravel web framework. It allows you to send notifications to the client side when something happens on the server side. In this article, we are going to use the third-party Pusher library to send notifications to the client side.

If you have ever wanted to send notifications from the server to the client when something happens on a server in Laravel, you're looking for the broadcasting feature.

The article walks through the scenario first and covers the basic flow of websockets and how they'd be used for messaging. From there they start in on the code, looking at the broadcast configuration and walking you through the setup of a Pusher account and the installation of the SDK. They help you configure the Laravel application for Pusher and install the Laravel Echo library for handling the messaging on the frontend. The tutorial goes through the code to create a "messages" table and hook in a "broadcast on" event. This is followed by the frontend setup including the Javascript to create the Pusher instance.

tagged: laravel broadcast pusher tutorial event websocket

Link: https://code.tutsplus.com/tutorials/how-laravel-broadcasting-works--cms-30500

Junior Grossi:
Solitary or Sociable? Testing Events and Listeners using Laravel
Apr 30, 2018 @ 14:38:58

In a new post to his site Junior Grossi covers two main methods for testing event handling in Laravel-based applications: either solitary or sociable.

Testing with Laravel is very easy, but it can be a nightmare when the tests depend on Events and Listeners. In this post I’m gonna show you how you can simplify and improve those tests.

[...] When testing events in Laravel, you can fake() events in a very simple way, like the documentation says. The problem is not with the events, but with the listeners, because usually a listener does a single action, but with more than one listener you start writing repeatable tests.

He starts by looking at some of the background behind the ideas of "solitary" and "sociable" as it relates to events. He then gets into the code, providing some examples of event tests (and how it could evolve into larger, unwieldy tests). He provides some recommendations on refactoring tests to help get around these issues. As a bonus at the end of the post he shows how to create sociable tests, complete with example code.

tagged: testing event handling laravel tutorial solitary sociable

Link: https://blog.jgrossi.com/2018/solitary-or-sociable-testing-events-and-listeners-using-laravel/

Laravel News Podcast:
Episode 59 - Scaling Laravel, testing Vue components, and model events
Mar 22, 2018 @ 15:57:39

The Laravel News podcast, hosted by Jacob Bennett and Michael Dyrynda, has posted their latest episode - Episode #59: Scaling Laravel, testing Vue components, and model events

Join Jake and Michael as they discuss the latest Laravel releases, Scaling Laravel, testing Vue components, and more.

Other topics mentioned include the announcement about Let's Encrypt wildcard certificates and how to use Font Awesome 5 SVGs with Laravel Blade. You can listen to this latest show either using the in-page audio player or by downloading the mp3 directly. If you enjoy the show and want to hear more, check out their archives at the bottom of the page and subscribe to their feed for updates on new shows as they're released.

tagged: laravelnews podcast ep59 scaling vue testing model event

Link: https://laravel-news.com/podcast/59

Laravel News:
Getting Started with Laravel Model Events
Mar 16, 2018 @ 14:47:09

The Laravel News site has a tutorial posted that introduces you to model events in Eloquent models and how to use them effectively in your code.

Laravel Model events allow you to tap into various points in a model’s lifecycle, and can even prevent a save or delete from happening. The Laravel model events documentation outlines how you can hook into these events with event classes, but this article aims to build upon and fill in a few additional details on setting up events and listeners.

The article starts with an overview of the different types of events available on the models and a brief summary of when each are fired. It then walks you through the process of registering events and where to configure the event-to-handler relationship. The artisan make:event command can then generate the skeleton code for you. In this class you can then add the handler method and then configure it in the providers. Finally it shows an example of how to test the event, stopping the save event and using observers to group the event handling.

tagged: laravel eloquent model event tutorial introduction

Link: https://laravel-news.com/laravel-model-events-getting-started

Sergey Zhuk:
Building ReactPHP Memached Client: Emitting Events
Nov 03, 2017 @ 14:44:39

Sergey Zhuk has posted the third part of his series covering the creation of a Memcached client using ReactPHP has the base and allowing for asynchronous operations. In this latest part of the series (part three) he focuses on emitting events for various actions/results in the client code.

In the previous article, we have faced with a problem: how to deal with a broken connection. Now, when the connection is closed all pending requests are rejected with the ConnectionClosedException. If we want to handle this situation we need to attach onRejected handlers to all promises because we can’t guess in advance which one will be the problem.

This [example] code already looks too complex, but also there is no way to find out if the connection was broken or we have manually close it. So, it becomes clear that we need a completely different approach.

He then shows how to make use of this event library to emit events at certain points in the client's state. He includes code examples showing how to use the emit method to throw the event focusing on handling when there's connection issues.

tagged: reactphp memcached client async emit event connection handling series part3

Link: http://sergeyzhuk.me/2017/11/03/memcached-reactphp-p3/

Herberto Graca:
Event-Driven Architecture
Oct 10, 2017 @ 15:28:19

In this new post to his site Herberto Graca has posted the latest part of his "The Software Architecture Chronicles* series, focusing this time on event-driven architectures.

This post is part of The Software Architecture Chronicles, a series of posts about Software Architecture. In them, I write about what I’ve learned on Software Architecture, how I think of it, and how I use that knowledge. The contents of this post might make more sense if you read the previous posts in this series.

Using events to design applications is a practice that seems to be around since the late 1980s. We can use events anywhere in the frontend or backend. When a button is pressed, when some data changes or some backend action is performed.

But what is it exactly? When should we use it and how? What are the downsides?

He starts by talking about the "what", "when" and "why" of using events to drive the architecture of the system, going into each of the topics in a bit more depth:

  • To decouple components
  • To perform async tasks
  • To keep track of state changes (audit log)

He then goes on to talk about common patterns for event-driven applications including event notification, event-carried state transfer and event sourcing.

tagged: event architecture software decouple async state notification sourcing

Link: https://herbertograca.com/2017/10/05/event-driven-architecture/

Freek Van der Herten:
Handling Stripe webhooks in a Laravel application
Oct 09, 2017 @ 15:33:06

Freek Van der Herten has a new post to his site showing you how to handle Stripe callbacks when integrating its webhook functionality into your application. True to form, he also created a Laravel package to make it even easier.

In the project I’m currently working on I had to integrate Stripe webhooks. Stripe has great documentation on how to handle webhooks, but it still took a fair amount of time to get the integration just right. My solution for handling webhooks is pretty generic and reusable by others. I decided to extract it to a package called laravel-stripe-webhooks, so nobody has to code this stuff up again. In this blogpost I’d like to share how the package works.

He then goes on to talk about the request validation that happens on the webhook callback and how the information can be reworked if something goes wrong. He then talks about the handling of valid requests either using a custom job or using events to trigger when a "source.chargable" event is fired.

tagged: stripe laravel package webhook tutorial event job

Link: https://murze.be/2017/10/handling-stripe-webhooks-laravel-application/

Nexmo Blog:
Laracon 2017 New York City – Conference report
Aug 23, 2017 @ 15:47:32

If you weren't able to make it to this year's Laracon US conference, the Nexmo blog has shared a summary of the event including some of their own highlights.

I recently attended Laracon in New York City for the 4th year in a row. This year the conference was held at New World Stages in Hell’s Kitchen, with 500 people in attendance (and a waiting list of over 1000!) making it the biggest one yet.

While the conference focuses on the Laravel PHP framework, the talks were diverse and covered topics like database segregation for multi-tenant applications, aesthetic and design tips for developers, advice on growing and scaling a side project into a business, and the importance of deep-focus work.

The author focuses on four of the talks that she found most useful:

  • "CRUDDY by Design" from Adam Wathan
  • "Custom Laravel" by Matt Stauffer
  • "Slay the Beast" from Jeffrey Way

The final talk was actually a keynote from Taylor Otwell himself covering the major changes that are coming in the 5.5 version of the framework including the Laravel Horizon queue management package. Each section comes with details of the session and links to other sources for more information.

tagged: laraconus17 conference wrapup summary event community laravel

Link: https://www.nexmo.com/blog/2017/08/15/laracon-2017-nyc-conference-report-dr/

PHP Roundtable:
065: TestFest 2017
Aug 01, 2017 @ 17:19:09

The PHP Roundtable podcast, hosted by PHP community member Sammy Powers, has posted their latest episode - Episode 065: TestFest 2017 with guests Ben Ramsey, Rafael Dohms, Zoe Slattery and Cal Evans.

Adding tests to php-src is a great way to get involved with PHP internals. Don't know how to get started? You're in luck. TestFest 2017 is going to be a thing in September. User groups and individuals around the world are going to organize to learn how to add tests to PHP and become official internals contributors.

It has been 7 years since the last TestFest in 2010. We chat about how to get involved with TestFest 2017.

You can catch this latest episode either using the in-page audio or video player or by watching it directly on YouTube. If you enjoy the episode consider subscribing to their feed and following them on Twitter to get the latest updates when new shows are released.

tagged: phproundtable podcast ep65 testfest2017 testing event core language

Link: https://www.phproundtable.com/episode/php-test-fest-2017


Trending Topics: