示例#1
0
  protected function wrapServiceConditionals($value, $code)
  {
    if (!$services = Builder::getServiceConditionals($value))
    {
      return $code;
    }

    $conditions = array();
    foreach ($services as $service)
    {
      $conditions[] = sprintf("\$this->hasService('%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    {\n%s    }\n", implode(' && ', $conditions), $code);
  }