Symfony\Component\DependencyInjection\Dumper\PhpDumper::wrapServiceConditionals PHP Method

wrapServiceConditionals() private method

Wraps the service conditionals.
private wrapServiceConditionals ( string $value, string $code ) : string
$value string
$code string
return string
    private function wrapServiceConditionals($value, $code)
    {
        if (!$services = ContainerBuilder::getServiceConditionals($value)) {
            return $code;
        }

        $conditions = array();
        foreach ($services as $service) {
            $conditions[] = sprintf("\$this->has('%s')", $service);
        }

        // re-indent the wrapped code
        $code = implode("\n", array_map(function ($line) { return $line ? '    '.$line : $line; }, explode("\n", $code)));

        return sprintf("        if (%s) {\n%s        }\n", implode(' && ', $conditions), $code);
    }