Skip to content

Commit

Permalink
chore: improved PHP 8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
winternet-studio committed Mar 28, 2024
1 parent 763d9ac commit ad5e61e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function addNamedErrors($name, $arrayMessages, $options = []) {
$arrayMessages = $this->augmentMessages($arrayMessages, $options['suffix'], 'suffix');
}

$this->errorMessages[$name] = array_merge( (array) $this->errorMessages[$name], $arrayMessages);
$this->errorMessages[$name] = array_merge( (array) @$this->errorMessages[$name], $arrayMessages);
}

private function addAllNamedErrors($arrayNames) {
Expand Down
18 changes: 10 additions & 8 deletions src/UserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function __construct($msg, $arrayInternalInfo = [], $options = []) {
$errorData .= 'Level '. ($key+1) .': '. ltrim(str_replace(\Yii::$app->basePath, '', (string) @$b['file']), '\\') .'::'. @$b['line'];
if ($key != 0) { //the first entry will always reference to this function (system_error) so skip that
$errorData .= ' / '. @$b['function'] .'(';
if (count($b['args']) > 0) {
if (isset($b['args']) && count($b['args']) > 0) {
$arrArgs = array();
foreach ($b['args'] as $xarg) {
if (is_array($xarg) || is_object($xarg)) {
Expand Down Expand Up @@ -212,19 +212,21 @@ function __construct($msg, $arrayInternalInfo = [], $options = []) {
$url = @$_SERVER['REQUEST_URI'];

$userID = $userName = null;
if (Yii::$app->getComponents()['user']) {
if (@Yii::$app->getComponents()['user']) {
if (!Yii::$app->user->isGuest) {
$userID = Yii::$app->user->getId();

// Automatically detect the name of the user!
$userUnfo = Yii::$app->user->identity->toArray();
$userName = '';
foreach ($userUnfo as $fieldName => $fieldValue) {
if (stripos($fieldName, 'name') !== false) {
$userName .= $fieldValue .' ';
if (Yii::$app->user->identity instanceOf \yii\base\Model) {
$userUnfo = Yii::$app->user->identity->toArray();
$userName = '';
foreach ($userUnfo as $fieldName => $fieldValue) {
if (stripos($fieldName, 'name') !== false) {
$userName .= $fieldValue .' ';
}
}
$userName = trim($userName);
}
$userName = trim($userName);
}
}

Expand Down

0 comments on commit ad5e61e

Please sign in to comment.