protected function openAndVerify($fileName)
{
$driverType = $this->db->name;
// Make sure the file exists
if (!@file_exists($fileName)) {
return false;
}
// Make sure the file is a valid XML document
try {
$xml = new SimpleXMLElement($fileName, LIBXML_NONET, true);
} catch (Exception $e) {
$xml = null;
return false;
}
// Make sure the file is an XML schema file
if ($xml->getName() != 'schema') {
$xml = null;
return false;
}
if (!$xml->meta) {
$xml = null;
return false;
}
if (!$xml->meta->drivers) {
$xml = null;
return false;
}
/** @var SimpleXMLElement $drivers */
$drivers = $xml->meta->drivers;
foreach ($drivers->children() as $driverTypeTag) {
$thisDriverType = (string) $driverTypeTag;
if ($thisDriverType == $driverType) {
return $xml;
}
}
// Some custom database drivers use a non-standard $name variable. Let try a relaxed match.
foreach ($drivers->children() as $driverTypeTag) {
$thisDriverType = (string) $driverTypeTag;
if (strpos($driverType, $thisDriverType) === 0 || substr($driverType, -strlen($thisDriverType)) == $thisDriverType) {
return $xml;
}
}
return false;
}