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

Robert Basic:
Current Vim setup for PHP development
Feb 10, 2017 @ 11:46:10

For those out there always interested in how other developers have their development environment, Robert Basic has some info on his own setup that might interest you. In this new post to his site he shares his configuration using the Vim editor when writing PHP code.

I made some changes to my Vim setup for PHP development recently, so it’s time to write it all down. I’m more than sure that I’ll break it soon and won’t be able to remember all the things I did to have the current setup.

Some new plugins popped up on my radar, I tweaked some older plugins and I even wrote one for PHPStan!

He starts with the improvements in tag support he's found recently using the Gutentags plugin. He also covers other tools and functionality like:

  • Jump to definition
  • (Getting the ) current PHP class and method
  • PHP namespaces
  • Linting
  • A promising completion engine for PHP
  • PHPStan in Vim
  • Debugging

He finishes up the post with a few other helpful supporting plugins for indenting, searching and argument swapping.

tagged: vim editor setup development plugin programming

Link: https://robertbasic.com/blog/current-vim-setup-for-php-development/

Leonid Mamchenkov:
composer-patches – Simple patches plugin for Composer
Jan 31, 2017 @ 09:22:18

Leonid Mamchenkov has an interesting post to his site detailing a plugin for the popular Composer package management tool that makes it easier to apply patches to the current version of libraries in use: composer-patches

composer-patches is a plugin for Composer which helps with applying patches to the installed dependencies. It supports patches from URLs, local files, and from other dependencies.

This plugin makes it so that, during the normal Composer installation flow, you can apply your own patches to fix functionality that may not be corrected upstream yet. It replaces the need to "fork and fix" in your own version of the repository and cleans up the process to a more automated flow. It can also help when working with multiple people on the same code that's not your own and apply their patches to evaluate their changes.

You can find more information about the composer-packages plugin in the README on its GitHub repository.

tagged: composer patch plugin introduction example usage

Link: http://mamchenkov.net/wordpress/2017/01/31/composer-patches-simple-patches-plugin-for-composer/

NetTuts.com:
Using Namespaces and Autoloading in WordPress Plugins, Part 4
Jan 19, 2017 @ 10:24:36

The TutsPlus.com site has posted the fourth part of their series covering the use of namespacing and autoloading in WordPress plugins. In this latest tutorial they take everything they've shared (and made) previously and put it all together into a cohesive whole plugin.

At this point, we've laid the foundation for our plugin, written the plugin, and defined and explored namespaces and autoloaders. All that's left is to apply what we've learned.

So in this tutorial, we're going to put all of the pieces together. Specifically, we're going to revisit the source code of our plugin, namespace all relevant classes, and write an autoloader so that we can remove all of our include statements.

He starts off talking about namespacing and how it relates to directory structure and the code you'll need for each of the plugin files for put them in the correct namespace. With just these in place, however, errors are thrown. This requires the setup of a custom autoloader and PHP's own spl_autoload_register handling. He includes the code for the autoloader, taking in the class name and splitting it up to locate the correct directory, making it easier to replace the loading of all plugin scripts.

tagged: namespacing tutorial series part4 wordpress plugin autoloading namespace

Link: https://code.tutsplus.com/tutorials/using-namespaces-and-autoloading-in-wordpress-plugins-4--cms-27342

Adam Wathan:
Optimizing Your PHPUnit Workflow in Sublime Text
Jan 17, 2017 @ 12:55:10

Adam Wathan has a post over on his site showing you how you can optimize your PHPUnit workflow in Sublime Text with the help of a few handy snippets.

I've been a big fan of Sublime Text's snippets feature for years.

They make it really easy to generate repetitive boilerplate code, and if you know how to use placeholders and substitutions properly, you can do some pretty magical stuff.

He shares some of his own snippets for automagically:

  • creating a new test matching the filename currently selected
  • making new test methods with some placeholder content
  • making the tests easier to run

For this last point he shows the use of the Sublime PHPUnit package to run the tests through the Sublime menu. Finally he ties it all together in a much simpler workflow including a final "all tests" run before he commits.

