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

Symfony Finland:
Porting a Symfony 3 application to Flex
Jun 26, 2017 @ 11:42:12

On the Symfony Finland site they've posted a retrospective about moving an application from Symfony 3 to Flex including the work that was done in the switch and the performance of the result.

Earlier this year I did some experimenting with a Hybrid state object between Symfony Twig templates and front end JavaScript frameworks. Since that time I did that experiment, the Symfony Flex project has progressed. I thought I would try how to port the state prototype to Symfony Flex.

[...] In my case the application was rather simple and all built in the AppBundle, which is best-practise in Symfony3 for many applications. I mostly had to move files and configurations around and change namespaces.

He starts by spending some time talking about the difference between a Symfony 3 environment and the environment Flex provides. He then goes through the eight or so steps to move from one to the other including file/directory changes and configuration updates. Next comes the look at performance differences between the two. Unsurprisingly Flex came out on top in every measurement he threw at it.

In addition to the new structure, the apparent improvement in performance is obviously welcome. This would likely be even more evident where I could leave more dependencies out, for example in API workloads. This obviously won't magically push Symfony/PHP into Golang or Node.js territory for raw API throughput, but for existing large code bases it could provide a low-effort boost.
tagged: symfony symfony3 symfonyflex migration performance benchmark process tutorial

Link: https://symfony.fi/entry/porting-a-symfony-3-application-to-flex

Symfony Blog:
Introducing Webpack Encore for Asset Management
Jun 13, 2017 @ 11:08:19

On the Symfony blog they've released an announcement about the release of a tool that wants to help make it easier for Symfony developers to work with frontend resources using the Webpack standard: Webpack Encore.

For everyone that has hit [the barrier of complexity in frontend dependencies and compilation], I'm very excited to show you something we've been working on for the last few months: Webpack Encore.

Encore gives you powerful CSS and JavaScript processing, combination, minification and a lot more, wrapped up in a simple API that's built on an industry-standard tool (Webpack).

He includes an example of the Javascript configuration to build out the Javascript, CSS and dependencies required for his build. He talks briefly about the conformity to the Webpack handling and how Encore fills that role in Symfony applications. The post ends linking to the project repository and the changes required to get the package installed.

tagged: webpack symfony encore library configuration frontend library dependency tool

Link: http://symfony.com/blog/introducing-webpack-encore-for-asset-management

CloudWays Blog:
Taylor Otwell Wants You To Build Your PHP Apps On Laravel
Jun 02, 2017 @ 09:47:26

On the Cloudways blog they've posted another in their series of interviews with members of the PHP community. In this latest article they talk with Taylor Otwell, the creator and lead developer of the Laravel framework.

Even today, PHP developers face the tough question of which framework to choose for their next project. The choice has largely been restricted to a handful of frameworks, out of which Laravel and Symfony stand out of the competition.

To clarify the situation, I reached out to Taylor Otwell, the creator of the Laravel framework to clarify some of the important points of the debate. This interview covers Otwell’s opinions on Laravel vs. Symfony debate and the competition between PHP and JavaScript.

In the interview Taylor answers questions about:

  • selecting a framework (Symfony vs Laravel)
  • the differences between the two frameworks and their usual audiences
  • workflow automation with Laravel
  • framework release cycles
  • the communities around each framework

You can read Taylor's answers to these and other questions in the full interview.

tagged: cloudways community interview taylorotwell laravel symfony

Link: https://www.cloudways.com/blog/taylor-otwell-interview/

Stefan Koopmanschap:
The idempotent command
May 31, 2017 @ 13:33:05

In a new post to his site Stefan Koopmanschap covers the creation of idempotent commands, that is, commands that can only run one at a time without having to worry about possible overlap.

One of the things you may run into these days (and that I had to solve this week) is that these days we provision all servers similarly (or according to their role). This may also mean that you provision several of your servers to run the same cronjobs at the same time. However, some tasks may not be run multiple times, and especially not at the same time. In a symfony project I'm working on, I was tasked with making sure some of the cronjobs would only be run once, even if started on several servers at the same time.

He then goes through the process he followed for adding in the locking making use of the console.command and console.terminate hooks in the Symfony Command component. He then made use of the arvenil/ninja-mutex package to do the actual locking. He works through his decision process on when to lock and how to detect which commands needed to be locked. He ends the post with the code for the listener to create and release the lock automagically when the command has finished.

tagged: idempotent command symfony example locking

Link: https://leftontheweb.com/blog/2017/05/30/The-idempotent-command/

SitePoint PHP Blog:
Re-Introducing Symfony Console – CLI PHP for the Uninitiated!
May 25, 2017 @ 11:38:02

