34 lines
1.4 KiB
PHP
34 lines
1.4 KiB
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
/** Display the current quotation's execution periods without rewriting the saved source. */
|
||
final class CourierQuoteDocument
|
||
{
|
||
public static function executionText(?string $text, string $periodLabel): string
|
||
{
|
||
$date = '\d{4}(?:\h*年\h*\d{1,2}\h*月\h*\d{1,2}\h*日?|[-./]\d{1,2}[-./]\d{1,2})';
|
||
$interval = $date . '(?:\h*(?:至|到|~|~|—|-)\h*' . $date . ')?';
|
||
$periods = $interval . '(?:\h*[;;]\h*' . $interval . ')*(?:\h*[((]临时[))])?';
|
||
$label = '(?:[本此该](?:次)?(?:报价|价格)\h*(?:的\h*)?(?:(?:执行|生效)(?:日期|时间|期间)?\h*[::]?\h*)?(?:[自从于]\h*)?'
|
||
. '|(?:报价)?(?:执行|生效)(?:日期|时间|期间)\h*[::]?\h*)';
|
||
|
||
return preg_replace('#' . $label . $periods . '(?:\h*(?:起(?:开始)?(?:执行|生效)?|(?:开始)?(?:执行|生效)))?。?#u',
|
||
'本报价执行期间:' . $periodLabel . '。', $text ?? '') ?? ($text ?? '');
|
||
}
|
||
|
||
public static function values(array $values, string $periodLabel): array
|
||
{
|
||
foreach ($values as &$row) {
|
||
if (! is_array($row)) continue;
|
||
foreach ($row as &$value) {
|
||
if (is_string($value) && ! is_numeric($value)) $value = self::executionText($value, $periodLabel);
|
||
}
|
||
unset($value);
|
||
}
|
||
unset($row);
|
||
|
||
return $values;
|
||
}
|
||
}
|