tagged: sublimetext editor phpunit workflow testing plugin snippet

Link: https://adamwathan.me/2017/01/16/optimizing-your-phpunit-workflow-in-sublime-text/

SitePoint PHP Blog:
Re-Introducing Jenkins: Automated Testing with Pipelines
Jan 06, 2017 @ 10:48:44

The SitePoint PHP blog has posted a tutorial from Alex Bilbie that "re-introduces you to Jenkins", a popular build automation software, and how you can integrate it, and a new feature called "pipelines", into your processes.

As our applications become more complex – with Composer dependencies, Webpack build scripts, and per-environment variables – we inevitably reach a point where testing all of these different intricacies becomes slow and laborious, especially when you’re tearing down and rebuilding the entire environment for each test. Likewise, code style might deviate over time and creating a production ready deployment archive requires a specific set of steps to be followed.

He talks about some common tasks that might be involved in the build (installing Composer libs, running PHPUnit, etc) and how automating them can help prevent issues and make it less time consuming for your developers as they make changes. Along with the latest version of Jenkins (v2.0) they introduced the "pipelines plugin". Pipelines allow you to define multi-step configurations Jenkins then uses when the build is executed. He walks you through installing Jenkins, setting it up and creating your first job. They provide the example pipeline script to get you started. There's also a section talking about the Jenkinsfile and setting it up in the Jenkins job to automatically be used (instead of a config in-job).

He finishes the post looking at multibranch pipelines and some things "taking it further" by adding in other plugins, customized with their own section in the Jenkinsfile configuration.

tagged: jenkins pipelines automation testing pipelines plugin groovy

Link: https://www.sitepoint.com/re-introducing-jenkins-automated-testing-with-pipelines/

Laravel News:
Run PHPUnit Tests From Sublime Text
Dec 29, 2016 @ 09:30:48

On the Laravel News site they've posted a guide showing you how to setup and run PHPUnit tests from Sublime Text, one of the more popular editors for code development.

Sublime Text is a great editor. It’s lightweight, fast, and extremely customizable. However, one downside to it compared to a full blown IDE is it doesn’t come with support for running your PHPUnit tests directly from the test class you are working with.

To solve this problem, Adam Wathan created and released a free package named Sublime PHPUnit that allows you to run your tests from a keyboard shortcut. Let’s take a look at how to add this package to your arsenal.

The post walks you through the installation of the tool (manually cloning the repository) and how to then use it via Sublime's command palette. There's also some instruction on customizing the plugin's setup and allowing for shortcut keystrokes bound to events the plugin provides. The final tip helps you change the tool used to run the tests (the Terminal app by default) over to something like ITerm.

tagged: phpunit test unittest sublimetext editor plugin keystroke run

Link: https://laravel-news.com/sublime-phpunit

Toptal.com:
The Ultimate Guide to Building a WordPress Plugin
Dec 23, 2016 @ 12:07:41

For those newer to the world of WordPress, you might only be casually familiar with WordPress plugins and their use. You might have only installed them and used them before but have you wondered what it would take to make your own? In this new tutorial from Toptal.com Ratko Solaja gives you a "ultimate guide" to getting started down the road of custom WordPress plugin development.

Plugins are a vital part of WordPress websites that need specific functionalities. While the official WordPress repository has more than 45,000 plugins from you to choose from, many of these plugins miss the mark.

Just because a plugin is in the repository doesn’t mean it won’t hinder its performance or compromise its security. So what can you do? Well, you can build your own.

He starts with the planning stages of his example plugin (a real-world project helps when learning new things) - one that allows users to save content for later reading. He outlines the goals of the settings screen, how saving will work, messages to the user and what the "saved" screen will do. He recommends starting with a boilerplate plugin and working from there. He then goes through each step of the development process:

  • Handle activation and deactivation
  • Create a plugin settings page
  • Create the plugin functionality
  • Make the plugin modular
  • Generate translation files

The end result is a complete plugin with both the required frontend and backend functionality to make the "save content" feature work. All code is provided and plenty of links to more information and other resources are sprinkled throughout the article.

tagged: toptal wordpress plugin guide tutorial content example

Link: https://www.toptal.com/wordpress/ultimate-guide-building-wordpress-plugin

TutsPlus.com:
Object-Oriented Autoloading in WordPress, Part 3
Dec 01, 2016 @ 11:15:35

TutsPlus.com has continued their series covering object-oriented development practices in WordPress (plugins) with this third tutorial. In previous parts they set up the environment and introduced some of the basic concepts of OOP programming and getting the first classes and files defined.

In the last tutorial, we reviewed the original state of our autoloader and then went through a process of object-oriented analysis and design. The purpose of doing this is so that we can tie together everything that we've covered in this series and the introductory series.

Secondly, the purpose of doing this in its own tutorial is so we can spend the rest of this time walking through our class, seeing how each part fits together, implementing it in our plugin, and then seeing how applying object-oriented programming and the single responsibility principle can lead to a more focused, maintainable solution.

They start with a brief review of what they've covered so far and begin to build on the changes suggested in the previous part of the series. They've already broken it down into the different functional classes (according to the single-responsibility principle) and take the next step of including them and calling some example code to prove all is working as expected.

tagged: oop wordpress tutorial series objectoriented programming plugin part3

Link: https://code.tutsplus.com/tutorials/object-oriented-autoloading-in-wordpress-part-3--cms-27515

Zend Developer Zone:
WordPress updates Plugin Guidelines
Nov 11, 2016 @ 12:55:11

The Zend Developer Zone has a new post with information about some updates from the WordPress project about what plugin authors must do to be compliant with the rules of the WordPress Plugin Directory.

After five years, the WordPress plugin team has updated the Plugin Guidelines. These are the guidelines that WordPress plugin authors must comply with to be included in the WordPress Plugin Directory.

The guidelines were soft-launched last month so that they could be vetted by the larger plugin developer community community. On November 1st, 2017, they were officially announced “Revised Guidelines Are Live” by Mika Epstein.

Overall, these guidelines are good. They are solid, well communicated and clear to anyone who reads them.

The ZDZ post focuses in on just two of the guidelines that were updated with a few brief thoughts in each:

  • #4. Keep your code (mostly) human readable
  • #9, The plugin and its developers must not do anything illegal, dishonest, or morally offensive

They point out that, while the intent is good for #9, the term "morally offensive" is very broad and could be interpreted in many ways by many different groups.

tagged: wordpress plugin update directory official guidelines

Link: https://devzone.zend.com/7331/wordpress-updates-plugin-guidelines/

SitePoint PHP Blog:
Extending OctoberCMS – Building a Soft-Delete Plugin
Nov 07, 2016 @ 10:38:24

The SitePoint PHP blog has a new post today helping the users of the OctoberCMS content management system build a "soft delete" plugin by extending the functionality already included in the code.

Developers usually stick with a new CMS for its simplicity and extensibility. OctoberCMS presents itself as a back to basics CMS, and provides an enjoyable experience for both developers and users. In this article, I’m going to demonstrate some aspects of the CMS that make it extensible, and we’ll also try a simple plugin to extend another plugin functionality.

The tutorial starts by talking about extensibility and how plugins play into it in most normal CMS software (in their example, its listening to an event fired when a new post is made). They start by creating a new plugin skeleton via the "create:plugin" artisan command and creating a migration to extend the database with the "soft delete" column. After running the migration, they add in a new listener for an "extendColumns" event and extending the filter to extend the scopes pulling out posts data. They further extend the functionality with a helpful trait filtering the data by the "deleted_at" value and adding that into the scope as well. Finally they add a listener onto the Eloquent events for the "deleting" event to capture it and set the "deleted_at" value on the post record and save it.

tagged: extend octombercms contentmanagement tutorial softdelete delete plugin events

Link: https://www.sitepoint.com/extending-octobercms-building-a-soft-delete-plugin/