Skip to content

Commit

Permalink
main
Browse files Browse the repository at this point in the history
  • Loading branch information
6562680 committed Jun 27, 2024
1 parent b1d1c68 commit b2d0378
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 99 deletions.
61 changes: 0 additions & 61 deletions helpers/calendar_php.example

This file was deleted.

114 changes: 76 additions & 38 deletions src/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,73 +97,111 @@ public static function php_throwable($error = null, ...$errors) : ?object
* > gzhegow, парсит ошибки для передачи результата в конструктор исключения
*
* @return array{
* message: string,
* code: int,
* previous: string,
* messageData: array,
* messageObject: object,
* messageList: string[],
* codeList: int[],
* previousList: string[],
* messageCodeList: array[],
* messageDataList: array[],
* message: ?string,
* code: ?int,
* previous: ?string,
* messageCode: ?string,
* messageData: ?array,
* messageObject: ?object,
* __unresolved: array,
* }
*/
public static function php_throwable_args($arg = null, ...$args) : array
{
$_message = null;
$_code = null;
$_previous = null;
$_messageData = null;

array_unshift($args, $arg);

foreach ( $args as $v ) {
if (is_int($v)) {
$_code = $v;
$len = count($args);

$messageList = null;
$codeList = null;
$previousList = null;
$messageCodeList = null;
$messageDataList = null;

$message = null;
$code = null;
$previous = null;
$messageCode = null;

$__unresolved = [];

for ( $i = 0; $i < $len; $i++ ) {
$a = $args[ $i ];

if (is_int($a)) {
$codeList[ $i ] = $a;

continue;
}

if (is_a($v, \Throwable::class)) {
$_previous = $v;
if (is_a($a, \Throwable::class)) {
$previousList[ $i ] = $a;

continue;
}

if (null !== ($_string = static::filter_string($v))) {
$_message = $_string;
if ('' !== ($vString = (string) $a)) {
$messageList[ $i ] = $vString;

continue;
}

if (
is_array($v)
|| is_a($v, \stdClass::class)
is_array($a)
|| is_a($a, \stdClass::class)
) {
$_messageData = (array) $v;
$messageDataList[ $i ] = (array) $a;

if ('' !== ($messageString = (string) $messageDataList[ $i ][ 0 ])) {
$messageList[ $i ] = $messageString;

unset($messageDataList[ $i ][ 0 ]);

if (isset($_messageData[ 0 ])) {
$_message = static::filter_string($_messageData[ 0 ]);
if (! $messageDataList[ $i ]) {
unset($messageDataList[ $i ]);
}
}

continue;
}

$__unresolved[ $i ] = $a;
}

$_message = $_message ?? null;
$_code = $_code ?? null;
$_previous = $_previous ?? null;
for ( $i = 0; $i < $len; $i++ ) {
if (isset($messageList[ $i ])) {
if (preg_match('/^[a-z](?!.*\s)/i', $messageList[ $i ])) {
$messageCodeList[ $i ] = strtoupper($messageList[ $i ]);
}
}
}

$_messageObject = null
?? ((null !== $_messageData) ? (object) $_messageData : null)
?? ((null !== $_message) ? (object) [ $_message ] : null);
$result = [];

if (null !== $_messageData) {
unset($_messageData[ 0 ]);
$result[ 'messageList' ] = $messageList;
$result[ 'codeList' ] = $codeList;
$result[ 'previousList' ] = $previousList;
$result[ 'messageCodeList' ] = $messageCodeList;
$result[ 'messageDataList' ] = $messageDataList;

$_messageData = $_messageData ?: null;
}
$messageDataList = $messageDataList ?? [];
$messageData = array_replace(...$messageDataList);
$messageObject = (object) ([ $message ] + $messageData);

$result = [];
$result[ 'message' ] = $_message;
$result[ 'code' ] = $_code;
$result[ 'previous' ] = $_previous;
$result[ 'messageData' ] = $_messageData;
$result[ 'messageObject' ] = $_messageObject;
$result[ 'message' ] = $message;
$result[ 'code' ] = $code;
$result[ 'previous' ] = $previous;
$result[ 'messageCode' ] = $messageCode;
$result[ 'messageData' ] = $messageData;

$result[ 'messageObject' ] = $messageObject;

$result[ '__unresolved' ] = $__unresolved;

return $result;
}
Expand Down

0 comments on commit b2d0378

Please sign in to comment.