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

Matthias Noback:
Exceptions and talking back to the user
Apr 10, 2018 @ 14:13:25

Matthias Noback has a new post to his site with some suggestions about exception handling and user feedback for both the backend experience and UI side.

Designing domain objects is all about offering meaningful behavior and insights through a carefully designed API. [...] So exceptions in your (object-oriented) domain model are not merely meant to signal an exceptional situation. They can be used to prevent invalid or unsupported usage of an object. By offering well-named methods (with sensible parameters) for changing the object's state, and by being very precise about throwing exceptions when invalid use is imminent, you make your domain objects usable in only one way: the way that makes sense. This is the exact opposite of how your domain objects end up looking if you generate getters and setters for every attribute.

He starts by looking at the use of exceptions to help with validation and a few ways they could be used:

  • Exceptions get thrown ad hoc, whenever something threatens the consistency of the domain object.
  • They often signal that something is about to happen that can't logically happen, like a state change that isn't allowed or conceptually possible.
  • Exception messages may contain more information than you'd like to share with the user.
  • Validation errors often require internationalization (i18n).

He explains each option and, where it helps, provides code examples to illustrate. He then moves on to the frontend, talking about changes to the UI when exceptions are thrown and some things on his "wish list" for frontend exception handling.

tagged: exception user messaging handling opinion tutorial

Link: https://matthiasnoback.nl/2018/04/exceptions-and-talking-back-to-the-user/

Matt Stauffer:
Laravel Collections’ higher order messaging and “when” method in Laravel 5.4
Aug 18, 2017 @ 15:31:19

In this new post to his site Matt Stauffer looks at the "higher order messaging" in Laravel's collections as a part of his series covering features in Laravel 5.4.

It seems like it was just last year that collection pipelines took over the Laravel world. Taylor had introduced collections to Laravel a while back but they sat somewhat under-appreciated until Adam Wathan wrote his book Refactoring to Collections about how they can transform the way you write a lot of your PHP code.

In Laravel 5.4, collections got a few boosts. Let’s take a look at a few.

He starts by talking about the higher order messaging design pattern and how it is different than just using something like foreach to iterate through a set. He then applies this to the Laravel collections, showing how they're implemented there via the "filter" and "pipe" methods.

tagged: collection higher order when messaging tutorial laravel54

Link: https://mattstauffer.co/blog/laravel-collections-higher-order-messaging-and-when-method-in-laravel-5-4

BitExpert Blog:
Mattermost Webhooks and PHP
Jul 19, 2017 @ 15:49:26

On the BitExpert blog Stephan Hochdörfer shares his experience working with Mattermost webhooks and interfacing them with backend PHP scripts. Mattermost is an Open Source Slack clone.

