Upgrade to Symfony 4.0

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

With the deprecations gone... yeah! It's time to upgrade to Symfony 4! If you were hoping this was going to be really cool and difficult... sorry. It's super easy... well... mostly easy.

Open composer.json and change symfony/symfony to ^4.0. There are a few other libraries that start with symfony/, but they're independent and follow different release cycles. Oh, except for symfony/phpunit-bridge: change that to ^4.0 also.

68 lines composer.json
... lines 1 - 15
"require": {
... line 17
"symfony/symfony": "^4.0",
... lines 19 - 30
},
"require-dev": {
... line 33
"symfony/phpunit-bridge": "^4.0",
... lines 35 - 36
},
... lines 38 - 68

Let's do this! Find your terminal and run:

composer update

Yep, upgrading is just that easy! Except... there are almost definitely some libraries in our composer.json file that are not yet compatible with Symfony 4. The best way to find out is just to try it! And then wait for an explosion!

Removing Alice

Ah! Here is our first! Look closely... this is coming from nelmio/alice: the version in our project is not compatible with Symfony 4. If we did some digging, we would find out that there is a new version of Alice that is compatible. But, that version also contains a lot of changes to Alice... and I don't like the library's new version very much. At least, not at this moment.

So, instead of upgrading, remove alice from composer.json. This will break our fixtures: we'll fix them later.

Update again!

composer update

Removing Outdated Libraries

Our next explosion! This comes from incenteev/composer-parameter-handler. This library helps you manage your parameters.yml file and... guess what? When we finish upgrading, that file will be gone! Yep, we do not need this library anymore.

Remove it from composer.json. Oh, also remove the distribution bundle: it helps support the current directory structure, and isn't needed with Flex. And below, remove the generator bundle. We'll install the new MakerBundle later.

Ok, update again!

composer update

When a Library is not Ready: StofDoctrineExtensionsBundle

It works! I'm just kidding - it totally exploded again. This time the culprit is StofDoctrineExtensionsBundle: the version in our project is not compatible with Symfony

  1. Now... we become detectives! Maybe the library supports it in a new version? Let's find out.

Google for StofDoctrineExtensionsBundle to find its GitHub page. Check out the composer.json file. It does support Symfony 4! Great! Maybe there's a new version that has this! Check out the releases. Oof! No releases for a long, long time.

This means that Symfony 4 support was added, but there is not yet a release that contains that code. Honestly, by the time you're watching this, the bundle probably will have a new release. But this is likely to happen with other libraries.

Actually, another common problem is when a library does not have Symfony 4 support, but there is an open pull request that adds it. In both situations, we have a problem, and you have a choice to make.

First... you can wait. This is the most responsible decision... but the least fun. I hate waiting!

Second, if there is a pull request, you can use that fork as a custom composer repository and temporarily use that until the library merges the pull request and tags a release. For example, imagine this pull request was not merged. We could add this as a vcs repository in composer.json, and then update the version constraint to dev-master, because the branch on the fork is master.

And third, since the pull request is merged, but there is no tag, we can simply change our version to dev-master. Believe me: I am not happy about this. But I'll update it later when there is a release.

70 lines composer.json
... lines 1 - 15
"require": {
... lines 17 - 27
"stof/doctrine-extensions-bundle": "dev-master"
},
... lines 30 - 70

Try to update again:

composer update

Ha! Look! It's actually working! Say hello to our new Symfony 4 app! Woohoo!

Upgrading old Packages

Oh, but check out that warning: the symfony/swiftmailer-bridge is abandoned. I don't like that! Hmm, I don't see that package in our composer.json file. Run:

composer why symfony/swiftmailer-bridge

Ah! It's required by symfony/swiftmailer-bundle. We're using version 2.3.8, which is apparently compatible with Symfony 4. But I wonder if there's a newer version?

Tip

Actually, version 2.3.8 is not compatible with Symfony 4. But due to an old issue with its composer.json file, it appears compatible. Be careful with old libraries!

Google for the package to find its GitHub page. Click releases.

Woh! There is a new version 3 of the bundle. And I bet it fixes that abandoned packages issue. Change our version to ^3.1.

70 lines composer.json
... lines 1 - 15
"require": {
... lines 17 - 21
"symfony/swiftmailer-bundle": "^3.1",
... lines 23 - 28
},
... lines 30 - 70

And now, update!

composer update

Because we're upgrading to a new major version, you'll want to check out the CHANGELOG on the project to make sure there aren't any major, breaking changes.

Yes! Abandoned package warning gone! And our project is on Symfony 4. Not bad!

But... get ready... because now the real work starts. And the fun! It's time to migrate our project to the Flex project structure!

Leave a comment!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.1.3",
        "doctrine/doctrine-bundle": "^1.6", // 1.8.1
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.2
        "doctrine/doctrine-migrations-bundle": "^1.1", // v1.3.1
        "doctrine/orm": "^2.5", // v2.7.2
        "fzaninotto/faker": "^1.7", // v1.7.1
        "knplabs/knp-markdown-bundle": "^1.4", // 1.6.0
        "sensio/framework-extra-bundle": "^5.0", // v5.1.3
        "stof/doctrine-extensions-bundle": "dev-master", // dev-master
        "symfony/asset": "^4.0", // v4.0.1
        "symfony/console": "^4.0", // v4.0.1
        "symfony/flex": "^1.0", // v1.0.49
        "symfony/form": "^4.0", // v4.0.1
        "symfony/framework-bundle": "^4.0", // v4.0.1
        "symfony/lts": "^4@dev", // dev-master
        "symfony/maker-bundle": "^1.0", // v1.0.2
        "symfony/monolog-bundle": "^3.1", // v3.1.2
        "symfony/polyfill-apcu": "^1.0", // v1.6.0
        "symfony/profiler-pack": "^1.0", // v1.0.3
        "symfony/security-bundle": "^4.0", // v4.0.1
        "symfony/security-csrf": "^4.0",
        "symfony/swiftmailer-bundle": "^3.1", // v3.1.6
        "symfony/translation": "^4.0", // v4.0.1
        "symfony/twig-bundle": "^4.0", // v4.0.1
        "symfony/validator": "^4.0", // v4.0.1
        "symfony/web-server-bundle": "^4.0", // v4.0.1
        "symfony/yaml": "^4.0" // v4.0.1
    },
    "require-dev": {
        "symfony/dotenv": "^4.0", // v4.0.1
        "symfony/phpunit-bridge": "^4.0", // v4.0.1
        "doctrine/doctrine-fixtures-bundle": "^3.0" // 3.0.2
    }
}