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

Robert Basic:
Events in a Zend Expressive application
Aug 05, 2016 @ 09:40:47

Robert Basic has written up a new post sharing a method he came up with for event handling in a Zend Expressive application. He makes use of Zend's own EventManager component to integrate it with some of his work from a previous post.

Three weeks ago I wrote a post on how to utilize Tactician in a Zend Expressive application. Today I want to expand on that post a little by adding the possibility to trigger and listen to events using the Zend EventManager component.

Using events allows our application to respond to different events that occur during a request.[...] This allows for a better separation of concerns in some cases, because if we take this approach, our code that deals with [the current functionality] doesn’t care any more what happens after that

He then gets into the code, showing how to install the EventManager component and how to create/inject an event manager into a current object (a Command). He then shows how to attach en event to the handler and perform an action when the event is hit. He points out one issue with this kind of setup, however: the need for all dependencies to be created prior to the event being attached. Fortunately the Zend EventManager comes with DI container support making it simpler to access dependencies needed during the firing of the event.

tagged: zendexpressive framework application event eventmanager tutorial overview introduction

Link: https://robertbasic.com/blog/events-in-a-zend-expressive-application/

Loïc Faugeron:
Mars Rover, Event Sourcing code
Aug 03, 2016 @ 10:39:52

Loïc Faugeron has continued his series developing the code for a "Mars Lander" coding exercise with this latest post sharing the actual code for the event sourcing functionality started in the previous tutorial.

In this series we're building the software of a Mars Rover, according to the following specifications. It will allow us to practice the followings: Monolithic Repositories (MonoRepo), Command / Query Responsibility Segregation (CQRS), Event Sourcing (ES) and Test Driven Development (TDD). Up until now, we've implemented the first use case, "Landing a rover on Mars".

We've also created an event-sourcing package with the following interfaces: Event, AnEventHappened and EventStore. In this article, we're going to implement them.

He then starts in using phpspec to generate the Event class for him and gives it a basic structure. He fleshes this out with a bit of functionality (to make the tests pass) and moves on to the "AnEventHappened" class. He generates the class in the same way as before and adds a "just now" method to return the event that "just happened". The last class, the "EventStore" could do different things depending on the storage method, so he's delaying that for now and will implement it later.

tagged: mars rover tutorial series event sourcing phpspec

Link: https://gnugat.github.io/2016/08/03/mars-rover-event-sourcing-code.html

PHP Roundtable:
049: Event Sourcing in PHP
Aug 01, 2016 @ 10:49:11

The PHP Roundtable podcast, hosted by Sammy Powers, has posted their latest episode today featuring guests Beau Simensen, Ross Tuck, Shawn McCool and Willem-Jan Zijderveld talking about event sourcing.

We spend much of our time as developers managing the state in our applications. There are many different approaches and philosophies attributed to reading, mutating and storing state.

The Event Sourcing pattern is an approach to managing application state. If we think of any given state of our app as a frame in a video, Event Sourcing allows us to scrub through past states of the app. Today we discuss what Event Sourcing is and how we can start integrating it into our PHP apps.

You can watch this latest episode either through the in-page video player or directly on YouTube. If you enjoy the show, be sure to subscribe to their feed and follow them on Twitter for the latest on when future shows are being recorded and released.

tagged: phproundtable podcast video ep49 event sourcing

Link: https://www.phproundtable.com/episode/event-sourcing-in-php

Loïc Faugeron:
Mars Rover, Event Sourcing package
Jul 27, 2016 @ 11:51:05

Loïc Faugeron has continued his "Mars Rover" series in his latest post today. This series, based on a set of specifications from a development challenge. In this latest post he continues looking at event sourcing and creates a package to handle the eventing to make it more flexible and robust.

In this series we're building the software of a Mars Rover, according to the following specifications. It will allow us to practice the followings: Monolithic Repositories (MonoRepo), Command / Query Responsibility Segregation (CQRS), Event Sourcing (ES) Test Driven Development (TDD).

Up until now, we've implemented the first use case, "Landing a rover on Mars" [and] in the last article, we wrote some Event Sourcing code. [...] In this article, we're going to extract them from the navigation package and put them in their own event-sourcing package.

