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

QaFoo Blog:
How You Can Successfully Ship New Code in a Legacy Codebase
Apr 21, 2017 @ 13:39:13

On the QaFoo blog there's a new post sharing some ideas on how you can add new code to a legacy application and ship it successfully without too much interruption to the current code.

Usually the problems software needs to solve get more complex over time. As the software itself needs to model this increased complexity it is often necessary to replace entire subsystems with more efficient or flexible solutions. Instead of starting from scratch whenever this happens (often!), a better solution is to refactor the existing code and therefore reducing the risk of losing existing business rules and knowledge.

[...] Instead of introducing a long running branch in your version control system (VCS) where you spend days and months of refactoring, you instead introduce an abstraction in your code-base and implement the branching part by selecting different implementations of this abstraction at runtime.

They then give a few examples of methods that can be use to get the new code in:

  • Replacing the Backend in a CMS
  • Rewriting a submodule without changing public API
  • Github reimplements Merge button

The final point is broken down into the process they recommend including the refactor of the current code, starting in on the new implementation and deleting the old code.

tagged: refactor ship new code legacy application tutorial

Link: https://qafoo.com/blog/101_branch_by_abstraction.html

Zend Framework Blog:
Develop Expressive Applications Rapidly Using CLI Tooling
Apr 12, 2017 @ 09:54:05

On the Zend Framework blog Matthew Weier O'Phinney has posted a tutorial showing off some of the Expressive command line functionality that can help you rapidly develop applications using the Zend Expressive framework.

First impressions matter, particularly when you start using a new framework. As such, we're striving to improve your first tasks with Expressive. With the 2.0 release, we provided several migration tools, as well as tooling for creating, registering, and deregistering middleware modules. Each was shipped as a separate script, with little unification between them.

Today, we've pushed a unified script, expressive, which provides access to all the migration tooling, module tooling, and new tooling to help you create http-interop middleware. Our hope is to make your first few minutes with Expressive a bit easier, so you can start writing powerful applications.

The post starts with the Composer commands to create a new Expressive project and to pull in the "zendframework/zend-expressive-tooling" package to add the CLI tools to the project. It then talks briefly about what functionality the tools bring and helps you use them to create your first module, populating out the directories and files required. Next up is the creation of the middleware for a "list" action and what the resulting code ends up being. They end the post by pointing out that this is just a start to the ultimate functionality of this tool and are open to requests for new commands to add in future releases.

tagged: zendexpressive application tooling commandline expressive tutorial install

Link: https://framework.zend.com/blog/2017-04-11-expressive-tooling.html

Fabien Potencier:
Symfony 4: Monolith vs Micro
Apr 05, 2017 @ 09:43:14

Fabien Potencier is back with a new post on his site following up this article about application composition and Symfony 4. In his latest post he compares two approaches to applications: micro versus macro.

Monolith projects versus micro-applications; a never-ending debate. Both ways to develop applications are fine in my book. Symfony supports both. Even if the Symfony Standard Edition is probably more suitable for monolith projects as it depends on the symfony/symfony package.

[...] Silex took another approach where each individual components are required when needed. Does it make Silex simpler, more lightweight, or faster than Symfony? No. Nevertheless, Symfony 4 is going to be more similar to Silex in this regard.

He talks about changes upcoming in Symfony 4 including the move away from the "symfony/symfony" package system and in with a component/bundle driven system. He gets into a specific example around the "symfony-framework" bundle. He then comes back around to the idea of "composition" of applications, adding Symfony dependencies only when needed but still having them work together seamlessly. The post ends with a discussion that was had about going the "bundle-less application" route and, while Symfony 4 will recommend it, the bundle system will still function as expected.

tagged: symfony symfony4 bundle application micro macro framework

Link: http://fabien.potencier.org/symfony4-monolith-vs-micro.html

Fabien Potencier:
Symfony 4: Compose your Applications
Apr 03, 2017 @ 10:31:26

On his site Fabien Potencier has posted an article about the next major release of the Symfony framework - version 4 - and how it will allow for the "composition" of your applications rather than some of the current methods.

Symfony 3.0 was boring, a cleaned-up version of the Symfony 2.8 version. Symfony 4.0 will be different: Symfony 4.0 = Symfony 3.4 - deprecated features + a new way to develop applications

