private function getMetadata(XMLAMetadataRequest $metadataRequest, array $patternValues = array()) { $context = new XMLAConnectionContext($this->xmlaConnection); $predicateList = array(); $compiledPatterns = array(); foreach ($patternValues as $key => $value) { $column = $metadataRequest->getColumn($key); if ($column === NULL) { throw new OLAPException("Metadata Request {$metadataRequest->getName()} does not support column {$key}"); } if (empty($value)) { continue; } if ($value instanceof Wildcard) { $pattern = $value->getPattern(); if (strstr($pattern, '%') === FALSE && strstr($pattern, '_') === FALSE) { $compiledPatterns[$key] = $pattern; } else { $predicateList[$key] = XMLAUtil::wildcardToRegexp(array($pattern)); } } else { $compiledPatterns[$key] = $value; } } $requestString = $this->xmlaConnection->generateRequest($context, $metadataRequest, $compiledPatterns); $root = $this->xmlaConnection->executeMetadataRequest($requestString, $metadataRequest->isCachable()); $rowList = array(); foreach ($root->childNodes as $row) { if ($row->namespaceURI != 'urn:schemas-microsoft-com:xml-analysis:rowset') { continue; } $valueList = array(); foreach ($predicateList as $key => $pattern) { $value = XMLAUtil::stringElement($row, $key); if (preg_match("#{$pattern}#", $value) == 0) { continue 2; } } foreach ($metadataRequest->getColumns() as $column) { $valueList[] = XMLAUtil::stringElement($row, $column->xmlaName); } $rowList[] = $valueList; } $headerList = $metadataRequest->getColumnNames(); // @todo return olap4jConnection.factory.newFixedResultSet(olap4jConnection, headerList, rowList); //return; return new ResultSet($headerList, $rowList); }
/** * * @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; }