📜 ⬆️ ⬇️

Symfony 2.2 Released

Symfony 2.2 has been released today.

List of innovations from the official blog :


Also in symfony 2.2, two components were identified from the existing code:

Further - in more detail about some changes.

Components


PropertyAccess

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, since It turned out to be a very convenient independent tool that can be used both in symfony and separately from it.
')
The getValue($objectOrArray, $propertyPath) method getValue($objectOrArray, $propertyPath) gets the value from an array or object according to $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 gets the value of the first existing of the following methods:
 $item->getProp(); $item->isProp(); $item->hasProp(); $item->__get('prop'); $item->prop; 

There is also setValue($objectOrArray, $propertyPath, $value) , which sets the value to $propertyPath .

It is necessary, first of all, when there is a need to pass paths into variables or parameters. For example, to output data structures in the form of a table .

Stopwatch

A stopwatch (although, rather, a microsecond) can be quite useful when debugging. It was extracted from HttpKernel, and is now available through the service container in development mode.

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

The measured intervals are displayed in the symfony profiler.

Component Changes


File Finder

 //   2.2       glob  regexp Finder::create()->files()->name('*.php'); Finder::create()->files()->name('/\.php$/'); //       Finder::create()->path('some/special/dir'); Finder::create()->path('/^foo\/bar/'); //  glob    in() Finder::create()->files()->in('src/Symfony/*/*/Resources/translations'); 

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

Routing

URL generation

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

Absolute URL: example.org/blog/what-a-wonderful-world
 // 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 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 URLs:

URL relative to the scheme: //example.org/blog/what-a-wonderful-world
 // 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-specific routes

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

 user_homepage: path: / host: "{user}.example.com" defaults: { _controller: AcmeDemoBundle:User:profile } main_homepage: path: / defaults: { _controller: AcmeDemoBundle:Main:homepage } 

Processes

To start external processes in addition to the run() method (which takes the lambda function as an argument for data processing), it became possible to start the process using the start() method and get data using the getOutput() method. In addition, you can use the getIncrementalOutput () method, which returns new data from the process from the 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:
 use Symfony\Component\Process\Process; $process = new Process('ls -lsa'); $process->start(); while ($process->isRunning()) { echo $process->getIncrementalOutput(); sleep(1); } 

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

The list of methods for obtaining process status is also expanded:
 $process->isSuccessful(); $process->hasBeenSignaled(); $process->hasBeenStopped(); $process->isRunning(); //   2.2 $process->isStarted(); $process->isTerminated(); 


Lts


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.

Source: https://habr.com/ru/post/171243/


All Articles