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

Loïc Faugeron:
Towards CQRS, Command Bus
May 12, 2016 @ 12:07:21

Loïc Faugeron has made a new post to his site talking about moving towards CQRS and Command Bus architecture in PHP applications.

By following the Command / Query Responsibility Segregation (CQRS) principle, we separate "write" logic from "read" logic. This can be applied on many levels, for example on the macro one we can have a single "Publisher" server (write) with many "Subscribers" servers (read), and on a micro level we can use this principle to keep our controllers small.

However, transitioning from a regular mindset to a CQRS one can be difficult. In this article, we'll explore the "Command Bus" pattern, to help us to get the Command (write) part right.

He starts with an example of a "create profile" happens and all logic lives in the controller. He then gets into the basics of the Command Bus handling and how the concept of "middleware" relates. He then shows how to migrate over to the Command Bus handling in his controller example, creating a CreateNewProfile command (with unit tests) and its handler. He then refactors the controller to put it to use. He points out that the initial version is tightly coupled to Doctrine so he refactors it too via some simple interfaces.

tagged: commandbus tutorial cqrs example refactor controller command handler

Link: https://gnugat.github.io/2016/05/11/towards-cqrs-command-bus.html

TutsPlus.com:
How to Create a Slack Interface for Your PHP Application
Apr 21, 2016 @ 10:12:04

On the TutsPlus.com site they've posted a tutorial helping you connect your PHP application with Slack allowing for both the sending of content to your Slack channel(s) but also responding to "slash" commands.

If you've been following the development of office communication tools in the past year or so, I'm sure you've heard plenty about Slack. [...] As developers, we are in a good position to jump on the trend and think about ways we can use Slack as a chat-based user interface for our applications.

That's why, in this tutorial, you will learn how to get started with integrating your PHP application to Slack, by making it post messages to a Slack channel and respond to slash commands.

They start with a "bare bones" setup that will get you up and running and sending messages to your Slack instance. Their example takes in a string and sends it along through a custom Slack application. They walk you through the steps to create this application on the Slack side and this example code to make the connection and send the message. The tutorial walks you through all of the provided code and helps you get your OAuth credentials in place to secure the connection.

With this basic functionality in place you can then build on top of it and define "slash" commands that request a URL. Their example "tells a joke" in the channel making the request.

tagged: tutorial slack integration api slash command introduction

Link: http://code.tutsplus.com/tutorials/how-to-create-a-slack-interface-for-your-php-application--cms-25269

Marko Pavlovic:
Restful Commander
Mar 23, 2016 @ 11:55:10

In this post to his site Marko Pavlovic talks about REST APIs, some of the non-CRUD (create, read, update, delete) operations that need to be performed and how the Command design pattern can help.

We’ve all been here: the data model has been designed, and we have the entities and relationships implemented. It is finally time to code up the business logic and we are faced with solving these problems: The actions we want to implement on a particular model are not part of the good old CRUD (Create, Read, Update, Delete) operations, and we need to make a lot of non-standard controller actions, and routes. [Also] the actions we want to implement do not belong to a any model, and we have to create a new controller just for the "API".

He gives a more concrete example to illustrate the problem using "sites", "visits" and a desire to add analytics functionality using each's data. He points out two common actions taken when something like this comes up: either new methods on the pre-existing controllers or possibly making a new controller to handle it. Instead he suggests using the Command pattern to handle requests themselves as self-contained items. This gathers all the logic needed in to one place and the Report instance can then be used as-is by the response that needs to render the results.

tagged: rest api command designpattern report site visit

Link: http://markonis.github.io/rest/api/design-patterns/2016/02/23/restful-commander.html

Geert Eltink:
Zend-Expressive Console CLI Commands
Feb 12, 2016 @ 11:21:15

In a new post to his site Geert Eltink shares how he added console command support to Zend Expressive, a PSR-7 framework from Zend that recently hit it's v1.0 mark.

zend-expressive does not come out of the box with a console for handling cli commands. However it's easy to add this and make full use of the container and its dependencies.

He uses the Symfony console component to handle most of the "heavy lifting" with the command line interaction, pulled in via Composer. He shows the process for getting the component installed and how to create the "bootstrap" file needed to build an instance of the Application class. He follows this with a simple "greeting" command including the configuration to add a few arguments and output the simple "Hello" message. He then creates the functionality to wire it in to the Zend Expressive application and gives an example of it in use.

tagged: zend expressive framework console command commandline cli tutorial symfony component

Link: https://xtreamwayz.com/blog/2016-02-07-zend-expressive-console-cli-commands

Freek Van der Herten:
Some Laravel Homestead tips
Jan 18, 2016 @ 12:27:30

Freek Van der Herten has a post to his site sharing some Laravel Homestead tips you can use to optimize and customize your current Homestead installation.

Homestead is a pre-packaged Vagrant box that includes a good development environment. It was made and is maintained by Taylor Otwell, the creator of Laravel. In this post I’d like to share some tips regarding this box.

His list of tips includes:

  • Map all sites at once
  • Use a bash function to work with a globally installed homestead
  • Map your dotfiles directory

Each tip comes with a bit of code/configuration changes to make to be able to use the functionality and configure the instance correctly.

tagged: laravel homestead tips configuration command example

Link: https://murze.be/2016/01/some-laravel-homestead-tips/

SitePoint PHP Blog:
Managing Cronjobs with Laravel
Oct 27, 2015 @ 11:18:06

The SitePoint PHP blog has a tutorial posted showing you how to use the Laravel "scheduler" to handle cron jobs and the execution of custom commands.

There are times when your application needs to run administrative tasks periodically on the server. Whether you want to send out emails to your users or clean up the database tables at the end of the day, you will need a task scheduling mechanism to take care of the tasks, when it’s time. Cron is a task scheduler in unix-like systems, which runs shell commands at certain intervals.

They start with some of the basics of cron and how is configuration is defined. Since the Laravel scheduler makes use of the same format, they want to be sure everyone is on the same page. Next they show you how to create a custom command in Laravel, a simple script designed to be run on the command line. The tutorial shows how to execute the simple command and how to add it to your application's "commands" list in the configuration. Finally they get to scheduling the commands, defining a schedule method and using the Laravel helper methods to set the execution time to something like "daily", "hourly" or, if you need something a bit more custom, a full cron-formatted string. The post ends with the addition of the Laravel scheduler execution to the system cron, set to run every minute.

tagged: manage cronjob laravel scheduler custom tutorial command

Link: http://www.sitepoint.com/managing-cronjobs-with-laravel/

Community News:
PEAR 1.10.0dev1 brings PHP 7 compatibility!
Jul 28, 2015 @ 12:14:42

As was announced on both the PEAR blog and Christian Weiske's blog, the PEAR project has made a major update to add PHP7 support preparing it for the upcoming major release.

The new PEAR installer release adds PHP 7 support while dropping support for PHP 4 - 5.3. It also fixes a nasty SSL issue that made it hard to use on PHP 5.6. With the update, strict warnings about static calls to a non-static PEAR::isError() are a thing of the past.

I've just published the first preview version: PEAR 1.10.0dev1.

Upgrading your version of the PEAR installer is as simple as a call to pear upgrade specifying this dev1 release (command is included in the post). He also links to some pre-release versions of the go-pear and pear-nozlib installers.

tagged: pear php7 compatibility dev1 installer upgrade command

Link: http://cweiske.de/tagebuch/pear-1.10.0dev1.htm

Joe Ferguson:
Install Homestead into your project
Jun 24, 2015 @ 09:53:42

As the Laravel News site mentions in one of their latest posts, the Laravel Homestead project received an update recently that makes it easier to install per-project rather than the previous "one install for everything" setup.

Over the weekend, Homestead received a new update that allows you to run it on a per project basis. Previously Homestead was designed so that you install it once on your system and share all your sites within the virtual machine. Joe Ferguson created the pull request to help get this feature implemented and he has a full write up on his blog.

This change pulls in the functionality doing all the hard work for you. It copies over needed files and setting up the Homestead vagrant instance directly from inside the project. Joe also describes the command line options you can provide, defining a name and hostname for the new instance. You can find out more about it in the official documentation.

tagged: laravel homestead project perproject command hostname name

Link: http://www.joeferguson.me/install-homestead-into-your-project/

Marc Morera:
Lazy Commands in Symfony
May 08, 2015 @ 08:13:22

In the latest post to his site Marc Morera about the use of "lazy services" with Symfony2. In his examples, he uses a command line application to illustrate his point, but it could apply elsewhere as well.

Since Symfony version 2.4 you can define your controllers and commands as services. This is so useful as long as you need to treat your classes as much decoupled as possible. [...] When we define as lazy a service, this is not instanced when is injected, but only when is accessed. [...] The point here is to define our service intended to work with the model as lazy.

He shows how to implement this kind of "lazy" handling in a command, registering the commands into the services but not creating the instances of them until they're used. He includes some example code showing how this is set up and offers a few tips on the implementation and common issues to think about.

tagged: symfony2 command lazy service register tutorial

Link: http://mmoreram.com/blog/2015/05/08/lazy-commands-in-symfony/

SitePoint PHP Blog:
Symfony2 Console: Getting Started with Console Helpers
Apr 09, 2015 @ 10:44:03

If you've ever worked with the Symfony Console component and wanted to enhance the experience with some additional functionality, check out the latest tutorial from the SitePoint PHP blog: Symfony2 Console: Getting Started with Console Helpers.

In this tutorial, I’ll share my experiences and we’ll give some extra love to the console helpers, which provide us with a large collection of handy functions. There are a lot of reasons to create console commands in your projects: sending emails, exporting/importing data, creating users, and so on. [...] By the end of this post, we want to be able to create a basic console command to generate some output – any output will do – only the way to getting there is important. Near the end, we’ll discover some console helpers in order to create some nice interactions between users and the interface.

He starts by helping you get the component installed via Composer and creating the first simple command line script (a ConsoleApplication). He shows how to add in a basic "hello world" command (conveniently named "BasicCommand") and the result when executed. With this in place, he starts in on three helpers:

  • Question Helper
  • Table class
  • Progress Bar

Each includes the code needed to implement it and the resulting output. You can find out more about the component in the Symfony2 documentation.

tagged: symfony2 console tutorial command helpers introduction question table progressbar

Link: http://www.sitepoint.com/symfony2-console-getting-started-console-helpers/