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

Laravel News:
Laravel 5.3 changes the “app” folder
Jul 22, 2016 @ 09:25:24

On the Laravel News site there's a new article posted about a big change coming to the "app" folder in Laravel-based applications (hint: it's moving towards more simple, not more complex).

As we are getting closer to the launch of Laravel 5.3 new features, seem to come out almost daily. The latest is a change to the “App” folder and in a move to simplify it, the Events, Jobs, Listeners, and Policies folders are now gone.

You can still get them back if you "artisan make" something that fits in one of these four folders but, as they're not really "required" by default they were removed to do some de-cluttering. If you want to find out more about what else is coming/changing in Laravel 5.3, check out this other article also on the Laravel News site.

tagged: laravel changes application app folder events jobs listeners policies

Link: https://laravel-news.com/2016/07/laravel-5-3-changes-app-folder

Nicolas Widart:
Writing modular applications with laravel-modules
Jul 13, 2016 @ 11:57:39

In a new post to his site Nicolas Widart introduces you to the idea of building Laravel applications a bit differently than you may normally: in a more modular structure. This structure makes use of this package to make it happen.

Let me start by saying Laravel is an amazing framework. However when it comes to writing more complex and bigger applications, I find the default structure laravel comes with cumbersome and not ideal.

The way the default laravel installation comes with is basically all the application logic inside an app/ folder. This works, but I would not suggest going this route. [...] This is what being modular is trying to resolve. You split of the business logic into different parts, which belongs together. If you're into Domain Driven Design, you can consider a module an aggregate.

Each module has its own resources (routes, models, views, etc) combined into a single "drop-in" structure. He provides an example of this structure and compares it to the more traditional Laravel "all-app" structure. The package he links to makes this modular structure simpler and points out that this system is what the AsgardCMS already uses behind the scenes.

tagged: modular application laravel tutorial example package asgardcms

Link: https://nicolaswidart.com/blog/writing-modular-applications-with-laravel-modules

Paragon Initiative:
Securing a PHP Application in 2016: The Pocket Guide
Jul 11, 2016 @ 12:45:11

The Paragon Initiative has posted a new tutorial giving you a pocket guide version to securing your PHP application in 2016.

Please set aside most of what you've heard over the years; chances are, most of it just muddies the water. Security is not a product. Security is not a checklist. Security is not an absolute.

Security is a process. Security is an emergent property of a mature mindset in the face of risk.

Perfect security is not possible, but attackers do have budgets. If you raise the cost of attacking a system (your application or the networking infrastructure it depends on) so high that the entities that would be interested in defeating your security are incredibly unlikely to succeed, you'll be incredibly unlikely to be compromised.

The post talks about the "essence of security" and how most prevention methods don't even add much processing overhead or overall development time. He makes four recommendations of things to do in current and future development to help secure your applications:

  • Use PHP 7 in All New Development
  • Use HTTPS Everywhere
  • Use Security Headers
  • Use Trustworthy Reference Material

The post ends with a few other things to think about when building secure applications including raising the "cost" of attacking your system and keeping in mind that your platform may not be the attacker's "end game".

tagged: paragoninitiative secure application pocket guide top4 php7 https headers references

Link: https://paragonie.com/blog/2016/07/securing-php-application-in-2016-pocket-guide

Freek Van der Herten:
A package to log activity in a Laravel app
Jun 30, 2016 @ 09:46:17

In a new post to his site Freek Van der Herten shares information about a logging package they've developed for Laravel-based applications to make activity logging simpler throughout the app: laravel-activitylog.

n your apps there’s probably a lot going on. Users log in and out, they create, update and delete content, mails get sent and so on. For an administrator of an app these events provide useful insights. In almost every project we make at Spatie we log these events and show them in the admin-section of our site. [...] We made a new package called laravel-activitylog that makes logging activities in a Laravel app a cinch. In this blogpost I’d like to walk you through it.

He then goes through the basics of using the library, complete with code examples:

  • simple activity logging with messaging
  • providing the "acted on" object information
  • logging the information about who the actor was

There's also a section with details on automatic model logging, making it easier to see the changes on you data without having to log each one individually. He also shows you how to use multiple logs, providing a method to narrow down log records by type.

tagged: laravel application logging package example introduction model

Link: https://murze.be/2016/06/package-log-activity-laravel-app/

SitePoint Web Blog:
Heroku Alternative: Deploy Apps with Dokku on DigitalOcean
Jun 29, 2016 @ 10:28:54

On the SitePoint Web blog there's a new tutorial showing you how to deploy applications with Dokku on DigitalOcean in the same way that you might with Heroku.

When Heroku announced their (quite reasonable) new limits for free apps, I realized that I would have to find another source of hosting for all the small, low-traffic projects that I currently have running on Heroku. [...] Since I have such an unreasonable number of apps running on Heroku, I thought it was high time to try out Dokku. Dokku is a Heroku-like tool that allows you to deploy complex apps by simply pushing with Git.

They start with some of the differences between the Heroku setup and Dokku, mostly that Dokku uses Docker for the deployment and configuration. They then show you how to create a Dokku server on DigitalOcean: setting up the domain, making the application and deploying the app with a push and other datastore plugins.

tagged: heroku dokku digitalocean deploy application tutorial

Link: https://www.sitepoint.com/heroku-alternative-deploy-apps-dokku-digitalocean/

SitePoint PHP Blog:
Can Symfony Apps Be Fast on Vagrant? Let’s Check with SuluCMS!
Jun 28, 2016 @ 12:13:15

On the SitePoint PHP blog they've posted a new tutorial looking at the combination of Symfony applications (well, one specific one) and Vagrant to optimize it for the best performance possible.

In this short tutorial, we’ll set up Sulu, a new Symfony based CMS, and optimize it on a Vagrant environment. Why a dedicated tutorial handling this? Besides the fact that Sulu has a rather complex initialization procedure, it is based on Symfony which is infamously slow on virtual machines with shared filesystems, and thus needs additional optimizations post-install. The performance hacks in this post, while Sulu-specific, can be applied to any Symfony application to make it faster on Vagrant.

The rest of the post walks you through the steps to get the box set up and the Sulu application up and running:

  • New Box and Folder Sharing
  • App Type and Vagrant Boot (configuration)
  • Installing Sulu

Then they get into the speed improvements and "hacks" to make the overall system perform better. They make updates to the log/cache directory fetching, moving the "vendors" folder into the VM (non-synced) and enabling the APC caching on autoloading. The tutorial also includes a few helpful troubleshooting tips of things to check if a problem does happen to pop up.

tagged: tutorial symfony application vagrant sulucms performance

Link: https://www.sitepoint.com/symfony-on-vagrant-performance-hacks-sulucms-case-study/

Yappa Blog:
Symfony Components in a Legacy PHP application
Jun 21, 2016 @ 12:50:13

On the Yappa Tech blog Joeri Verdeyen has written up a post covering the integration of modern Symfony components into a legacy application with a relatively simple container setup and configuration.

Symfony Components are a set of decoupled and reusable PHP libraries. They are becoming the standard foundation on which the best PHP applications are built. You can use any of these components in any of your applications independently from the Symfony Framework.

[...] The purpose of this post is to roughly describe how to implement some of the Symfony Components. I've created a set of gists to get started. You should already know how Symfony Components work in the Symfony Framework.

He starts with an example Composer configuration pulling in some of the more popular Symfony packages (like VarDumper and FormBuilder). He then includes the code to bootstrap the container instance and the services.yml he's come up with to bootstrap and integrate all of the components. The tutorial ends with examples of putting some of these components to use in resolving controllers, using the FormBuilder, using the command line and outputting errors with the VarDumper.

tagged: symfony component legacy application tutorial container example

Link: http://tech.yappa.be/symfony-components-in-a-legacy-php-application