The SitePoint PHP blog has posted a tutorial from author Claudio Ribeiro that wants to re-introduce you to the Symfony Console package, a component of the larger Symfony framework that makes it easier to create and work with command-line PHP scripts.

As software developers, we often feel the need to resort to command line tools. These kinds of tools are helpful when we need to do a sort of recurring task like migrating data, performing imports, or creating cron jobs.

The Symfony Console component tool provides us with a simple framework to create our own command line tools. Unlike many components in Symfony, this is a standalone package and is used by the likes of Laravel‘s Artisan and many other famous PHP packages.

The tutorial then walks you through the installation process, via Composer, and the creation of a new command. With this simple base created, he then adds in actual functionality, building out a command to hash and verify a password string. They show how to use the command and an example of its output. Next up, he creates another command example, this time verifying the password hash provided as an argument. The tutorial wraps up with a look at testing your console comamnds with PHPUnit tests via the included CommandTester functionality.

tagged: symfony console commandline cli package component tutorial introduction

Link: https://www.sitepoint.com/re-introducing-symfony-console-cli-php-uninitiated/

Symfony Blog:
The new Symfony 3.3 Service Configuration Changes Explained
May 23, 2017 @ 10:15:27

On the Symfony blog, there's an article posted by Ryan Weaver helping to explain the new service configuration changes that are included with version 3.3 of the framework.

In less than 2 weeks, Symfony 3.3 will be released. It comes with a lot of new stuff, but there is one feature that stands out: the new service configuration. I am very excited about these changes: they're designed to accelerate development, make Symfony easier to learn and encourage best-practices (e.g. injecting specific dependencies instead of using $container->get())... without sacrificing predictability and stability.

The post includes an example of what the new configuration file format will look like and briefly explains some of the changes. For those interested in a more in-depth look, they also link to this page in the Symfony documentation that goes through the changes step by step. It covers the autowiring by default, autoload of services, controllers being registered as services and more. If you're planning on making the move up to v3.3 when it's released (or sometime after) definitely check out this guide to make the transition easier.

tagged: symfony framework service configuration changes explained documentation

Link: http://symfony.com/doc/master/service_container/3.3-di-changes.html

Symfony Blog:
Preparing your Applications for PHP 7 with Symfony Polyfills
May 19, 2017 @ 11:07:50

The Symfony blog has posted an article showing you how to prepare your applications for a migration to PHP 7 with the help of various polyfill libraries. These libraries make it possible to use PHP 7 functionality in non-PHP 7 applications if the function in use isn't defined.

According to the May 2017 PHP Stats, 53% of PHP developers use PHP 7.0 or 7.1, but only 10% of Composer packages require PHP 7.0 or higher. In fact, 1 in 4 packages still require PHP 5.3, which is used by less than 1% of developers.

[...] Upgrading your development machines is usually a simple task, but upgrading the rest of the infrastructure (servers, tools, etc.) usually requires more resources. This is where Symfony Polyfills can help you preparing the code of your application for PHP 7.

The article briefly explains what polyfills are and how to load in the current Symfony set via a Composer install. There've provided functionality for PHP versions 5.4 through 5.6 as well as PHP 7.0 and 7.1 to ensure you have the most up to date functionality at your fingertips.

tagged: php7 application symfony polyfill library functionality composer tutorial

Link: http://symfony.com/blog/preparing-your-applications-for-php-7-with-symfony-polyfills

Fabien Potencier:
Symfony 4: Contributing Recipes
Apr 19, 2017 @ 10:23:34

Fabien Potencier has posted another in his series of tutorials looking at the next major release of the Symfony framework - Symfony v4. In this series he's covered some of the changes that will be coming in this release and what you can do to prepare. In this latest post he looks at the idea of "recipes" and how you can contribute them back to the project

Symfony Flex is not Open-Sourced yet, but I can already feel the excitement in the community. [...] You know, that "one more feature" that will make Symfony Flex the next killer application for the Symfony community.

People are worried about the opinionated recipe repository. Keep in mind that one of the main goals of Symfony Flex is to automate your day-to-day workflow for the happy path.

He reassures those reading the post that a package doesn't need a recipe to be installed and the "opinions" that the main repository uses around packages. He also talks about another recipe configuration option not mentioned previously: aliases. These allow for shortened versions of the Composer installation commands that are easier to remember than the full package name. He covers a bit about how it works in Flex and the process it follows behind the scenes when installing the package.

tagged: symfony4 symfony contribute recipe framework symfonyflex

Link: http://fabien.potencier.org/symfony4-contributing-recipes.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