There is another way to think about a new major version though: Symfony 4.0 = Symfony 3.0 + all features added in 3.x - deprecated features + a new way to develop applications

He goes through some of his thinking process around some of these changes and the "day-to-day experience" of managing a Symfony application. Specifically he suggests that:

  • Installing a Bundle is too cumbersome
  • Removing a Bundle is even more cumbersome
  • The Symfony Standard Edition is not good enough
  • No Distribution Ecosystem

He ends the post with a look at what he sees as the ideal ecosystem for the framework and where Symfony Flex fits into the picture (example project here).

Symfony Flex is going to be the default way to manage Symfony 4 applications. But Symfony Flex will be available as an option to manage Symfony 3.3 and 3.4 applications as well! That said, we might need to break backward compatibility between now and the launch of Symfony 4. Consider Symfony Flex as alpha before Symfony 4.
tagged: symfony symfony4 compose application progress ecosystem

Link: http://fabien.potencier.org/symfony4-compose-applications.html

Hackermoon.com:
Debugging a PHP application with strace
Mar 28, 2017 @ 11:24:43

On the Hackernoon.com site there's a recent post from Paolo Agostinetto showing you how to debug your PHP application with a different tool that most might use: strace.

Every once in a while it happens that you have a tricky bug, and when it does you risk to lose hours or even days fixing it.

[...] Yet, sometimes there is that one bug that makes you lose your shit after a whole afternoon spent looking for the root cause. In my experience, bugs that I introduce are generally very quick and easy to spot and fix. But the real challenge is finding bugs in other people’s code like third party libraries, PHP extensions or even PHP itself.

He then talks about a time when his situation was a bit different - he was getting 500 errors from his code that weren't being caught correctly by error handling. He found that Apache was out-of-memory-ing but debugging the exact cause (a suspect Doctrine query) would take more time. Instead he turned to strace and, with a bit of hunting in the resulting output, he tracked the issue down to XDebug being enabled (and a setting that was generating a memory leak).

tagged: debug application strace memory error xdebug process

Link: https://hackernoon.com/debugging-a-php-application-with-strace-4d0ae59f880b

Alejandro Celaya:
My thoughts after migrating some projects to Zend Expressive 2
Mar 28, 2017 @ 10:15:20

Alejandro Celaya has a new post to his site sharing some of his thoughts after migration applications to Zend Expressive 2 and some of his experiences along the way upgrading to this latest version.

The day Zend Expressive 2 was released I was super excited. I have been using it a lot for both professional and personal projects, so I'm quite used to it.

Since I've been using it in many projects, being able to update all of them to version 2 was a challenge, but I can say, I have succeed.

He talks about the projects themselves first, his own site at alejandrocelaya.com and shlink.io, and what kind of functionality they have. He then briefly covers the process to get them migrated and some of the changes he needed to make including:

  • adding an error hander
  • moving to the new error handling middleware strategy
  • using the support for interop middleware (single-pass)
  • small router changes due to using a custom router

He ends the post looking at the shift in programmatic approach Zend Expressive 2 uses (versus v1 handling) and changes he made to his middleware handling to reflect it.

tagged: zendexpressive2 zendexpressive upgrade application process changes

Link: https://blog.alejandrocelaya.com/2017/03/27/my-thoughts-after-migrating-some-projects-to-zend-expressive-2/

Robert Basic:
Loading fixtures for a Symfony app in Behat tests
Mar 23, 2017 @ 10:38:58

Robert Basic has a new post to his site with some advice for the Behat users out there testing their Symfony applications. He shows how to easily load up fixture data with the help of Doctrine.

Performing end to end testing of any application requires from us to have a set of reliable test data in the database.

If we write a Symfony application and use Behat to do the end to end testing, the we can use the Doctrine fixtures bundle to create the required fixture loaders and load them in our Behat scenarios when required.

He walks you through the installation of the Doctrine fixtures bundle (via Composer, naturally) and how to enable it via the Symfony kernel configuration. He then includes an example of the fixture loader class from the FOSUserBundle and how it works. Next up is the installation of the Behat Symfony 2 extension and a bit of extra code to make a new feature context for Behat containing a "loadDataFixtures" method to do the heavy lifting.

tagged: fixture symfony application behat load extension bundle tutorial

Link: https://robertbasic.com/blog/loading-fixtures-for-a-symfony-app-in-behat-tests/

