4 How News in Symfony 3

In November 2015 except for a PHP 7 and Drupal 8, Symfony 3 is about to come.

What changes and news it brings?

Symfony already knows that a lot. The new version places great emphasis on the DX (developer experience). It brings us a simpler and more straightforward API, better decoupled components, standards PSR-3 and PSR-7 integration. A lot of other innovations that will make writing applications just got more fun.

When is What Version Out?

Have you migrated from Symfony 1 to 2 and do you want to avoid a similar massacre? Don't worry - although there are lot of news, Symfony now respects backward compatibility promise.

Migration Symfony 2 to 3 will be greatly simplified by the fact that along with the version 3 will be released and version 2.8. It will have all the new feature in version 3 and will include BC layer to the 2.x series. Version 2.8 will be long term supported (LTS) - so you can count on the support until the end of 2018.



Version 2.8 will LTS. The first LTS new series will be up to 3.3 (to be released in May 2017).


What are the 2 main differences between 3.0 and 2.8 then?

And now The Most Expected 4 News

1. Service Autowiring

See pull-request

Symfony now supports constructor autowiring. When you are creating a service definition so you can turn on autowiring and skip the manual passing arguments.

Autowiring is quite popular in the Czech Republic due to bundles like Skrz or Kutny

How it looks like in practice?

Earlier long registration

# services.yml 

services:
    myService:
        class: MyBundle\MyService
        arguments: [ @dependency1, @dependency2 ]

    dependency1:
        class: MyBundle\Dependency1

    dependency2:
        class: MyBundle\Dependency2

Now you can cut to

# services.yml

services:
    myService:
        class: MyBundle\MyService
        autowiring: true

How does it work?

Dependency Injection container analyze constructor and services:

What about the interface?

Instead of a specific type of service you require an interface that implements the service. But what if we have multiple services to one interface (typical chain pattern)? Just for the service explicitly state:

# services.yml

services:   
    dependency1:
        class: MyBundle\Dependency1
        autowiring_types: MyBundle\MyInterface

2. More Logical Folders

Symfony 3 full-stack brings order. Get rid of chaos in the /app folder.

How?

Temporary files, logs, settings for PHPUnit, console files...

All this is now obvious location separate from the code of our application.



Tests you can run simply in command line via vendor/bin/phpunit.


3. Symfony Profiler in a New Jacket

See pull-request

For the programmer it is important not only to clear the code, but also arranged the meta-information about the application. Those in Symfony easily displayed using Symfony Profiler.

He had displayed so much information that it began to lose programmer. After 4 years he has finally made flat design.

Important information and above all error messages are now much easier to read.





Easy to get from profiler back to page

4. Micro Kernel

See pull-request

Great joy will have smaller applications developers, who enjoy the comfort of the ecosystem full-stack Symfony. A few days ago, on November 5, was added to FrameworkBundle Micro Kernel.

That is precisely suited to applications that require simple configuration, bundle and that Silex enough.

Micro Kernel namely:

How does the Micro Kernel looks like?

<?php

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;

class ConcreteMicroKernel extends Kernel
{
    use MicroKernelTrait;

    public function halloweenAction()
    {
        return new Response('halloween');
    }

    public function registerBundles()
    {
        return [new FrameworkBundle()];
    }

    protected function configureRoutes(RouteCollectionBuilder $routes)
    {
        $routes->add('/', 'kernel:halloweenAction');
    }

    protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader)
    {
        $containerBuilder->loadFromExtension('framework', [
            'secret' => '$ecret',
        ]);

        $containerBuilder->setParameter('title', 'Symfony 3 is painless');
    }
}

Now you know...

In Symfony they Know...

When the programmer may resort to more simple solution, he or she will.

Therefore, they are trying to use it without its obstacles.




What do you think?