eZ\Publish\Core\Persistence\TransformationProcessor\PcreCompiler::compileTargetCharacter PHP Method

compileTargetCharacter() protected method

Compile target into a closure, which can be used by preg_replace_callback.
protected compileTargetCharacter ( string $char ) : callback
$char string
return callback
    protected function compileTargetCharacter($char)
    {
        switch (true) {
            case $char === 'remove':
                return function ($matches) {
                    return '';
                };
            case $char === 'keep':
                return function ($matches) {
                    return $matches[0];
                };
            case preg_match('("(?:[^\\\\"]+|\\\\\\\\|\\\\\'|\\\\")*?")', $char):
                $string = str_replace(array('\\\\', '\\"', "\\'"), array('\\', '"', "'"), substr($char, 1, -1));
                return function ($matches) use($string) {
                    return $string;
                };
            default:
                $char = $this->compileCharacter($char);
                return function ($matches) use($char) {
                    return $char;
                };
        }
    }