Helper :: convertExpressions: Bitrix method

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

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

        
$converter = function ($matches) use ($ids$names)
        {
            
$mods = [];
            if (
$matches['mod1'])
            {
                
$mods[] = $matches['mod1'];
            }
            if (
$matches['mod2'])
            {
                
$mods[] = $matches['mod2'];
            }

            if (
$matches['object'] === 'Document')
            {
                
$key array_search($matches['field'], $ids);
                if (
$key !== false)
                {
                    
$fieldName $names[$key];
                    return 
'{{'.$fieldName. ($mods' > '.implode(','$mods) : '').'}}';
                }
            }
            elseif (
preg_match('/^A[_0-9]+$/'$matches['object']))
            {
                return 
'{{~'.$matches['object'].':'.$matches['field']. ($mods' > '.implode(','$mods) : '').'}}';
            }

            return 
$matches[0];
        };

        
$source preg_replace_callback(
            \
CBPActivity::ValueInlinePattern,
            
$converter,
            
$source
        
);

        return 
$source;
    }