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

Stovepipe Systems:
What are Bundles in Symfony?
Dec 06, 2016 @ 10:22:56

On the Stovepipe Systems Dev blog today Iltar van der Berg has shared a post about bundles, one of the key concepts in the Symfony ecosystem - what they are and some of the common features they all share.

People often refer to bundles as modules or re-usable code for Symfony applications. When a developer has experience with Symfony1 or another framework with the module concept, it might seem logical that this is what a bundle represents in Symfony.

So what is a bundle? When do you need one and what can it do? What's the difference between an AppBundle and a vendor Bundle?

He starts with the release of Symfony 2, including bundle support, and how common practices created hard dependencies between bundles. This created issues in the applications and reusability of the bundles (their whole purpose) so a solution was created: the AppBundle. This bundle shifted the emphasis away from the file structure of the bundles and more towards the domain they occupied, handling some "magic" references automatically for you.

As mentioned, the bundle provides an extension point. Other bundles for example, can hook in on your bundle because it contains some logic to expose information such as the directory of the bundle.

[...] The main purpose of a bundle however, is to provide an extension point for the Dependency Injection Container. When talking about this extension point, it revolves around adding, changing or removing service definitions.

tagged: symfony bundle introduction appbundle vendor

Link: https://stovepipe.systems/post/what-are-bundles-in-symfony

SitePoint PHP Blog:
Event Sourcing in a Pinch
Nov 30, 2016 @ 10:56:26

Christopher Pitt is back with a new tutorial on the SitePoint PHP blog talking about event sourcing in PHP including a brief explanation about what it is and how it can be useful in your PHP application.

Let’s talk about Event Sourcing. Perhaps you’ve heard of it, but haven’t found the time to attend a conference talk or read one of the older, larger books which describe it. It’s one of those topics I wish I’d known about sooner, and today I’m going to describe it to you in a way that I understand it.

Christopher then gets into some of the basic concepts behind event sourcing, a part of Domain Driven Design, and the difference between storing state and storing behavior. With this outlined he gets into the creation of the actual event handlers with examples from a retail application (orders, outlets, stock, pricing, etc). He includes the code for several simple events, a method for recoding them in your database and some helper functions to translate the event to the SQL required for the insert operation. He then links these with the event classes and putting them to use, executing them and getting the results back via a sort of "layer" between the fetch and the response.

tagged: eventsourcing tutorial introduction example domaindrivendesign

Link: https://www.sitepoint.com/event-sourcing-in-a-pinch/

TutsPlus.com:
Building Your Startup: The Dashboard Foundation
Nov 24, 2016 @ 16:28:49

NetTuts.com has continued their "Building Your Startup" series with this latest post focusing on the dashboard for the users of the meeting planner - a "quick look" into the current stats for their account.

For my initial statistics reporting, I focused on simple real-time data and detailed historical data. For example, real-time data would tell you the number of users and meetings built on the system to date and their status.

The historical data would tell you the number of users and meetings completed over time as well as other interesting data—especially growth curves that I and prospective investors may care about.

He then walks through the creation of the dashboard view, gathering together various pieces of real-time and historical data and displaying them in a simple table view. All code and SQL required is included as well as a few screenshots showing the results.

tagged: startup series meeting planner dashboard introduction

Link: https://code.tutsplus.com/tutorials/building-your-startup-the-dashboard-foundation--cms-26682

Barry van Veen:
Laravel service provider examples
Nov 15, 2016 @ 09:44:31

In this recent post to his site Barry van Veen introduces you to providers in Laravel applications and how they relate back to the built-in service provider.

Currently, I'm working on my first Laravel package. So, it was time to dive into the wonderful world of the service container and service providers.

Laravel has some great docs about, but I wanted to see some real-world examples for myself. And what better way than to have a look at the packages that you already depend on?

This post details the different things that a service provider can be used for, each taken from a real open-source project. I've linked to the source of each example.

He starts off talking about (and linking to) the current provider documentation and includes a basic example of adding the provider to your configuration. He then covers several different pieces of functionality that can be used inside the providers including:

  • binding of singletons and instances
  • setting up aliases
  • registering dependencies
  • adding in additional resources

There's also a few "other" things included showing how to defer loading, set up event listeners and adding in a new Blade directive.

tagged: laravel service provider introduction tutorial example

Link: https://barryvanveen.nl/blog/34-laravel-service-provider-examples

Laravel News:
Build your own Slack Bot with this PHP library
Nov 14, 2016 @ 10:43:22

On the Laravel News site they have a new post introducing a handy library you can use to make your own Slackbot quickly and easily (and in a framework agnostic way).

It seems like everyone is using Slack, from company channels to community groups including one for Laravel.

Bots have been the new rage within the service and if you’d like to build your own Marcel Pociot created a framework agnostic PHP Slackbot library to make this easy.

Bots built with SlackBot can hear things, say things and reply to what they hear. This allows you to create conversational applications the way real human people talk to each other.

