Skip to content

Commit

Permalink
Fix PHP 8.1 deprecation warnings on Helper and FormHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
diegosurita committed Jan 17, 2024
1 parent fd87953 commit b4b42e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public function setEntity($entity, $setScope = false) {
* @return array An array containing the identity elements of an entity
*/
public function entity() {
return explode('.', $this->_entityPath);
return explode('.', (string)$this->_entityPath);
}

/**
Expand Down
28 changes: 26 additions & 2 deletions lib/Cake/View/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,19 @@ protected function _getDateTimeValue($value, $timeFormat) {
}

if (is_numeric($value)) {
$value = strftime('%Y-%m-%d %H:%M:%S', $value);
try {
$value = datefmt_format(
datefmt_create(
locale: setLocale(LC_TIME, 0),
dateType: \IntlDateFormatter::FULL,
timeType: \IntlDateFormatter::FULL,
pattern: 'yyyy-MM-dd HH:mm:SS'
),
$value
);
} catch (\Error) {
$value = date('Y-m-d H:i:s', $value);
}
}
$meridian = 'am';
$pos = strpos($value, '-');
Expand Down Expand Up @@ -3021,7 +3033,19 @@ protected function _generateOptions($name, $options = array()) {
$data = $options['monthNames'];
} else {
for ($m = 1; $m <= 12; $m++) {
$data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1, 1999));
try {
$data[sprintf("%02s", $m)] = datefmt_format(
datefmt_create(
locale: setLocale(LC_TIME, 0),
dateType: \IntlDateFormatter::FULL,
timeType: \IntlDateFormatter::FULL,
pattern: 'MM'
),
mktime(1, 1, 1, $m, 1, 1999)
);
} catch (\Error) {
$data[sprintf("%02s", $m)] = date('m', mktime(1, 1, 1, $m, 1, 1999));
}
}
}
break;
Expand Down

0 comments on commit b4b42e2

Please sign in to comment.