He starts by creating the package itself as a Composer package including the composer.json configuration and a few other files to have phpspec work correctly. He then adds the event-sourcing package to the main project and starts in on using phpspec to generate its basic files. He then updates the main Lander class to use this new package for events. There's no code in the eventing classes yet, but stay tuned for the next tutorial in the series that will update them and get it all working together.

tagged: mars rover tutorial series landing event sourcing package phpspec

Link: https://gnugat.github.io/2016/07/27/mars-rover-event-sourcing-package.html

Loïc Faugeron:
Mars Rover, Landing event
Jul 20, 2016 @ 09:33:05

Loïc Faugeron has posted the latest tutorial in his series about developing a "Mars Rover" script using various design patterns and principles. In this latest part of the series he looks at handling the "landing event" of the rover.

In this series we're going to build the software of a Mars Rover, according to the following specifications. [...] Previously we've created a navigation package, and in it a LandRover class that validates input parameters for our first use case. [...] We've then refactored it to extract coordinates and orientation in their own classes.

In this article we're going to create the actual landing logic, using Event Sourcing

He then starts in, creating the tests first because of TDD, on the LandRoverHandler to integrate a command architecture (using the Command Bus pattern). He then sets up the structure for the event sourcing and an basic event for the landing of the rover. This includes the handler for the event, the event itself and the storage method for capturing that the event happened. He fills in the generated classes with a bit of logic and a few updates to the test for the new structure.

tagged: mars rover tutorial series landing event sourcing orientation phpspec

Link: https://gnugat.github.io/2016/07/20/mars-rover-landing-event.html

SitePoint PHP Blog:
Powering Raspberry Pi Projects with PHP
Jul 13, 2016 @ 12:20:52

The SitePoint PHP blog has posted a tutorial from author Andrew Carter showing you how you can use the Raspberry Pi hardware to power a PHP-based application with a bit of simple setup.

A Raspberry Pi is a brilliant tiny computer that you can power off of a micro USB cable. The most recent model has WiFi, an ethernet port, 4 USB ports and an HDMI port. There’s also a micro SD card slot, which is where the “hard drive” goes.

It’s capable of running Raspbian Linux, which is a Debian based Linux distribution. This makes it familiar to Ubuntu users who can then just sudo apt-get install all the things. Like with any Linux machine, you can install PHP on it and make a website – but we can do so much more than that!

He starts with the equipment you'll need to follow along with the tutorial - a recent Raspberry Pi model with wifi and a bit of other electronics equipment (he also recommends a starter kit for those new to this hardware world). Once the Pi is set up, he then installs PHP via an apt-get package install along with the PiPHP: GPIO library that makes working with the input/output simpler via PHP. He then shows the wiring you'll need to do to get a LED and button connected. A simple script is included that sets up a watcher on the button input and, when the "push" event is fired, it blinks the LED five times.

He finishes the post with a look at some of his own testing and preparation for a talk on this same subject with some slightly humorous results.

tagged: raspberrypi project tutorial piphp gpio hardware led button listener event

Link: https://www.sitepoint.com/powering-raspberry-pi-projects-with-php/

SitePoint PHP Blog:
PHP, Arduino, And… Minecraft? Connecting an Arduino to PHP!
Jul 12, 2016 @ 10:39:38

The SitePoint PHP blog has continued their series looking at connecting the real world with the online world via Minecraft and an Arduino. In this new post author Christopher Pitt picks up where he left off in part one and brings the Arduino in to the picture.

In the first part of this series, we learned a bit of Minecraft and the circuitry we can make inside it. We also made a circuit to alert us when the door to our mansion was opened. We then hooked this virtual alarm to a listening PHP script, so we can know when the door is opened in the context of a PHP script.

In this part, we’ll build a small Arduino-based alarm circuit. We’ll learn how to trigger the alarm, using the the official IDE and programming language, and then using something called Firmata. We’ll round the series out by connecting the alarm circuit to the Minecraft circuit, so we hear a real alarm for Minecraft mansion.

He takes some time at the beginning of the post introducing the Arduino hardware and what they have to offer. He lists the parts you'll need for this setup to work and how they need to be set up. He then gets into the code for the Ardunio side and how to get it over to the board. He presents another option to the potentially painful change-reupload cycle of debugging Arduino code: using the PHP "carica/firmata" library to connect to and add listeners to hook into the board. He uses this to then set up a PHP script to watch for changes in the Minecraft log files and fire an event to the waiting Arduino board.

The final item in this part of the tutorial series talks about bringing in the "Gorilla" extension for Carica Firmata to help prevent issues with too fast connections to the board interrupting the boot sequence.

tagged: tutorial series part2 minecraft arduino alarm connecting event loop

Link: https://www.sitepoint.com/php-arduino-and-minecraft-connecting-an-arduino-to-php/

Symfony Blog:
Announcing the Fourth Symfony Docs Hack Day
May 13, 2016 @ 09:58:29

On the Symfony Blog they've posted the official announcement of their Fourth Symfony Docs Hack Day happening on May 21st. This hack day is focused on just improving the documentation for the framework, not handling bugs in the main codebase itself.

The Symfony project is proud to announce its fourth Symfony Docs Hack Day. This Hack Day will be an online event to give a push to the Symfony Docs before the Symfony 3.1 release at the end of this month.

[...] Hosts Ryan Weaver, Wouter de Jong and Christian Flothmann along with you and all your friends from the Symfony community. The Hack Day is for everyone - we need Symfony experts and newcomers. If you're new to Symfony, you give us a fresh look at the documentation!

The post gives you a bit of an idea what the event will be like and what you can expect, especially as a first time submitter. It will be happening completely online via the "#symfony-docs" channel on the Freenode IRC network. You can prepare by following some of the links in the post to pending pull requests and a list of missing documentation contents.

tagged: symfony hackday documentation update event irc freenode framework

Link: http://symfony.com/blog/announcing-the-fourth-symfony-docs-hack-day

Joshua Thijssen:
My guide to commenting on joind.in
Dec 21, 2015 @ 10:44:16

If you've been to any PHP conference (or attended a PHP-related online event) in recent years, you probably have heard of the speaker/event feedback site Joind.in. The concept is simple: when you attend a talk or event you go to the site, give the speaker a star rating and leave them comments. This gives the speakers direct feedback on how they did and where they can improve. There's a a trick to giving valuable feedback, though, and Joshua Thijssen has posted some helpful tips to guide you and your comments in the right direction.

The joind.in website can be considered a presenter’s portfolio: it contains a list of talks they have done in the past (and where), plus it contains reviews from attendees. [...] This is why many conferences and presenters will talk about joind.in and ask you to rate and comments on their talks: it gives them feedback on how you experienced the talk, what can be improved to make it even better, and gives the presenters more chance to get accepted on even the larger conferences, where sometimes there are only 50 slots, but over 500 people submitted talks).

[...] Even though commenting and rating talks by itself isn’t really difficult and is quick to do so, there are some common “mistakes” and pitfalls which I’d like to discuss.

He breaks it down into five main points, elaborating on each as he goes through them:

  1. Stars don’t tell you everything
  2. Rate the presentation and speaker, not your expectations.
  3. Don’t punish the presenter for external faults
  4. Comment anonymously
  5. Give suggestions on how to improve

For each one he also gives examples of good feedback versus comments that aren't as helpful to the speaker. Each one of these is an easy trap to slip in to, so remember them next time you're giving a speaker feedback (even if it's not on Joind.in!).

tagged: speaker feedback useful commenting joindin event conference guide

Link: https://adayinthelifeof.nl/2015/12/17/commenting-on-joindin.html

Hart KT:
Custom Events in Symfony2 Bundle
Oct 12, 2015 @ 11:10:58

Hari KT has a quick tutorial posted to his site showing you how to use custom events in Symfony bundles from start to finish.

In this tutorial we will create a custom event for symfony2 bundle. Assuming you have downloaded the symfony-standard distribution to play.

He starts by creating a simple bundle (HktEventBundle) and building out the matching event class, extending the base Symfony EventDispatcherEvent. He then shows how to dispatch a simple event from a controller, triggering a html.event.page_viewed event when the request is made to this default controller. He matches this with a listener that subscribes to the event (including a handler method) and the changes you'll need to make to your configuration to wire them all together.

tagged: symfony2 bundle custom event simple tutorial introduction

Link: http://harikt.com/blog/2015/10/11/custom-events-in-symfony2-bundle/