The post then walks you through some of the most common operations using the bot including:

  • sending messages to a Slack instance
  • working with "conversations"
  • receiving simpler messages and acting on the contents

They also link to this more extended tutorial from the author of the library showing how to use the library with a simple Laravel application.

tagged: slack bot tutorial slackbot library framework agnostic tutorial introduction

Link: https://laravel-news.com/2016/11/slack-bot/

Zend Developer Zone:
Welcome to PHP
Nov 09, 2016 @ 11:05:02

It's no secret that PHP is one of the most popular languages for web development available. The language has enjoyed quite a bit of popularity over the years with more and more developers discovering and learning it all the time. On the Zend Developer Zone they've put together a guide just for those new to the PHP language and its community: Welcome to PHP.

Every day new developers discover the power of PHP and start looking for resources to help them learn more. It would be impossible to gather a complete list of all the resources, people, and projects that are useful to developers new to PHP. However, I decided it was time to put together a list designed to be starting point.

Ok, so all we need on the Internet is one more list. That having been said, I couldn’t think of a better way to organize this data other than into a list of lists. [...] Otherwise, here it is, presented to you in all its glory. If you like it, if you know someone new to PHP, please share it. I do hope that it is useful to anyone and everyone looking to get more involved or learn more. As the title says, Welcome to PHP!

The post is broken down into several sections (lists) including:

  • Language Resources
  • Community
  • Forums
  • Frameworks
  • News

There's plenty of links and descriptions of each resource linked to in these and a few other sections. If you're new to the world of PHP or even just looking to expand your horizons to more PHP-related things outside of your "developer bubble" check out the full post.

tagged: welcometophp language community guide introduction list resources

Link: https://devzone.zend.com/welcome-to-php/

TutsPlus.com:
Using Namespaces and Autoloading in WordPress Plugins, Part 2
Nov 03, 2016 @ 11:55:25

The TutsPlus.com site has continued their series looking at namespace-based autoloading in WordPress applications with part two. In this latest article they build on the simple plugin from part one and enhancing it with more functionality and autoloaded classes.

In the previous tutorial, we began talking about namespaces and autoloading with PHP in the context of WordPress development. And although we never actually introduced either of those two topics, we did define them and begin laying the foundation for how we'll introduce them in an upcoming tutorial.

Before we do that, though, there's some functionality that we need to complete to round out our plugin. The goal is to finish the plugin and its functionality so that we have a basic, object-oriented plugin that's documented and works well with one caveat; it doesn't use namespaces or autoloading.

This, in turn, will give us the chance to see what a plugin looks like before and after introducing these topics.

They start off with a quick review of the setup and previous development work done on the plugin making it easier to load in Javascript templates in a dynamic way. The plugin is then ready to start helping with the plugin use. They add in a basic CSS file to the site's "assets" folder and enqueue it. They start updating the plugin code, adding in an assets interface, a CSS loader and some styling for the box shown on the edit post interface.

tagged: namespace autoload wordpress plugin introduction part2 series autoload css loader

Link: https://code.tutsplus.com/tutorials/using-namespaces-and-autoloading-in-wordpress-plugins-part-2--cms-27203

Scotch.io:
Understanding PHP Generators
Oct 28, 2016 @ 11:20:44

The Scotch.io blog has posted a tutorial that wants to introduce you to and help you understand a feature recently added to the PHP language: generators. In this new article author Samuel Oloruntoba walks you through some of the basics and offers advice on when to use this helpful feature.

When it comes to driving, speed is not everything. But on the web, speed makes all the difference. The faster your application, the better the user experience. Well, this article is on PHP Generators, so why are we talking about speed? As you are soon about to find out, generators make a huge difference on speed and memory management.

He starts off by explaining what generators are and gives a simple code example showing how they can replace a standard loop (without some of the memory overhead). He uses a for and foreach loop to show a memory overflow caused by it trying to reach the highest integer allowed in the config. To help solve this, he makes use of generators, a much more memory efficient method that only returns the latest value requested and doesn't keep the remainder in memory. He then answers the question of why you might need to even use generators, how to return keys and send values into the generator. He also offers a word of advice on using them - mostly to not overuse them as it's still possible to have issues (like the memory one above).

tagged: generator example introduction tutorial memory yield

Link: https://scotch.io/tutorials/understanding-php-generators

SitePoint PHP Blog:
Testing PHP Code with Atoum – an Alternative to PHPUnit
Oct 21, 2016 @ 11:52:28

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.

tagged: testing unittest atoum introduction tutorial alternative

Link: https://www.sitepoint.com/testing-php-code-with-atoum-an-alternative-to-phpunit/

TutsPlus.com:
Using Namespaces and Autoloading in WordPress Plugins, Part 1
Oct 21, 2016 @ 10:43:38

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.

tagged: namespace autoload wordpress plugin introduction part1 series quotes

Link: https://code.tutsplus.com/tutorials/using-namespaces-and-autoloading-in-wordpress-plugins-part-1--cms-27157