Published: Sat, 22 Oct 2016 02:46:09 -0500
Fri, 21 Oct 2016 12:19:30 -0500
On the Stomt blog today there's a post showing how you can share components across Laravel/Lumen applications using a simple structure and making things like microservices easier.
In this blog post, we show a way to split up large Laravel applications into smaller micro-services, in our case Laravel & Lumen applications, and the advantages and pitfalls it brings with it. As a result, we sped up our applications by more than 30% and achieved greater maintainability, too. These principles can, of course, be easily applied to other frameworks.
A lot of functions are needed in our REST API as well as in our administration panel. [...] While we still have a “monolithic” codebase, we have multiple completely independent backend applications. You might want to call them “micro-services” (because it’s so trendy).
These microservices required similar functionality and splitting those out into shared components made sense. They walk you through some of the basic requirements they had when splitting the application and how the components are structured. They then shift over to the Laravel/Lumen side and show how multiple applications can be hosted via the same installation and where the shared components fit in. They show how to define namespaces to load the components and set up the providers so Laravel/Lumen knows how to use them.
Fri, 21 Oct 2016 11:52:28 -0500
The SitePoint PHP blog has a tutorial posted introducing you to a more recent addition to the testing tools available to PHP: atoum. The tutorial provides the basics and shows you how to use it in testing your code as an alternative to PHPUnit.
f you’ve been around PHP for more than a little while, you’ve no doubt started to test your code. And if you ask anyone in the PHP space what to use for writing unit tests, likely the first answer that they’ll give you is PHPUnit.
It’s the de facto standard in the PHP community, and with good reason. But it’s not the only choice. Whilst it does command the lion’s share, other choices abound, one of which I’m going to take you through in this tutorial; it’s called atoum.
They briefly introduce the tool (a "simple, modern, and intuitive unit testing framework for PHP") and help you get it installed. They also recommend installing the "atoum/stubs" package as well, making it easier to do autocomplete in most IDEs. From there the tutorial helps you configure your atoum installation to allow for code coverage reports to be generated. With things configured nicely, the next step is creating a first test evaluating a simple method that either works correctly or throws an exception. Code is included showing how to use the testing to set up expectations and evaluate the results of method execution. Finally they show the command to execute the test(s) and what the resulting code coverage reports look like.
Fri, 21 Oct 2016 10:43:38 -0500
The TutsPlus.com site has posted a new tutorial for the WordPress developers out there showing you how to get started with namespacing and autoloading in your WordPress installation.
Namespaces and autoloading are not topics that are usually discussed when it comes to working with WordPress plugins. Some of this has to do with the community that's around it, some of this has to do with the versions of PHP that WordPress supports, and some of it simply has to do with the fact that not many people are talking about it. And that's okay, to an extent.
Neither namespaces nor autoloading are topics that you absolutely need to use to create plugins. They can, however, provide a better way to organize and structure your code as well as cut down on the number of require, require_once, include, or include_once statements that your plugins use.
The article then starts in by listing the things you'll need to have installed and working to follow along. It then talks about what they're going to help you build - a simple plugin that adds an "Inspirational quotes" widget to your post editor page. They walk you through the basic setup of the plugin, adding the box to the page and setting up the "questions.txt" file to pull the quotes from. Code is provided for each step including the creation of the "quote reader" class and the class to display the meta box.
Fri, 21 Oct 2016 09:33:41 -0500
Freek Van der Herten has a post to his site showing how PHP functions can (sort of) be overloaded with the help of a trait from Adam Wathan.
PHP does not support method overloading. In case you’ve never heard of method overloading, it means that the language can pick a method based on which parameters you’re using to call it. This is possible in many other programming languages like Java, C++.
However, with some clever coding, Adam Wathan made a trait, aptly called Overloadable, that makes method overloading possible. It works by just accepting any parameters using the splat operator and then determining which of the given functions must be called according to the given parameters.
He shows how to use the trait in a simple example, defining a single "bar" function and using the "Overloadable" trait to handle the switching between the methods based on the input variables. You can find more information about the trait and the source for it in this gist over on GitHub.
Fri, 21 Oct 2016 08:05:01 -0500
Popular posts from PHPDeveloper.org for the past week:
Thu, 20 Oct 2016 12:07:18 -0500
The Laravel News site has released the latest episode of it's podcast, episode #28, covering Laravel 5.3.18, Yarn, Leanpub and more.
This is our last podcast episode for 2016 and we will be taking a break until next year.
Other topics mentioned also include Laravel Links, case sensitive filesystems in development and Powershell for Mac/Linux. You can listen to this latest episode either using the in-page player or by subscribing to their feed and getting this and other great episodes as they're released.
Thu, 20 Oct 2016 11:09:17 -0500
The Voices of the ElePHPant podcast has posted their latest interview with a member of the PHP community. In this new show host Cal Evans talks with Kirsten Hunter at the php[tek] 2016 conference.
Cal and Kirsten talk about her work as an API evangelist with Akamai. They also discuss her work across tech communities and different technologies as a "polyglot" developer. They also talk about some of the current technology in the PHP ecosystem and how it relates to making and maintaining APIs. Kirsten also talks some about her opinions on versioning in APIs and usability.
You can listen to this latest episode either through the in-page audio player or by downloading the mp3 directly. If you enjoy the episode be sure to subscribe to their feed and follow them on Twitter for updates when new shows are released.
Thu, 20 Oct 2016 10:58:47 -0500
The SitePoint PHP blog has posted another Minecraft-themed tutorial from Christopher Pitt, this time explaining how you can mod Minecraft with PHP without having to learn Java.
I’ve always wanted to make a Minecraft mod. Sadly, I was never very fond of re-learning Java, and that always seemed to be a requirement. Until recently. Thanks to dogged persistence, I’ve actually discovered a way to make Minecraft mods, without really knowing Java. There are a few tricks and caveats that will let us make all the mods we desire, from the comfort of our own PHP.
The method he's come up with talks directly to the Minecraft server (using AMPHP) to communicate via a RCON connection and place items in the world based on messages from the user. He uses code created previously to listen to the logs and grab the messages from the user. With this data he then sends a "blueprint" over the RCON connection with a set of coordinates of locations to build the blocks. The end result looks something like this.
Thu, 20 Oct 2016 09:32:44 -0500
In the latest part of his series covering Laravel 5.3, Matt Stauffer has posted this new tutorial covering the new notification system in the latest version of the popular Laravel framework.
In a previous blog post I've covered Laravel's new Mailable feature, which introduces some important changes to how we send mail in Laravel. I'd recommend at least skimming it if you haven't read it yet. In short, the preferred mail syntax is no longer sending mail using the "classic" mail closures, but instead creating a "Mailable" class for each message you want to send—for example, the "WelcomeNewUser" mailable class.
In Laravel 5.3, we have another new feature for communicating with our users: Notifications.
This notification system makes it simpler to send messages to your user when you don't care as much how they get it, just that they do. He walks you through the creation of your first notification class and breaks it down into its main parts, explaining each one. He shows how to define the different handlers for the notification types (like "toEmail") and how to trigger the notification, passing in either a single user or all users in the system. He then talks about the channels that are available to notifications and how to integrate several including Nexmo, database and the "broadcast" channel.
Thu, 20 Oct 2016 08:05:01 -0500
Here's what was popular in the PHP community one year ago today: