Helper :: unConvertExpressions: Bitrix method

      
<?php 
//  Bitrix\Bizproc\Automation\Helper :: unConvertExpressions()
//  /dist/bitrix/modules/bizproc/lib/automation/helper.php:234

    
public static function unConvertExpressions($source, array $documentType)
    {
        
$source = (string)$source;
        list(
$ids$names) = static::getFieldsMap($documentType);

        
$converter = function ($matches) use ($ids$names)
        {
            
$matches['mixed'] = htmlspecialcharsback($matches['mixed']);

            if (
strpos($matches['mixed'], '~') === 0)
            {
                
$len strpos($matches['mixed'], '#');
                
$expression = ($len === false)
                    ? 
substr($matches['mixed'], 1)
                    : 
substr($matches['mixed'], 1,$len 1)
                ;
                return 
'{='.trim($expression).'}';
            }

            
$pairs explode('>'$matches['mixed']);
            
$fieldName $fieldId '';

            while ((
$pair array_shift($pairs)) !== null)
            {
                
$fieldName .= $fieldName'>'.$pair $pair;

                
$key array_search(trim($fieldName), $names);
                if (
$key !== false)
                {
                    
$fieldId $ids[$key];
                    break;
                }
            }

            if (
$fieldId)
            {
                
$mods = isset($pairs[0]) ? trim($pairs[0]) : '';
                return 
'{=Document:'.$fieldId.($mods' > '.$mods '').'}';
            }

            return 
$matches[0];
        };

        
$source preg_replace_callback(
            
'/\{\{(?<mixed>[^=].*?)\}\}/is',
            
$converter,
            
$source
        
);

        return 
$source;
    }