/**
  *
  * @param XMLAConnectionContext $context
  * @param XMLAMetadataRequest   $metadataRequest
  * @param array                 $restrictions
  *
  * @throws
  */
 public function generateRequest(XMLAConnectionContext $context, XMLAMetadataRequest $metadataRequest, array $restrictions)
 {
     $content = "Data";
     $buf = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<SOAP-ENV:Envelope\n" . "    xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" . "    SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" . "  <SOAP-ENV:Body>\n" . "    <Discover xmlns=\"urn:schemas-microsoft-com:xml-analysis\"\n" . "        SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" . "    <RequestType>";
     $buf .= $metadataRequest->getName();
     $buf .= "</RequestType>\n" . "    <Restrictions>\n" . "      <RestrictionList>\n";
     $restrictedCatalogName = null;
     if (!empty($restrictions)) {
         foreach ($restrictions as $restriction => $value) {
             $buf .= "<{$restriction}>";
             $buf .= htmlspecialchars($value);
             $buf .= "</{$restriction}>";
             // To remind ourselves to generate a <Catalog> restriction
             // if the request supports it.
             if ($restriction == 'CATALOG_NAME') {
                 $restrictedCatalogName = $value;
             }
         }
     }
     $buf .= "      </RestrictionList>\n" . "    </Restrictions>\n" . "    <Properties>\n" . "      <PropertyList>\n";
     // Add the datasource node only if this request requires it.
     if ($metadataRequest->requiresDatasourceName()) {
         $buf .= "        <DataSourceInfo>";
         $buf .= htmlspecialchars($context->xmlaConnection->getDataSourceInfo());
         $buf .= "</DataSourceInfo>";
     }
     $requestCatalogName = null;
     if ($restrictedCatalogName != null && strlen($restrictedCatalogName) > 0) {
         $requestCatalogName = $restrictedCatalogName;
     }
     // If the request requires catalog name, and one wasn't specified in the
     // restrictions, use the connection's current catalog.
     if ($context->xmlaCatalog != null) {
         $requestCatalogName = $context->xmlaCatalog->getName();
     }
     if ($requestCatalogName == null && $metadataRequest->requiresCatalogName()) {
         $requestCatalogName = $context->xmlaConnection->getCatalog();
     }
     // Add the catalog node only if this request has specified it as a
     // restriction.
     //
     // For low-level objects like cube, the restriction is optional; you can
     // specify null to not restrict, "" to match cubes whose catalog name is
     // empty, or a string (not interpreted as a wild card). (See
     // IOlapDatabaseMetaData.getCubes API doc for more details.) We assume
     // that the request provides the restriction only if it is valid.
     //
     // For high level objects like data source and catalog, the catalog
     // restriction does not make sense.
     if ($requestCatalogName != null && $metadataRequest->allowsCatalogName()) {
         $buf .= PHP_EOL . "        <Catalog>";
         $buf .= htmlspecialchars($requestCatalogName);
         $buf .= "</Catalog>\n";
     }
     $buf .= PHP_EOL . "        <Content>";
     $buf .= htmlspecialchars($content);
     $buf .= "</Content>\n" . "      </PropertyList>\n" . "    </Properties>\n" . "    </Discover>\n" . "</SOAP-ENV:Body>\n" . "</SOAP-ENV:Envelope>";
     return $buf;
 }