Skip to content

Commit

Permalink
10.6.3: #354
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Mar 3, 2024
1 parent c34216b commit 9171f68
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Core/lib/cache/dfc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* @used-by \Df\Sso\Button::_prepareLayout()
* ---
* @used-by dfaoc()
* @see df_no_rec()
* @see df_prop()
* @see dfaoc()
* @param object $o
Expand Down Expand Up @@ -108,6 +109,7 @@ function dfc($o, Closure $f, array $a = [], bool $unique = true, int $offset = 0
* и поэтому Closure не уникальна.
* 2017-08-11 The cache tags. A usage example: @see df_cache_get_simple()
* 2017-01-02 Задавайте параметр $offset в том случае, когда dfc() вызывается опосредованно. Например, так делает @see dfac().
* @see df_no_rec()
* @see dfac()
* @used-by df_category_children_map()
* @used-by df_currency()
Expand Down
1 change: 1 addition & 0 deletions Core/lib/caller/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @used-by df_caller_entry_m()
* @used-by df_caller_f()
* @used-by df_caller_m()
* @used-by df_caller_mf()
* @used-by df_log_l()
* @used-by df_sentry()
* @used-by \Df\Framework\Log\Dispatcher::handle()
Expand Down
6 changes: 6 additions & 0 deletions Core/lib/caller/other.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ function df_caller_m(int $o = 0):string {return df_cc_method(df_assert(df_caller
'df_bt_entry_is_method' /** @uses df_bt_entry_is_method() */
)));}

/**
* 2024-03-03
* @used-by df_no_rec()
*/
function df_caller_mf(int $o = 0):string {return df_cc_method(df_assert(df_caller_entry(++$o)));}

/**
* 2016-08-29
* @used-by df_abstract()
Expand Down
19 changes: 19 additions & 0 deletions Core/lib/lang/other.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
use Df\Core\RAM;
/**
* 2017-02-07
* @used-by df_lang_zh()
Expand All @@ -17,6 +18,24 @@
*/
function df_b(array $args, bool $r) {return !$args ? $r : $args[intval(!$r)];}

/**
* 2024-03-03 "Refactor `static $inProcess` to a function": https://github.com/mage2pro/core/issues/354
* @see df_prop()
* @see dfc()
* @see dfcf()
* @used-by df_sprintf_strict()
* @used-by \Df\Qa\Failure\Error::log()
*/
function df_no_rec(Closure $f):void {
static $inProcess = []; /** @var bool[] $inProcess */
$k = df_caller_mf(); /** @var string $k */
if (!isset($inProcess[$k])) {
$inProcess[$k] = true;
try {$f();}
finally {unset($inProcess[$k]);}
}
}

/**
* @used-by \Df\Core\Html\Tag::openTagWithAttributesAsText()
* @param mixed $v
Expand Down
1 change: 1 addition & 0 deletions Core/lib/lang/prop.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function df_n_set($v) {return is_null($v) ? DF_N : $v;}
* @used-by \Inkifi\Pwinty\API\Entity\Order::magentoOrder()
* @used-by \Wolf\Filter\Customer::categoryPath()
* @used-by \Wolf\Filter\Customer::garage()
* @see df_no_rec()
* @see dfc()
* @param object|null|ArrayAccess $o
* @param mixed|string $v [optional]
Expand Down
1 change: 1 addition & 0 deletions Core/lib/reflection/text/cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function df_cc_class_uc(...$a):string {return df_cc_class(df_ucfirst(dfa_flatten
/**
* 2016-08-10 Если класс не указан, то вернёт название функции. Поэтому в качестве $a1 можно передавать `null`.
* @used-by df_caller_m()
* @used-by df_caller_mf()
* @used-by df_rest_action()
* @used-by \Df\Qa\Trace\Frame::method()
* @param string|object|null|array(object|string)|array(string = string) $a1
Expand Down
24 changes: 9 additions & 15 deletions Core/lib/text/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,20 @@ function df_sprintf_strict($s):string {/** @var string $r */ /** @var mixed[] $a
catch (Th $th) {
/**
* 2024-03-03
* 1) A similar code: @see \Df\Qa\Failure\Error::log()
* 2) The previous (wrong) code:
* The previous (wrong) code:
* static $inProcess = false;
* if (!$inProcess) {
* https://github.com/mage2pro/core/blob/10.6.0/Core/lib/text/format.php#L118-L119
* https://3v4l.org/a6oIr
*/
static $inProcess; /** @var bool $inProcess */
if (!$inProcess) {
$inProcess = true;
try {
df_error(
'df_sprintf_strict failed: «{message}».'
. "\nPattern: {$s}."
. "\nParameters:\n{params}."
,['{message}' => df_xts($th), '{params}' => print_r(df_tail($args), true)]
);
}
finally {$inProcess = false;}
}
df_no_rec(function() use($s, $th, $args):void {
df_error(
'df_sprintf_strict failed: «{message}».'
. "\nPattern: {$s}."
. "\nParameters:\n{params}."
,['{message}' => df_xts($th), '{params}' => print_r(df_tail($args), true)]
);
});
}
}
return $r;
Expand Down
11 changes: 3 additions & 8 deletions Qa/Failure/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,14 @@ private function log():void {
# поэтому try... catch с целью записи отчёта крайне важно:
# без этого при сбое асинхроноого запроса диагностичекское сообщение о сбое окажется утраченным.
/** 2024-03-03 A similar code: @see df_sprintf_strict() */
static $inProcess;
if (!$inProcess) {
$inProcess = true;
try {
df_report('mage2.pro/{date}--{time}.log', $this->report());
}
df_no_rec(function():void {
try {df_report('mage2.pro/{date}--{time}.log', $this->report());}
# 2023-08-03 "Treat `\Throwable` similar to `\Exception`": https://github.com/mage2pro/core/issues/311
catch (Th $th) {
df_log($th);
throw $th;
}
finally {$inProcess = false;}
}
});
}

/**
Expand Down
2 changes: 2 additions & 0 deletions Qa/lib/validation/assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ function df_ar($v, $c = null, $m = null) {return dfcf(function($v, $c = null, $m
* https://github.com/mage2pro/core/blob/5.5.7/Core/Exception.php#L61-L67
* @used-by df_assert_qty_supported()
* @used-by df_call_parent()
* @used-by df_caller_m()
* @used-by df_caller_mf()
* @used-by df_catalog_locator()
* @used-by df_config_field()
* @used-by df_configurable_children()
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/core"
,"version": "10.6.2"
,"version": "10.6.3"
,"description": "Mage2.PRO core package."
,"type": "magento2-module"
,"homepage": "https://mage2.pro"
Expand Down

0 comments on commit 9171f68

Please sign in to comment.