Skip to content

Commit

Permalink
Fix #1017: PHP 8.1 enhancements for native functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Feb 26, 2022
1 parent c099ff4 commit 7f8c927
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
3 changes: 2 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Change Log: `yii2-grid`

## Version 3.5.0

**Date:** 11-Jan-2022
**Date:** 25-Feb-2022

### BC Breaking new major release

- (enh #1017): PHP 8.1 enhancements for native functions.
- Enhance & standardize php docs for new website https://docs.krajee.com.
- (bug #1011): Correct GridView initialization for `toggleData` set to `false`.
- (enh #1010): Enhance sorter link rendering to include customizable sorter icons.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
],
"require": {
"kartik-v/yii2-krajee-base": ">=3.0.3",
"kartik-v/yii2-dialog": "~1.0"
},
"autoload": {
Expand Down
5 changes: 3 additions & 2 deletions src/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Closure;
use Exception;
use kartik\base\Lib;
use Yii;
use yii\grid\ActionColumn as YiiActionColumn;
use yii\helpers\ArrayHelper;
Expand Down Expand Up @@ -204,7 +205,7 @@ protected function renderLabel(&$options, $title, $iconOptions = [])
$label = ArrayHelper::remove($options, 'label');
if (is_null($label)) {
$icon = $this->renderIcon($options, $iconOptions);
if (strlen($icon) > 0) {
if (Lib::strlen($icon) > 0) {
$label = $this->_isDropdown ? ($icon.' '.$title) : $icon;
} else {
$label = $title;
Expand Down Expand Up @@ -284,7 +285,7 @@ protected function renderDataCellContent($model, $key, $index)
if (!isset($options['class'])) {
$options['class'] = 'btn '.$this->grid->getDefaultBtnCss();
}
$trimmed = trim($content);
$trimmed = Lib::trim($content);
if ($this->_isDropdown && !empty($trimmed)) {
$label = ArrayHelper::remove($options, 'label', Yii::t('kvgrid', 'Actions'));
$caret = $notBs3 ? '' : ArrayHelper::remove($options, 'caret', ' <span class="caret"></span>');
Expand Down
16 changes: 8 additions & 8 deletions src/ColumnTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

use Closure;
use kartik\base\Config;
use kartik\base\Lib;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\i18n\Formatter;
use yii\web\View;

/**
Expand Down Expand Up @@ -248,8 +248,8 @@ public function parseExcelFormats(&$options, $model, $key, $index)
if (isset($this->xlFormat)) {
$fmt = $this->xlFormat;
} elseif ($autoFormat && isset($this->format)) {
$tSep = $formatter->thousandSeparator ? $formatter->thousandSeparator : ',';
$dSep = $formatter->decimalSeparator ? $formatter->decimalSeparator : '.';
$tSep = isset($formatter->thousandSeparator) ? $formatter->thousandSeparator : ',';
$dSep = isset($formatter->decimalSeparator) ? $formatter->decimalSeparator : '.';
switch ($format) {
case 'text':
case 'html':
Expand All @@ -268,7 +268,7 @@ public function parseExcelFormats(&$options, $model, $key, $index)
case 'percent':
case 'scientific':
$decimals = is_array($this->format) && isset($this->format[1]) ? $this->format[1] : 2;
$append = $decimals > 0 ? "\\{$dSep}" . str_repeat('0', $decimals) : '';
$append = $decimals > 0 ? "\\{$dSep}" . Lib::str_repeat('0', $decimals) : '';
if ($format == 'percent') {
$append .= '%';
}
Expand All @@ -281,7 +281,7 @@ public function parseExcelFormats(&$options, $model, $key, $index)
break;
case 'date':
case 'time':
$fmt = 'Short ' . ucfirst($format);
$fmt = 'Short ' . Lib::ucfirst($format);
break;
case 'datetime':
$fmt = 'yyyy\-MM\-dd HH\:mm\:ss';
Expand Down Expand Up @@ -323,7 +323,7 @@ protected function renderPageSummaryCellContent()
}
$content = $this->getPageSummaryCellContent();
if ($this->pageSummary === true) {
$format = $this->pageSummaryFormat ? $this->pageSummaryFormat : $this->format;
$format = isset($this->pageSummaryFormat) ? $this->pageSummaryFormat : $this->format;
return $this->grid->formatter->format($content, $format);
}
return ($content === null) ? $this->grid->emptyCell : $content;
Expand Down Expand Up @@ -447,7 +447,7 @@ protected function parseFormat()
Html::addCssClass($this->pageSummaryOptions, $class);
Html::addCssClass($this->footerOptions, $class);
}
if (null !== $this->width && trim($this->width) != '') {
if (Lib::trim($this->width) != '') {
Html::addCssStyle($this->headerOptions, "width:{$this->width};");
Html::addCssStyle($this->pageSummaryOptions, "width:{$this->width};");
Html::addCssStyle($this->footerOptions, "width:{$this->width};");
Expand Down Expand Up @@ -516,7 +516,7 @@ protected function fetchContentOptions($model, $key, $index)
if ($this->isValidAlignment('vAlign')) {
Html::addCssClass($options, "kv-align-{$this->vAlign}");
}
if (null !== $this->width && trim($this->width) != '') {
if (Lib::trim($this->width) != '') {
Html::addCssStyle($options, "width:{$this->width};");
}
$options['data-col-seq'] = array_search($this, $this->grid->columns);
Expand Down
38 changes: 19 additions & 19 deletions src/GridViewTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

use Closure;
use Exception;
use kartik\base\BootstrapTrait;
use kartik\base\Config;
use kartik\base\Lib;
use kartik\dialog\Dialog;
use Yii;
use yii\base\InvalidConfigException;
Expand Down Expand Up @@ -1009,7 +1009,7 @@ protected function setPagerOptionClass($param, $css)
* Renders the table page summary.
*
* @return string the rendering result.
* @throws InvalidConfigException|Exception
* @throws Exception
*/
public function renderPageSummary()
{
Expand Down Expand Up @@ -1233,7 +1233,7 @@ protected function initModule()

/**
* Initialize grid export.
* @throws InvalidConfigException|Exception
* @throws Exception
*/
protected function initExport()
{
Expand Down Expand Up @@ -1493,7 +1493,7 @@ protected function initExport()

/**
* Initialize toggle data button options.
* @throws InvalidConfigException|Exception
* @throws Exception
*/
protected function initToggleData()
{
Expand Down Expand Up @@ -1541,7 +1541,7 @@ protected function initToggleData()

/**
* Initialize bootstrap specific styling.
* @throws InvalidConfigException|Exception
* @throws Exception
*/
protected function initBootstrapStyle()
{
Expand Down Expand Up @@ -1614,7 +1614,7 @@ protected function initLayout()
if ($value instanceof Closure) {
$value = call_user_func($value, $this);
}
$this->layout = str_replace($key, $value, $this->layout);
$this->layout = Lib::str_replace($key, $value, $this->layout);
}
}
}
Expand All @@ -1626,8 +1626,8 @@ protected function initLayout()
protected function replaceLayoutTokens($pairs)
{
foreach ($pairs as $token => $replace) {
if (strpos($this->layout, $token) !== false) {
$this->layout = str_replace($token, $replace, $this->layout);
if (Lib::strpos($this->layout, $token) !== false) {
$this->layout = Lib::str_replace($token, $replace, $this->layout);
}
}
}
Expand Down Expand Up @@ -1677,7 +1677,7 @@ protected function endPjax()

/**
* Initializes and sets the grid panel layout based on the [[template]] and [[panel]] settings.
* @throws InvalidConfigException|Exception
* @throws Exception
*/
protected function initPanel()
{
Expand Down Expand Up @@ -1718,28 +1718,28 @@ protected function initPanel()
}
if ($footer !== false) {
static::initCss($footerOptions, $this->getCssClass(self::BS_PANEL_FOOTER));
$content = strtr($this->panelFooterTemplate, ['{footer}' => $footer]);
$content = Lib::strtr($this->panelFooterTemplate, ['{footer}' => $footer]);
$panelFooter = Html::tag('div', $content, $footerOptions);
}
if ($before !== false) {
static::initCss($beforeOptions, 'kv-panel-before');
$content = strtr($this->panelBeforeTemplate, ['{before}' => $before]);
$content = Lib::strtr($this->panelBeforeTemplate, ['{before}' => $before]);
$panelBefore = Html::tag('div', $content, $beforeOptions);
}
if ($after !== false) {
static::initCss($afterOptions, 'kv-panel-after');
$content = strtr($this->panelAfterTemplate, ['{after}' => $after]);
$content = Lib::strtr($this->panelAfterTemplate, ['{after}' => $after]);
$panelAfter = Html::tag('div', $content, $afterOptions);
}
$out = strtr($this->panelTemplate, [
$out = Lib::strtr($this->panelTemplate, [
'{panelHeading}' => $panelHeading,
'{type}' => $type,
'{panelFooter}' => $panelFooter,
'{panelBefore}' => $panelBefore,
'{panelAfter}' => $panelAfter,
]);

$this->layout = Html::tag('div', strtr($out, [
$this->layout = Html::tag('div', Lib::strtr($out, [
'{title}' => Html::tag($titleTag, $heading, $titleOptions),
'{summary}' => Html::tag('div', '{summary}', $summaryOptions),
]), $options);
Expand Down Expand Up @@ -1776,7 +1776,7 @@ protected function renderToolbar()

/**
* Generates the toolbar container with the toolbar
* @throws InvalidConfigException|Exception
* @throws Exception
*/
protected function renderToolbarContainer()
{
Expand All @@ -1787,8 +1787,8 @@ protected function renderToolbarContainer()
* forcing float-right only if no float is defined in toolbarContainerOptions
*/
if (
!strpos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_RIGHT))
&& !strpos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_LEFT))
!Lib::stripos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_RIGHT))
&& !Lib::stripos($this->toolbarContainerOptions['class'], $this->getCssClass(self::BS_PULL_LEFT))
) {
$this->addCssClass($this->toolbarContainerOptions, self::BS_PULL_RIGHT);
}
Expand Down Expand Up @@ -1968,9 +1968,9 @@ protected function registerAssets()
*/
protected function renderTablePart($part, $content)
{
$content = strtr($content, ["<{$part}>\n" => '', "\n</{$part}>" => '', "<{$part}>" => '', "</{$part}>" => '']);
$content = Lib::strtr($content, ["<{$part}>\n" => '', "\n</{$part}>" => '', "<{$part}>" => '', "</{$part}>" => '']);
$token = $part === 'thead' ? 'Header' : 'Footer';
$prop = strtolower($token).'Container';
$prop = Lib::strtolower($token).'Container';
$options = $this->$prop;
$before = "before{$token}";
$after = "after{$token}";
Expand Down

0 comments on commit 7f8c927

Please sign in to comment.