In a recent attempt to automate a few things even more, I was looking for a way to post messages to our [Mattermost](http://mattermost.org/) instance via the [Incoming Webhook](https://docs.mattermost.com/developer/webhooks-incoming.html) feature of Mattermost. I did a quick search on [Packagist](https://packagist.org/search/?q=mattermost) for Mattermost client libraries and as it turns out there a quite a few. I picked the [thibaud-dauce/mattermost-php](https://packagist.org/packages/thibaud-dauce/mattermost-php) package simply because it was the first match.

He then walks through the installation of the package and how it works, using Guzzle, to send messages to the Mattermost service. The incoming request is just a JSON-formatted data set, so it's easily parsed in plain PHP. The output, however, needs to be in a format Mattermost understands. That's where the package comes in, providing a "send" method that allows for the customized text and optional attachment to be sent to the Mattermost server.

tagged: mattermost package webhook messaging message tutorial

Link: https://blog.bitexpert.de/blog/mattermost-webhooks-and-php/

Laravel News:
Echo is coming to Laravel 5.3
May 13, 2016 @ 16:07:09

On the Laravel News site there's a post talking about a feature coming in the 5.3 version of the Laravel framework - Laravel Echo (not a separate system, just an enhancement inside the framework).

Laravel Echo is coming to Laravel 5.3 and is designed to be an improvement over the current event broadcasting system. [...] In this video, Taylor steps through the features by demoing a little to do app. You can see the full source code to the demo on GitHub.

Echo is essentially an improvement on the in-application messaging to provide more real-time feedback between users in the system. In his demo, he makes use of the Vue.js framework heavily and custom broadcasters and Pusher.

tagged: laravel echo realtime messaging

Link: https://laravel-news.com/2016/05/echo-coming-laravel-5-3/

Madewithlove Blog:
Thread carefully
Nov 16, 2015 @ 17:55:58

In a post to the Madewithlove blog Maxime Fabre takes a look at threading in PHP using the pthreads support that can be included into your PHP installation.

As far as I can remember, PHP has always had a terrible reputation at handling very heavy (or asynchronous) tasks. [...] But PHP can do threading, and more importantly it's a lot easier than you probably think.

[...] In this article I'm going to dive into the pthreads extension (short for POSIX Threads). It has been around for a while (since 2012) but I feel like too many people forget it exists or assume it is going to be painful to use – mostly because the official documentation is rather slim about it.

They start by getting the pthreads support installed locally (it assumes you use OS X and the "brew" package manager but it can be installed manually too). The article starts off by defining some basic nomenclature from the pthreads world and gives a diagram of how it all fits together. From there it gets into some examples, showing a simple thread class to fetch Google results and how to fire off multiple instances at the same time. They then extend this even further and look at the concept of "workers" and using them to manage individual jobs. It then moves up the next level and looks at "pools" of workers and processing multiple workers at the same time.

There's also a section dealing with one "gotcha" that can happen with class inheritance between parent and child threads. They show how to work around this with a custom Worker class that performs the autoloading for you and is executed at the start of a Pool. Finally they cover the messaging between the child threads and, as a bonus, how threading could be used in a command bus setup.

tagged: threading tutorial pthreads example worker thread pool process commandbus messaging

Link: http://blog.madewithlove.be/post/thread-carefully/

NetTuts.com:
Creating a Dating Application with Sinch: RESTful API
Apr 27, 2015 @ 15:19:26

NetTuts.com has kicked off a new tutorial series today about building a dating application with a combination of Laravel, MongoDB and the Sinch service allowing for messaging between users. The Sinch service has several features including voice/messaging/SMS communication methods and device verification.

In this tutorial, we're going to create a dating application for iOS similar to Tinder. For voice and messaging, we will leverage the Sinch platform, making use of its powerful SDK. In the first part, we will focus on the development of a RESTful API to store and retrieve user information. In the second part, the iOS client will hook into this API to find nearby users based on the user's current location. We will use Laravel 5.0 for the RESTful service and will be covering basic concepts, such as routes and controllers. We are also going to define custom models to support MongoDB integration in an ActiveRecord-like manner.

This first part of the series is mostly about just getting things set up so they walk you through:

  • Basic setup of the Laravel application
  • Creation of the Base model (for MongoDB connection)
  • Creating helper methods
  • Building out CRUD functionality for the database layer
  • Making a User model
  • Creating the BaseController class
  • Making a SessionController class (and working with sessions)
  • Building a UserController

They end this part of the series by hooking all of this functionality together with some simple RESTful routing for GET, POST, PUT and DELETE request handling for the various endpoints.

tagged: tutorial series laravel sinch messaging rest api framework part1

Link: http://code.tutsplus.com/tutorials/creating-a-dating-application-with-sinch-restful-api--cms-23709

Coder on Code:
Design Patterns in PHP: Adapters
Jan 26, 2015 @ 16:46:42

The Coder on Code site has posted a new tutorial covering the Adapter design pattern in detail. They talk about what the pattern is, what it can be useful for and include some code to illustrate.

The adapter pattern also referred as the wrapper pattern, I find that wrapper is a more fitting name since it describes clearly what this pattern does; it encapsulates the functionality of a class or object into a class with a common public interfaces. [...] Adapters are one of the easiest patterns to comprehend and at the same time one of the most useful ones.

He starts with some of the basic definitions of terms involved in the pattern: client, adapter and adapteee. His example centers around a notification manager class that lets you switch types between Twitter, Email and SMS messaging. His initial code has all of the message types handled in one class method. He shows how to refactor this out to an interface and a set of child classes, each with the corresponding handling in a "sendNotification" method. These are then used by an adapter in the main class to send the given message. This simplifies the main messenger class and contributes to the overall improvement of architecture and testability of the application.

tagged: designpattern adapter example introduction client adapter adaptee messaging tutorial

Link: http://coderoncode.com/2015/01/25/design-patterns-in-php-adapters.html

Twilio Blog:
How to Build an MMS Ticketing System Using PHP, Laravel and Twilio
Oct 03, 2014 @ 17:18:54

On the Twilio blog there's a recent post showing the construction of some fundamental parts of a MMS ticketing system using Laravel and Twilio for the messaging.

Have you ever arrived at a movie, flight or concert and realized you’ve forgotten your paper ticket? Imagine how much worse it would be if you showed up at Willy Wonka’s front door, but forgot your golden ticket! To prevent an epic disaster such as this, we’re going to build an app that delivers Willy Wonka’s golden ticket directly to your phone using MMS. All the Oompa Loompas have to do is scan it. Not Willy Wonka? Don’t worry, this code should be useful for any app or company that distributes tickets. Hopefully computers are more helpful with the golden ticket than last time.

The application makes use of a few libraries outside of the Laravel framework structure to handle the various functional pieces: one for creating QR codes and another for sending the messages via Twilio. They walk through some of the basic setup for the first endpoint and the "Golden Ticket Distribution" page. He then uses the Endroid QR code library to generate a code based on a string and outputting it to the user. Using a few pieces of data from the URL (in $_GET), they define the phone number to send to and the name of the user. Finally they tie it into the Twilio messaging system and send the MMS message containing the resulting QR code.

tagged: twilio mms messaging qr code library tutorial laravel

Link: https://www.twilio.com/blog/2014/09/how-to-build-an-mms-ticketing-system-using-php-laravel-and-twilio.html

NetTuts.com:
Creating a Photo Tag Wall With Twilio Picture Messaging & PHP
Jan 10, 2014 @ 16:36:00

On NetTuts.com today there's a new tutorial that helps you create a "photo tag wall" using the Twilio picture messaging functionality and some PHP. The picture messaging service lets you send and receive photos over phone numbers and short codes.

Twilio’s recently announced Picture Messaging has vastly opened up what we can do with text messaging, now we can attach photos to our text messages and have them get used in different ways. In our case, we are going to build a Photo Tag Wall, which will contain photos linked to tags that will be displayed on a website. This can be handy for events, or parties, or just about anything where you want to associate photos and tags.

They use a combination of the Jolt microframework for the structure of the app, Idiorm/Paris for the MySQL handling and the Twilio PHP library to talk to their web service. They start by setting up the database tables for both the "tag" and "photo" (SQL included). They include a sample configuration file, used by the Twilio library, and get into the actual code. The first part shows how to make the request to the API and resize the fetched data into a correctly sized photo on the server. Then they get into the routing, making both a root path and a "listener" for the Twilio API to call when a new photo it sent. Finally, they set up the actual photo wall page, pulling the image data from the database and the image from the local file system.

tagged: photo tag wall tutorial twilio picture messaging mysql

Link: http://net.tutsplus.com/tutorials/php/creating-a-photo-tag-wall-with-twilio-picture-messaging-php

Lorenzo Alberton:
Updated Kafka PHP client library
Sep 18, 2012 @ 16:58:50

Lorenzo Alberton has a new post with an update about a library he's been working on to interface with Apache's Kafka system, "a persistent, distributed, high-throughput publish-subscribe messaging system".

Over a year ago I sort of reverse-engineered the protocol, and published a first rudimental library to produce and consume messages with version 0.05. Since then, the Kafka project has evolved a lot, moving from the LinkedIN repositories to the Apache Incubator, gaining traction, committers, features. The protocol has changed slightly too, so the old library doesn't work anymore with the new version (0.6+).

The library has gotten lots of new features in this update including gzip compression support, custom exception handling and better connection handling. He includes some sample code in the post showing how to create both the Producer and Consumer for the messages (and one for working with Zookeeper).

tagged: kafka client apache messaging producer consumer library update

Link:


Trending Topics: