Skip to content

Commit

Permalink
Merge branch 'master' into feature/extract-prepareCacheData-method-
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 authored Oct 28, 2023
2 parents dbb5c67 + fcd9e0a commit 870316e
Show file tree
Hide file tree
Showing 78 changed files with 3,770 additions and 1,210 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Autodetect text files
* text=auto
* text=auto eol=lf

# ...Unless the name matches the following overriding patterns

Expand Down
2 changes: 1 addition & 1 deletion docs/guide-ru/runtime-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ return [
Временная метка [IP-адрес][ID пользователя][ID сессии][Уровень важности][Категория] Текст сообщения
```

Этот формат может быть изменен при помощи свойства [[yii\log\Target::prefix]], которое получает анонимную функцию, возвращающую нужный префикс сообщения. Например, следующий код позволяет настроить вывод идентификатор текущего пользователя в качестве префикса для всех сообщений.
Этот формат может быть изменен при помощи свойства [[yii\log\Target::prefix]], которое получает анонимную функцию, возвращающую нужный префикс сообщения. Например, следующий код позволяет настроить вывод идентификатора текущего пользователя в качестве префикса для всех сообщений.

```php
[
Expand Down
250 changes: 126 additions & 124 deletions docs/internals-fa/core-code-style.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ Yii Framework 2 Change Log

2.0.50 under development
------------------------

- Bug #20045: Fix type `boolean` in `MySQL` (terabytesoftw)
- Bug #20040: Fix type `boolean` in `MSSQL` (terabytesoftw)
- Bug #20005: Fix `yii\console\controllers\ServeController` to specify the router script (terabytesoftw)
- Bug #19060: Fix `yii\widgets\Menu` bug when using Closure for active item and adding additional tests in `tests\framework\widgets\MenuTest` (atrandafir)
- Bug #13920: Fixed erroneous validation for specific cases (tim-fischer-maschinensucher)
- Bug #19927: Fixed `console\controllers\MessageController` when saving translations to database: fixed FK error when adding new string and language at the same time, checking/regenerating all missing messages and dropping messages for unused languages (atrandafir)
- Bug #20002: Fixed superfluous query on HEAD request in serializer (xicond)
- Enh #12743: Added new methods `BaseActiveRecord::loadRelations()` and `BaseActiveRecord::loadRelationsFor()` to eager load related models for existing primary model instances (PowerGamer1)
- Enh #20030: Improve performance of handling `ErrorHandler::$memoryReserveSize` (antonshevelev, rob006)
- Enh #20042: Add empty array check to `ActiveQueryTrait::findWith()` (renkas)
- Enh #20032: Added `mask` method for string masking with multibyte support (salehhashemi1992)


2.0.49.2 October 12, 2023
Expand Down
2 changes: 1 addition & 1 deletion framework/base/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function register()
set_error_handler([$this, 'handleError']);
}
if ($this->memoryReserveSize > 0) {
$this->_memoryReserve = str_pad('', $this->memoryReserveSize, 'x');
$this->_memoryReserve = str_repeat('x', $this->memoryReserveSize);
}
// to restore working directory in shutdown handler
if (PHP_SAPI !== 'cli') {
Expand Down
13 changes: 12 additions & 1 deletion framework/console/controllers/ServeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ public function actionIndex($address = 'localhost')
}
$this->stdout("Quit the server with CTRL-C or COMMAND-C.\n");

passthru('"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\" \"$router\"");
$command = '"' . PHP_BINARY . '"' . " -S {$address} -t \"{$documentRoot}\"";

if ($this->router !== null && $router !== '') {
$command .= " -r \"{$router}\"";
}

$this->runCommand($command);
}

/**
Expand Down Expand Up @@ -122,4 +128,9 @@ protected function isAddressTaken($address)
fclose($fp);
return true;
}

protected function runCommand($command)
{
passthru($command);
}
}
4 changes: 4 additions & 0 deletions framework/db/ActiveQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ protected function createModels($rows)
*/
public function findWith($with, &$models)
{
if (empty($models)) {
return;
}

$primaryModel = reset($models);
if (!$primaryModel instanceof ActiveRecordInterface) {
/* @var $modelClass ActiveRecordInterface */
Expand Down
41 changes: 33 additions & 8 deletions framework/db/mssql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ protected function resolveTableNames($table, $name)
*/
protected function loadColumnSchema($info)
{
$isVersion2017orLater = version_compare($this->db->getSchema()->getServerVersion(), '14', '>=');
$column = $this->createColumnSchema();

$column->name = $info['column_name'];
Expand All @@ -393,20 +394,21 @@ protected function loadColumnSchema($info)
if (isset($this->typeMap[$type])) {
$column->type = $this->typeMap[$type];
}

if ($isVersion2017orLater && $type === 'bit') {
$column->type = 'boolean';
}

if (!empty($matches[2])) {
$values = explode(',', $matches[2]);
$column->size = $column->precision = (int) $values[0];

if (isset($values[1])) {
$column->scale = (int) $values[1];
}
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';
} elseif ($type === 'bit') {
if ($column->size > 32) {
$column->type = 'bigint';
} elseif ($column->size === 32) {
$column->type = 'integer';
}

if ($isVersion2017orLater === false) {
$column->type = $this->booleanTypeLegacy($column->size, $type);
}
}
}
Expand Down Expand Up @@ -813,4 +815,27 @@ public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]);
}

/**
* Assigns a type boolean for the column type bit, for legacy versions of MSSQL.
*
* @param int $size column size.
* @param string $type column type.
*
* @return string column type.
*/
private function booleanTypeLegacy($size, $type)
{
if ($size === 1 && ($type === 'tinyint' || $type === 'bit')) {
return 'boolean';
} elseif ($type === 'bit') {
if ($size > 32) {
return 'bigint';
} elseif ($size === 32) {
return 'integer';
}
}

return $type;
}
}
2 changes: 1 addition & 1 deletion framework/db/mysql/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ protected function loadColumnSchema($info)
if (isset($values[1])) {
$column->scale = (int) $values[1];
}
if ($column->size === 1 && $type === 'bit') {
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';
} elseif ($type === 'bit') {
if ($column->size > 32) {
Expand Down
54 changes: 32 additions & 22 deletions framework/helpers/BaseFormatConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,13 @@ class BaseFormatConverter
* @param string|null $locale the locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`.
* If not given, `Yii::$app->language` will be used.
* @return string The converted date format pattern.
* @throws \Exception
*/
public static function convertDateIcuToPhp($pattern, $type = 'date', $locale = null)
{
if (isset(self::$_icuShortFormats[$pattern])) {
if (extension_loaded('intl')) {
if ($locale === null) {
$locale = Yii::$app->language;
}
if ($type === 'date') {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], IntlDateFormatter::NONE);
} elseif ($type === 'time') {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$_icuShortFormats[$pattern]);
} else {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], self::$_icuShortFormats[$pattern]);
}
$pattern = $formatter->getPattern();
$pattern = self::createFormatter($locale, $type, $pattern);
} else {
return static::$phpFallbackDatePatterns[$pattern][$type];
}
Expand Down Expand Up @@ -350,22 +341,13 @@ public static function convertDatePhpToIcu($pattern)
* @param string|null $locale the locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`.
* If not given, `Yii::$app->language` will be used.
* @return string The converted date format pattern.
* @throws \Exception
*/
public static function convertDateIcuToJui($pattern, $type = 'date', $locale = null)
{
if (isset(self::$_icuShortFormats[$pattern])) {
if (extension_loaded('intl')) {
if ($locale === null) {
$locale = Yii::$app->language;
}
if ($type === 'date') {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], IntlDateFormatter::NONE);
} elseif ($type === 'time') {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$_icuShortFormats[$pattern]);
} else {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], self::$_icuShortFormats[$pattern]);
}
$pattern = $formatter->getPattern();
$pattern = self::createFormatter($locale, $type, $pattern);
} else {
return static::$juiFallbackDatePatterns[$pattern][$type];
}
Expand Down Expand Up @@ -545,4 +527,32 @@ public static function convertDatePhpToJui($pattern)
'U' => '@', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
]);
}

/**
* Creates a date/time formatter based on the given parameters.
*
* @param string|null $locale The locale to be used. If null, the application's current language will be used.
* @param string $type The type of formatter ('date', 'time', etc.)
* @param string $pattern The pattern for the IntlDateFormatter.
*
* @return string The resulting pattern after formatter creation.
*
* @throws \Exception If the 'intl' extension is not loaded.
*/
private static function createFormatter($locale, $type, $pattern)
{
if ($locale === null) {
$locale = Yii::$app->language;
}

if ($type === 'date') {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], IntlDateFormatter::NONE);
} elseif ($type === 'time') {
$formatter = new IntlDateFormatter($locale, IntlDateFormatter::NONE, self::$_icuShortFormats[$pattern]);
} else {
$formatter = new IntlDateFormatter($locale, self::$_icuShortFormats[$pattern], self::$_icuShortFormats[$pattern]);
}

return $formatter->getPattern();
}
}
30 changes: 30 additions & 0 deletions framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,4 +497,34 @@ public static function mb_ucwords($string, $encoding = 'UTF-8')

return implode('', $parts);
}

/**
* Masks a portion of a string with a repeated character.
* This method is multibyte-safe.
*
* @param string $string The input string.
* @param int $start The starting position from where to begin masking.
* This can be a positive or negative integer.
* Positive values count from the beginning,
* negative values count from the end of the string.
* @param int $length The length of the section to be masked.
* The masking will start from the $start position
* and continue for $length characters.
* @param string $mask The character to use for masking. The default is '*'.
* @return string The masked string.
*/
public static function mask($string, $start, $length, $mask = '*') {
$strLength = mb_strlen($string, 'UTF-8');

// Return original string if start position is out of bounds
if ($start >= $strLength || $start < -$strLength) {
return $string;
}

$masked = mb_substr($string, 0, $start, 'UTF-8');
$masked .= str_repeat($mask, abs($length));
$masked .= mb_substr($string, $start + abs($length), null, 'UTF-8');

return $masked;
}
}
8 changes: 5 additions & 3 deletions framework/messages/af/yii.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
' and ' => ' en ',
'"{attribute}" does not support operator "{operator}".' => '"{attribute}" ondersteun nie operateur "{operator}" nie.',
'(not set)' => '(nie gestel nie)',
'Action not found.' => '',
'Aliases available: {aliases}' => '',
'An internal server error occurred.' => '\'n Interne bediener fout het plaasgevind.',
'Are you sure you want to delete this item?' => 'Is jy seker jy wil hierdie item skrap?',
'Condition for "{attribute}" should be either a value or valid operator specification.' => 'Voorwaarde vir "{attribute}" moet óf \'n waarde, óf \'n geldige operateurspesifikasie wees.',
Expand All @@ -43,10 +45,10 @@
'Only files with these extensions are allowed: {extensions}.' => 'Slegs hierdie soort lêers word toegelaat: {extensions}.',
'Operator "{operator}" must be used with a search attribute.' => 'Operateur "{operator}" moet gebruik word met \'n soekkenmerk.',
'Operator "{operator}" requires multiple operands.' => 'Operateur "{operator}" vereis veelvuldige operande.',
'Options available: {options}' => '',
'Page not found.' => 'Bladsy nie gevind nie.',
'Please fix the following errors:' => 'Maak asseblief die volgende foute reg:',
'Please upload a file.' => 'Laai asseblief \'n lêer op.',
'Powered by {yii}' => 'Aangedryf deur {yii}',
'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.' => '',
'The combination {values} of {attributes} has already been taken.' => 'Die kombinasie {values} van {attributes} is reeds geneem.',
'The file "{file}" is not an image.' => 'Die lêer "{file}" is nie \'n prent nie.',
Expand All @@ -68,7 +70,6 @@
'Update' => 'Opdateer',
'View' => 'Beskou',
'Yes' => 'Ja',
'Yii Framework' => 'Yii Raamwerk',
'You are not allowed to perform this action.' => 'Jy mag nie hierdie aksie uitvoer nie.',
'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.' => 'Jy kan \'n maksimum van {limit, number} {limit, plural, one{lêer} other{lêers}} oplaai.',
'You should upload at least {limit, number} {limit, plural, one{file} other{files}}.' => 'Jy moet ten minste {limit, number} {limit, plural, one{lêer} other{lêers}} oplaai.',
Expand Down Expand Up @@ -108,6 +109,7 @@
'{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.' => '{attribute} moet ten minste {min, number} {min, plural, one{karakter} other{karakters}} bevat.',
'{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.' => '{attribute} moet hoogstens {max, number} {max, plural, one{karakter} other{karakters}} bevat.',
'{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.' => '{attribute} moet {length, number} {length, plural, one{karakter} other{karakters}} bevat.',
'{compareAttribute} is invalid.' => '',
'{delta, plural, =1{1 day} other{# days}}' => '{delta, plural, =1{1 dag} other{# dae}}',
'{delta, plural, =1{1 hour} other{# hours}}' => '{delta} uur',
'{delta, plural, =1{1 minute} other{# minutes}}' => '{delta, plural, =1{1 minuut} other{# minute}}',
Expand All @@ -123,14 +125,14 @@
'{nFormatted} B' => '{nFormatted} B',
'{nFormatted} GB' => '{nFormatted} GB',
'{nFormatted} GiB' => '{nFormatted} GiB',
'{nFormatted} kB' => '{nFormatted} KB',
'{nFormatted} KiB' => '{nFormatted} KiB',
'{nFormatted} MB' => '{nFormatted} MB',
'{nFormatted} MiB' => '{nFormatted} MiB',
'{nFormatted} PB' => '{nFormatted} PB',
'{nFormatted} PiB' => '{nFormatted} PiB',
'{nFormatted} TB' => '{nFormatted} TB',
'{nFormatted} TiB' => '{nFormatted} TiB',
'{nFormatted} kB' => '{nFormatted} KB',
'{nFormatted} {n, plural, =1{byte} other{bytes}}' => '{nFormatted} {n, plural, =1{greep} other{grepe}}',
'{nFormatted} {n, plural, =1{gibibyte} other{gibibytes}}' => '{nFormatted} {n, plural, =1{gibigreep} other{gibigrepe}}',
'{nFormatted} {n, plural, =1{gigabyte} other{gigabytes}}' => '{nFormatted} {n, plural, =1{gigagreep} other{gigagrepe}}',
Expand Down
Loading

0 comments on commit 870316e

Please sign in to comment.