Alejandro Celaya:
Managing PUT requests with file uploads in psr-7 and middleware PHP applications
Mar 07, 2017 @ 13:17:01

Alejandro Celaya has posted a new tutorial to his site covering the handling of PUT requests in PSR-7 applications for file uploads via middleware.

It has been a long time since I first realized that handling file uploads in non-POST requests (like PUT) wasn't an easy task. One could assume the $_FILES array should be populated regardless the HTTP verb, but actually, PHP doesn't do it on its own.

After a long time wanting to find a solution to this problem, I've finally dedicated the time to get something functional, that allows file uploads to be transparently handled regardless the HTTP verb (it works the same way in POST, PUT and PATCH requests).

Since nowadays I try to work with psr-7/middleware based applications, I have created a Zend Expressive app that registers a middleware capable of parsing a multipart/form-data request body, populating the request's uploaded files array and parsed body array. This way, you can call $request->getUploadedFiles() or $request->getParsedBody() in any PUT or PATCH action, the same way you would do in a POST action.

His example application shows a simple HTML form that, when submitted, changes the HTTP request type based on a radio option selected at the bottom. He walks through the steps that the application takes to handle the upload via this middleware that makes it possible to work with the body of the PUT the same way as other requests. He goes through each part of the code that's required to make the middleware flow work and finishes up the post looking at a few other things to consider (like opting for POST over PUT for file uploads).

tagged: zendexpressive application tutorial psr7 middleware put request fileupload upload

Link: https://blog.alejandrocelaya.com/2017/03/06/managing-put-requests-with-file-uploads-in-psr-7-and-middleware-php-applications/

Codevate.com:
Driving user engagement by leveraging Disqus in Symfony-based web apps
Mar 06, 2017 @ 10:27:22

The Codevate blog has a tutorial posted by Chris Lush showing how to "drive user engagement" with Disquis in a Symfony-based application. He basically shows how to use commenting, with the help of Disquis, to encourage user participation with your content without having to build your own.

Engaging your audience is an ever-increasing concern when publishing content, since having a community that visitors can witness and interact with can help drive repeat traffic to your website. One such approach would be to let users write comments about your content, creating discussion that others can engage with. The temptation to implement your own comment system is strong since at a surface level it's a simple problem to solve, but to build a robust solution that can deal with moderation requirements such as banning & blocking users, editing comments, or just exploring related threads within a forum can easily turn your "users can write comments" requirement into another project in its own right.

Disqus to the rescue.

He starts by showing the benefits that using Disquis can provide to your site and outlines the steps required to get it up on your site. He then walks you through the process, step-by-step, of registering with the Disquis service, adding the code to your site and even integrating single sign-on with your own backend system.

tagged: user engagement disquis tutorial symfony application

Link: https://www.codevate.com/blog/15-driving-user-engagement-by-leveraging-disqus-in-symfony-based-web-apps

SitePoint PHP Blog:
How to Secure Laravel Apps with 2FA via SMS
Mar 01, 2017 @ 11:52:23

On the SitePoint PHP blog there's a new tutorial posted by author Younes Rafie showing you how to secure your Laravel application with 2FA (two-factor authentication) via SMS messages. In this example they make use of the Twilio SMS handling to send the message to the end user's device.

While everyone is concerned about their application’s security, few take it seriously and take the plunge. The first thing you’ll notice when learning about this is that two factor authentication (2FA) is the go-to solution as a first step.

Although there have been some serious problems with using text messages as a second factor, it’s definitely safer than a plain username and password combination, given that many users tend to use popular and easy to guess passwords for critical services such as payments, chat, emails, etc. In this article, we’re going to build two factor authentication into a Laravel application using Twilio SMS as the second factor.

The tutorial then starts by explaining what the end result will look like - a basic username/password login system that will require a code (from the SMS message) to continue into the account. They walk you through the creation of a new Homestead instance and installation/configuration of the new Laravel project. It then shows the updates you'll need to make to migrations and the models to handle the storage of the SMS tokens. It also shows the Blade templates to create the code entry view and error output in case of a code validation failure.

The tutorial then integrates Twilio's PHP SDK via a provider and provides a screencast of the end result.

tagged: laravel application security sms twofactor authentication

Link: https://www.sitepoint.com/secure-laravel-apps-2fa-via-sms/