New Features in Symfony 3.2: Workflow Component, Twig & Other Changes

Symfony has rapidly become the framework of choice for web development apps and projects. Two important reasons behind the popularity are the frequent updates to the framework and the addition of new components. The result is a lightweight framework that is has taken the world by storm.

The latest news is the release of Symfony 3.2. This release introduces several important areas including caching, profiling and validations processes. I will discuss several important changes that distinguish this update.

How to Install Symfony 3.2 with Composer

The first important update is the way in which Symfony is installed. In several previous articles, I have highlighted Composer as the best option for installing any package, library or framework. You can install Symfony 3.2 with the following SSH command.

This command will install the stable release of Symfony 3.2. Once the installation finishes, go to the project’s folder and run the following command to start the server.

ssh

1

$php bin/console server:run

This will start the server and highlight the localhost port in use like this

Open the mentioned URL (http://127.0.0.1:800) in the browser. You will see the new welcome page of Symfony 3.2.

I will now discuss the new components and features introduced in Symfony 3.2.

The All New Workflow Component

Symfony 3.2 has introduced a new component called Workflow . A workflow is the set of processes and procedures that are used in a development environment for automation and production. The workflows are always repeated actions and are scheduled recursively. The Workflow component works with two event features State And Transitions. To use this component, you should first install it through the following command

ssh

1

$composer require symfony/workflow

This command will enable the component. To further read about this component, check out these excellent examples by Javier Eguiluz and eleven labs.

Improved Features In Symfony 3.2

Symfony 3.2 has introduced several important changes in key areas of the framework. The complete list is available on the Symfony website . I will now demonstrate several highlight changes with the pull request code.

Form

These are some of the highlights of the improvements introduced in Symfony 3.2. For a more detailed look at all the improvements and changes, check out the official Symfony Announcement.

Support for Symfony 3.2

One of the most important headache for PHP framework users is the duration of support for a particular version. The support for Symfony 3.1 will end in July 2017. After this date, developers should either upgrade or re-code their apps in Symfony 3.2.

For Symfony 3.2, the proposed support roadmap is:

Upgrade from Symfony 3.1 to 3.2

With every new version, developers rush to make their projects compatible with the new release. The problem with new release is that some features and components of the previous releases are no longer supported.

I will now discuss the features that Symfony 3.2 has dropped from the lineup. I will also mention the require command for including these packages through Composer.

FrameworkBundle

Removed Dependency

Require Command

doctrine/annotations

composer require doctrine/annotations

symfony/security-core & symfony/security-csrf

composer require symfony/security-core & symfony/security-csrf

symfony/templating

composer require symfony/templating

symfony/translation

composer require symfony/translation

symfony/asset

composer require symfony/asset

Resources/public/images/* files

–

Resources/public/css/*.css files

Inlined in twig Bundle

BrowserKit

Client HTTP user agent has been changed to Symfony BrowserKit.

DependencyInjection

Calling get() on a ContainerBuilder instance before compiling the container is deprecated.

Form

The Calling of isValid() on a Form instance before submitting is deprecated:

Previously:

php

1

2

3

if($form->isValid()){

// ...

}

After:

php

PHP

1

2

3

if($form->isSubmitted()&&$form->isValid()){

// ...

}

DataCollector::varToString() is deprecated and will be removed in Symfony 4.0. Use the cloneVar() method instead.

Surrogate name in a Surrogate-Capability HTTP request header has been changed to ‘symfony’.

Before:

Surrogate-Capability: symfony2=”ESI/1.0″

After:

Surrogate-Capability: symfony=”ESI/1.0″

Validator

Tests\Constraints\AbstractConstraintValidatorTest has been deprecated and now becomes Test\ConstraintValidatorTestCase.

Setting the strict option of the Choice Constraint to false has been deprecated and the option will be changed to true as of 4.0

php

PHP

1

2

3

4

5

6

7

8

useSymfony\Component\Validator\Constraints asAssert;

classMyEntity

{

/**

* @Assert\Choice(choices={"MR", "MRS"}, strict=true)

*/

private$salutation;

}

Yaml

Support for silently ignoring duplicate mapping keys in YAML has been deprecated and will lead to a ParseException in Symfony 4.0.

Mappings with a colon (:) that is not followed by a whitespace are deprecated and will lead to a ParseException in Symfony 4.0 (e.g. foo:bar must be foo: bar).

Conclusion

Symfony 3.2 offers a host of improvements and new features for web development projects. The new version addresses many issues that plagued previous versions of Symfony. Developers must visit the official documentation for in depth look at the new introductions. If you would like to contribute to the discussion, please leave a comment below.

Start Creating Web Apps on Managed Cloud Servers Now!

About Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways – A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com