The release of the PHP framework Yii version 2.0.11. Instructions for upgrading and installing can be found on the official website . Version 2.0.11 contains more than 110 improvements and fixes .
Four small changes may affect existing applications, so pay attention to UPGRADE.md .
Many thanks to our wonderful community . We did it together!
The development process of Yii 2 can be monitored by placing an asterisk on GitHub . We also have Twitter and Facebook .
Since we are already working on Yii 2.1 , make sure that the version of the framework in composer.json
spelled as ~2.0.11
. Otherwise, after the release of 2.1 project may break.
Next we look at the most interesting changes and improvements included in the release. A full list is available at CHANGELOG .
We decided not to accept pull requests without tests with rare exceptions. This should improve the quality of the code and reduce the time spent on checking it. More than half of the pull requests for 2.0.11 were made according to this decision.
Some tests, such as tests for the URL manager, have undergone significant refactoring. The methods have become smaller, it has become easier to read them.
Alexey Rogachev did significant work on refactoring, correcting and covering the JavaScript part of the framework with tests.
In the Bash and Zsh console, it became quite simple to organize a supplement for the ./yii
. Setup is described in the manual .
In addition, when typing errors, the console prompts existing commands with similar spelling.
It became possible to set globally the storage duration of the data in the cache via yii\caching\Cache::$defaultDuration
.
A convenient syntax has appeared:
$data = $cache->getOrSet($key, function () { return $this->calculateSomething(); });
The code above does the same as:
$data = $cache->get($key); if ($data === false) { $data = $this->calculateSomething(); $cache->set($key, $data); }
After lengthy discussions, it was decided to add the ability to customize the dependency container through the main application configuration:
$config = [ 'id' => 'basic', // ... 'container' => [ 'definitions' => [ 'yii\widgets\LinkPager' => ['maxButtonCount' => 5] ], 'singletons' => [ ], ], ];
More information about this feature can be found in the “ application configurations ” section of the official manual.
With each release to make development more enjoyable, we try to make mistakes all the more useful and accurate. 2.0.11 is no exception. Now the error when trying to access a non-existent component reports that this is exactly what happened. Previously, the framework cursed the impossibility of automatic class loading.
Two methods have been added to the controller: asJson()
and asXml()
. They serve to return data in JSON and XML, respectively.
0=1
, which were used for communications in AR.Another improvement does not directly affect performance, but will definitely help increase it in applications. We started logging memory usage and route mapping. Expect the corresponding panels in the next debug module release.
Three new methods have been added to yii\db\Query
: filterHaving()
, andFilterHaving()
and orFilterHaving()
. They are similar to the other filter*
methods that add a condition only if the value is not empty and is usually used for various filters.
The yii\db\Connection
class yii\db\Connection
become more pleasant to use in the case of master-slave configurations:
shuffleMasters
, with which you can disable the random selection of the master connection.getMaster()
method and master
property. They allow you to get the current active master connection.\yii\db\Query
can now be passed to insert()
either directly as a second argument, or as the value of one of the parameters:
$db = Yii::$app->db; // query $sourceQuery = new \yii\db\Query() ->select([ 'title', 'content', ])->from('{{post_queue}}'); $command = $db->createCommand(); $command->insert('{{post}}', $sourceQuery); // query $titleQuery = new \yii\db\Query() ->select('title')->from('{{titles}}')->limit(1); $command = $db->createCommand(); $command->insert('{{post}}', [ 'title' => $titleQuery, 'content' => '!', ]);
We are constantly checking the framework for compatibility with PHP 7. By 2.0.11, we found and fixed a problem related to error handling and Throwable
.
When generating URLs via UrlManager::createAbsoluteUrl()
, Url::to()
or Url::toRoute()
you can now specify the scheme as empty for creating protocol-independent URLs:
echo Url::to('@web/images/logo.gif', ''); // //www.example.com/images/logo.gif
Also, when generating URLs, the parameters for which there are default values become optional:
echo Url::to(['post/index', 'page' => 1, 'tag' => '']); // : echo Url::to(['post/index', 'page' => 1]);
Widget extensibility has been greatly improved. Added events during initialization, before the start of rendering and after its completion. For application examples, see issue .
The HostControl
filter was included in the HostControl
, with which you can prevent an attack by changing the host. Ideally, it is better not to allow the correct configuration of the web server, but since there were quite a lot of requests from those who do not have access to the configuration
server, decided to still include this filter in the framework. Details on setting up this filter can be found in the manual .
Also, a problem with screening data on the error page in debug mode was found and fixed. Since the problem does not affect the working server, we did not release a separate patch release.
Together with the release of the framework, we are releasing a new version 2.0.5 of the Composer installer . This Composer plugin is responsible for installing extensions and avoids configuration during bootstrapping . He also performs various tasks when creating a new project. Thanks to Robert Korulczyk , it became possible to perform tasks with composer install
, which is especially important for processing local configuration files, which can now be copied using the new copyFiles
method. More details can be read in the README .
Also, the plugin started when updating the yiisoft/yii2
notify about important changes from UPGRADE.md .
This is the first release, with a signed GPG tag, which allows you to verify that it was made by the Yii team. Later we will post detailed verification instructions.
On GitHub, signed tags can be distinguished by the words "verified": https://github.com/yiisoft/yii2-framework/releases/tag/2.0.11 .
Source: https://habr.com/ru/post/320906/
All Articles