SitePoint PHP Blog:
Your Own Custom Annotations – More than Just Comments!
Jun 21, 2016 @ 11:04:14

The SitePoint PHP blog has posted a new tutorial from author Daniel Sipos showing you how you can use custom annotations in your Symfony-based application. You can also do annotation parsing outside of Symfony but that requires other external libraries to accomplish.

In this article, we are going to look at how we can create and use our own custom annotations in a Symfony 3 application. You know annotations right? They are the docblock metadata/configuration we see above classes, methods and properties. You’ve most likely seen them used to declare Controller routes (@Route()) and Doctrine ORM mappings (@ORM()), or even to control access to various classes and methods in packages like Rauth. But have you ever wondered how can you use them yourself?

[...] In this article we are going to build a small reusable bundle called WorkerBundle. [...] We’re going to develop a small concept that allows the definition of various Worker types which “operate” at various speeds and which can then be used by anyone in the application. The actual worker operations are outside the scope of this post, since we are focusing on setting up the system to manage them (and discover them via annotations).

He then gets into the code, creating the WorkerInterface the workers will implement and a sample worker class with an annotation describing it. Next up he creates the WorkerManager to create and get the current set of workers. Then comes the discovery process and the creation of a simple class that looks through files and finds those with the @Worker annotation and makes them available as a worker instance. Finally he "wires it all together" in the services configuration and shows an example of a basic worker instance and using it by calling its work method.

tagged: custom annotations worker example symfony application tutorial

Link: https://www.sitepoint.com/your-own-custom-annotations/

SitePoint PHP Blog:
Hacking the Fitbit – Emulating a Pager for Twitter DMs!
Jun 17, 2016 @ 10:27:57

The SitePoint PHP blog has a tutorial they've posted from Christopher Pitt showing you how to hack your Fitbit into a pager for Twitter DMs. This essentially turns your Fitbit into a notification system for when someone on Twitter sends you a direct message. It's not overly useful (as you can't send a message) but it is an interesting integration.

I’ve been trying to wake up earlier in the morning. The trouble is that alarms wake everybody up, not just me. To get around this problem, I recently bought the cheapest Fitbit I could find, having learned that they have a neat silent alarm.

The truth is, if I had the cash I would rather have bought an Apple watch. When I got the Fitbit, my programmer brain immediately jumped to the question; “How can I hack this thing?” I ended up learning a bit about Fitbit, OAuth and the Twitter API. I also learned that sometimes it’s better just to get an Apple watch…

His application uses Lumen as the framework and makes connections to both the Twitter and Fitbit JSON APIs. He defines a few routes for the OAuth handling (with callbacks) and a simple view with the "Connect To" links. He shows the creation of applications on both the Twitter and Fitbit side and how to define their keys in your configuration. He sets up the Socialite providers for both connections and a bit of caching to prevent the need for a full pull. He then uses the Fitbit API to set "silent alarms" on your device that are timed to go off immediately when the app detects a new DM on the Twitter stream.

tagged: tutorial fitbit twitter api connect application alarm directmessage

Link: https://www.sitepoint.com/hacking-the-fitbit-emulating-a-pager-for-twitter-dms/

SitePoint PHP Blog:
The PHP Application Environment
Jun 16, 2016 @ 10:48:53

In this new post to the SitePoint PHP blog editor Bruno Skvorc shares a chapter from the recently released Jump Start PHP Environments from SitePoint publishing. You can order a copy of your own here.

This chapter will focus on the application environment. We’ll also discuss *AMP bundles such as XAMPP and why they’re a poor choice; production /development parity; and performance and debugging.

The remainder of the post is broken up into these main sections and also discusses topics like:

  • the differences between development, staging and production
  • the "machine pollution" that comes with the *AMP bundles
  • optimization tips about databases, front-end tools and caching

If this sample chapter was useful to you, be sure to check out and order the full book from the O'Reilly store.

tagged: application environment ebook jumpstart sample chapter

Link: https://www.sitepoint.com/php-application-environment/