Symfony 2.2 released

    Symfony 2.2 released today.

    The list of innovations from the official blog :

    • Console: Auto-complete at the command line;
    • Console: Progress bar for long tasks;
    • Console: Hide passwords in command line mode;
    • Console: The offer to the user to choose from the list of possible options;
    • Finder: Filtering along the way;
    • Finder: glob syntax support in in () method;
    • Finder: Increase speed on some platforms;
    • HttpKernel: New sub-framework for managing resource fragments;
    • HttpKernel: Improved output of fatal errors;
    • HttpKernel: Logging of obsolete calls;
    • Process: Obtaining intermediate results of running processes;
    • Process: restarting the process;
    • Process: Obtaining the status of an executing process;
    • Routing: Support for URL hosts during routing;
    • Routing: Relative URLs for the scheme and path;
    • Security: Interesting security utilities;
    • Validators: Validators related to payment systems;
    • FrameworkBundle: Performance improvement for functional tests;
    • FrameworkBundle: Caching static pages.

    Also in Symfony 2.2, two components were extracted from existing code:
    • PropertyAccess;
    • Stopwatch

    Further - in more detail about some changes.



    PropertyAccess provides access to the fields of structures (arrays, objects), including hierarchical ones. The component code was extracted from the Form component into a separate component, because It turned out to be a very convenient standalone tool that can be used both in Symfony and separately from it.

    The method getValue($objectOrArray, $propertyPath)receives a value from an array or object in accordance with $propertyPath:
    use Symfony\Component\PropertyAccess\PropertyAccess;
    // ...
    $row = array();
    $accessor = PropertyAccess::getPropertyAccessor();
    // $row[] = $item[firstName];
    $row[] = $accessor->getValue($item, '[firstName]');
    // $row[] = $item->getFirstName()
    $row[] = $accessor->getValue($item, 'firstName');
    // $row[] = $item[user][firstName];
    $row[] = $accessor->getValue($item, '[user][firstName]');
    // $row[] = $item->getUser()->getFirstName()
    $row[] = $accessor->getValue($item, 'user.firstName');

    When accessing objects, the method receives the value of the first existing of the following methods:

    There is and setValue($objectOrArray, $propertyPath, $value)that sets the value to $propertyPath.

    This is necessary, first of all, when there is a need for making paths to variables or parameters. For example, to display these structures in a table .


    A stopwatch (although more likely a microsecond) can be very useful for debugging. It was extracted from HttpKernel, and is now available through a service container in development mode.

    So it can be used in the controller:
    if ($this->has('debug.stopwatch')) {
        $stopwatch = $this->get('debug.stopwatch');
    // ...
    // ...
    // ...
    $event = $stopwatch->stop('foo');

    The measured gaps appear in the Symfony profiler.

    Component Changes

    File Search (Finder)

    // До версии 2.2 можно было искать файлы по шаблону glob или regexp
    // Теперь это доступно и для директорий
    // Синтаксис glob доступен в методе in()

    Finder performance has also improved, as criteria are now converted to native Linux, BSD, and MacOS commands.


    URL Generation

    Prior to version 2.2, it was possible to generate two kinds of URLs.

    // Twig
    {{ url('blog', { post: 'what-a-wonderful-world' }) }}
    // PHP
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'), true);
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::ABSOLUTE_URL);

    URL relative to the domain (default): /blog/what-a-wonderful-world
    // Twig
    {{ path('blog', { post: 'what-a-wonderful-world' }) }}
    // PHP
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'));
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::ABSOLUTE_PATH);

    Now you can generate two more types of URL:

    URL relative to the scheme://
    // Twig
    {{ url('blog', { post: 'what-a-wonderful-world' }, true) }}
    // PHP
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::NETWORK_PATH);

    URL relative to the path: ../
    // Twig
    {{ path('blog', { post: 'what-a-wonderful-world' }, true) }}
    // PHP
    $generator->generate('blog', array('post' => 'what-a-wonderful-world'), UrlGeneratorInterface::RELATIVE_PATH);

    Host Dependent Routes

    Now you can set routes for specific hosts and use their templates:

        path: /
        host: "{user}"
        defaults: { _controller: AcmeDemoBundle:User:profile }
        path:  /
        defaults: { _controller: AcmeDemoBundle:Main:homepage }

    The processes

    To start external processes, in addition to the method run()(which takes the lambda function as an argument for data processing), it became possible to start the process by the method start()and receive data using the method getOutput(). In addition, you can use the getIncrementalOutput () method, which returns new data from the process from a previous call to this method.

    use Symfony\Component\Process\Process;
    $process = new Process('ls -lsa');
    $process->run(function ($type, $data) {
        echo $data;

    Now you can do this:
    use Symfony\Component\Process\Process;
    $process = new Process('ls -lsa');
    while ($process->isRunning()) {
        echo $process->getIncrementalOutput();

    Added methods for getting errors getErrorOutput()and getIncrementalErrorOutput().

    The list of methods for obtaining process status has also been expanded:
    // в версии 2.2


    Now we are waiting for the first LTS version of Symfony 2, which will be released in late May and will be supported for two years.

    Also popular now: